From d53dcaeb54f1c540c388ec6688481482dc216873 Mon Sep 17 00:00:00 2001 From: mdivecky Date: Sat, 9 Jul 2022 20:50:33 +0200 Subject: [PATCH] Update --- config.yaml | 4 ++++ headline.py | 26 ++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/config.yaml b/config.yaml index 68a3244..ec930cb 100644 --- a/config.yaml +++ b/config.yaml @@ -14,3 +14,7 @@ feeds: - name: "novinky.cz" rss_source: "https://www.novinky.cz/rss" unique_tag: "guid" + + - name: "CTK" + rss_source: "https://www.ceskenoviny.cz/sluzby/rss/zpravy.php" + unique_tag: "guid" \ No newline at end of file diff --git a/headline.py b/headline.py index 3857648..f2e5f6a 100644 --- a/headline.py +++ b/headline.py @@ -8,7 +8,6 @@ import json import imgkit from diff_match_patch import diff_match_patch -import difflib from pprint import pprint import hashlib @@ -29,21 +28,20 @@ dmp = diff_match_patch() rc = redis.Redis(host='localhost', port=6379, db=0) -image_options = { - 'width': '450', -} - +article_count = 0 def write_article(article, rc): rval = json.dumps(article['content']) rc.set(article['rss_id'], rval) - -def process_diff(diff, article): +def process_diff(old, new, rss_id): + diff = dmp.diff_main(old['title'], new['title']) dmp.diff_cleanupSemantic(diff) html_diff = dmp.diff_prettyHtml(diff) - filename = hashlib.md5(article['rss_id'].encode()).hexdigest() + ".jpg" - image = imgkit.from_string(html_diff, filename, options = {'width': '450'}) + print(old['link']) + #print(diff) + #filename = "./img/" + hashlib.md5(rss_id.encode()).hexdigest() + ".jpg" + #image = imgkit.from_string(html_diff, filename, options = {'width': '450', 'quiet': ''}) return(True) @@ -52,10 +50,9 @@ def process_item(article, rc): old = json.loads(rc.get(article['rss_id'])) new = article['content'] if old['title'] != new['title']: - print('Article changed. Fuck the world.') - diff = dmp.diff_main(old['title'], new['title']) - process_diff(diff, article) - #write_article(article_rc) + print('Article changed. World is fucked.') + diff = process_diff(old, new, article['rss_id']) + #write_article(article, rc) return(True) else: # Article is the same. All good! @@ -66,7 +63,7 @@ def process_item(article, rc): -article_count = 0 + for feed in config['feeds']: rss_source = str(feed['rss_source']) unique_tag = str(feed['unique_tag']) @@ -93,5 +90,6 @@ for feed in config['feeds']: } article_count += 1 process_item(article, rc) + print("Processed articles:") print(article_count) \ No newline at end of file