Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from FlrQue/nightly
Browse files Browse the repository at this point in the history
Nightly to main code base. This is update v21.10-1.
  • Loading branch information
Florke64 authored Oct 5, 2021
2 parents ef72bc4 + 79335a2 commit 85e2731
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 19 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions .idea/rss-static-reader.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Below is the list of features I want to implement into this program. When I comp
Output look can be customized to look a bit nicer than now.

- **Random article**:
Link to randomly choosen "article of the day" or something like that.
~~Link to randomly choosen "article of the day" or something like that.~~ [1456773903813866098f88eae8787822ee352c66](https://github.com/FlrQue/rss-static-reader/commit/1456773903813866098f88eae8787822ee352c66)

- **Feed limit**:
Number of the articles shown under the single page would be possible limit.
Expand Down
9 changes: 8 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
RELOAD_TIME: float = 15 # in minutes
RSS_FEED_FILE: str = "rss-feed-list.conf"
TARGET_HTML_DIR: str = "html"
RANDOM_ARTICLE_LINK: bool = True

# Advanced config:
WIDGET_LIST: tuple = (
Expand All @@ -18,7 +19,13 @@
'category_link_block',
'back_link_block',
'page_title',
'footer_generate_time'
'footer_generate_time',
'random_article'
)

ACCEPTED_DATETIME_FORMAT: tuple = (
'%a, %d %b %Y %H:%M:%S %z', # Common date-time string format for most feeds
'%Y-%m-%dT%H:%M:%SZ', # Added as a fix of #3 issue (feedburner.com)
)

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion html_template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
</head>

<body>
<header><!--__RSS_FEED_BACK_HOME_LINK-->
<header><!--__RSS_FEED_BACK_HOME_LINK__-->
<h1>RSS - Static Reader</h1>
<a href="#rss_feeds">RSS Feeds</a>
<a href="#articles">All Articles</a>
<a href="#categories">RSS Feed categories</a>
<!--__RSS_RANDOM_ARTICLE_LINK__-->
<hr/>

<h2 id="rss_feeds">RSS Feeds</h2><!--__RSS_FEED_SOURCES_DEDICATED_LINKS__-->
Expand Down
2 changes: 2 additions & 0 deletions html_template/widgets/random_article.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<a href="%art_link%">Random Article</a>
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
feedreader
feedparser>=6.0.8
1 change: 1 addition & 0 deletions rss-feed-list.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Format:
# <feed_url>;<feed_name>;[category,another_category,...]
https://feeds.feedburner.com/niebezpiecznik/;Niebezpiecznik;Technology,Security
https://archlinux.org/feeds/news/;Arch Linux News;Linux
https://omgubuntu.co.uk/feed;OMG, Ubuntu!;Linux,Technology
https://itsfoss.com/feed;It's FOSS;Technology
52 changes: 40 additions & 12 deletions rss_static_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import time
import datetime
import threading
import random
from typing import Union

# 3rd party Python libraries
Expand Down Expand Up @@ -94,10 +95,15 @@ def __init__(self, article_title: str, article_url: str, published_on: str, arti
feed_source: FeedSource = None) -> None:
self.article_title: str = article_title
self.article_url: str = article_url
self.published_date_time: float = datetime.datetime.now().timestamp()

for datetime_format in config.ACCEPTED_DATETIME_FORMAT: # type: str
try:
self.published_date_time = datetime.datetime.strptime(published_on, datetime_format).timestamp()
break
except ValueError:
continue

datetime_format = "%a, %d %b %Y %H:%M:%S %z"
self.published_date_time: datetime = datetime.datetime.strptime(published_on, datetime_format)
# self.published_date_time: str = published_on
self.article_author: str = article_author

self.feed_source: Union[FeedSource, None] = feed_source
Expand Down Expand Up @@ -135,6 +141,7 @@ def article_list_factory(feedparser_entries: dict, feed_source: FeedSource) -> l

FEED_SOURCES: dict[str, FeedSource]
FEED_ARTICLES: list[Union[FeedArticle]]
RANDOM_ARTICLE_LINK: str = "#"
FEED_CATEGORIES: dict[str, FeedCategory]
WIDGET_TEMPLATES: dict[str, str]

Expand Down Expand Up @@ -241,7 +248,7 @@ def wipe_target() -> None:
os.remove(path.join(target_directory, file))


def use_widget(widget_id: str, widget_data: dict[str, str]) -> str:
def use_widget(widget_id: str, widget_data: dict[str, str] = {}) -> str:
widget_template: str = WIDGET_TEMPLATES.get(widget_id)

if widget_template is None:
Expand Down Expand Up @@ -291,19 +298,40 @@ def generate_html_files(target_directory_path: str = "html_target", subfeed_id:
'category_article_amount': str(category.article_count)
})

global RANDOM_ARTICLE_LINK
article_count: int = len(FEED_ARTICLES)
random_article_index: int = random.randint(0, article_count)

i: int = 0
for article in FEED_ARTICLES: # type: FeedArticle
if subfeed_id == "index" or \
(type(page_type) is FeedSource and article.feed_source.id == FEED_SOURCES.get(subfeed_id).id) or \
(type(page_type) is FeedCategory and FEED_CATEGORIES.get(subfeed_id).name in article.feed_source.categories):
(type(page_type) is FeedSource and
article.feed_source.id == FEED_SOURCES.get(subfeed_id).id) or \
(type(page_type) is FeedCategory and
FEED_CATEGORIES.get(subfeed_id).name in article.feed_source.categories):

datetime_from_timestamp: datetime = datetime.datetime.fromtimestamp(article.published_date_time)
article_published_date_time: str = datetime_from_timestamp.strftime("%a, %d %b %Y %H:%M:%S %z")

article_dedicated_links_dom += use_widget('article_link_block', {
'art_link': article.article_url,
'art_title': article.article_title,
'src_title': article.feed_source.name,
'art_author': article.article_author,
'pub_date': article.published_date_time.strftime("%A, %d %b %Y %H:%M"),
# TODO: Move DATE_FORMAT to config.py
'pub_date': article_published_date_time,
})

if i == random_article_index and subfeed_id == "index":
RANDOM_ARTICLE_LINK = article.article_url

i += 1

if config.RANDOM_ARTICLE_LINK and subfeed_id == "index":
index_html_template_content = index_html_template_content.replace(
'<!--__RSS_RANDOM_ARTICLE_LINK__-->',
use_widget('random_article', {'art_link': RANDOM_ARTICLE_LINK})
)

index_html_template_content = index_html_template_content.replace(
'<!--__RSS_FEED_SOURCES_DEDICATED_LINKS__-->',
sources_dedicated_links_dom
Expand All @@ -320,8 +348,8 @@ def generate_html_files(target_directory_path: str = "html_target", subfeed_id:
)

index_html_template_content = index_html_template_content.replace(
'<!--__RSS_FEED_BACK_HOME_LINK-->',
WIDGET_TEMPLATES.get('back_link_block')
'<!--__RSS_FEED_BACK_HOME_LINK__-->',
use_widget('back_link_block')
) if subfeed_id != "index" else index_html_template_content

index_html_template_content = index_html_template_content.replace(
Expand Down Expand Up @@ -385,14 +413,14 @@ def run(self) -> None:

self.set_running(True)

start_time: float = time.time()
while self.__running:
start_time: float = time.time()

clear_cache()
wipe_target()
process()

finish_time: float = time.time()

total_job_time: float = finish_time - start_time
print(f"Job finished in {total_job_time} seconds.")

Expand Down

0 comments on commit 85e2731

Please sign in to comment.