Update
This commit is contained in:
parent
d30baa49f6
commit
d53dcaeb54
2 changed files with 16 additions and 14 deletions
|
@ -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"
|
26
headline.py
26
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)
|
Loading…
Reference in a new issue