fix webworm dates.

This commit is contained in:
Jason Schwarzenberger 2020-11-03 10:31:14 +13:00
parent f23bf628e0
commit 0d6a86ace2
2 changed files with 17 additions and 10 deletions

View File

@ -13,7 +13,7 @@ OUTLINE_API = 'https://api.outline.com/v3/parse_article'
READ_API = 'http://127.0.0.1:33843' READ_API = 'http://127.0.0.1:33843'
INVALID_DOMAINS = ['youtube.com', 'bloomberg.com', 'wsj.com'] INVALID_DOMAINS = ['youtube.com', 'bloomberg.com', 'wsj.com']
TWO_DAYS = 60*60*24*10 TWO_DAYS = 60*60*24*2
def list(): def list():
feed = [] feed = []

View File

@ -8,17 +8,18 @@ if __name__ == '__main__':
sys.path.insert(0,'.') sys.path.insert(0,'.')
import requests import requests
from datetime import datetime
from utils import clean from utils import clean
WEBWORM_DOMAIN = "https://www.webworm.co" WEBWORM_DOMAIN = "https://www.webworm.co"
API_STORIES = lambda x: f'{WEBWORM_DOMAIN}/api/v1/archive?sort=new&search=&offset=0&limit=100' API_STORIES = lambda x: f"{WEBWORM_DOMAIN}/api/v1/archive?sort=new&search=&offset=0&limit=100"
#API_ITEM = lambda x : f'https://hn.algolia.com/api/v1/items/{x}' #API_ITEM = lambda x : f'https://hn.algolia.com/api/v1/items/{x}'
API_ITEM_COMMENTS = lambda x: f"{WEBWORM_DOMAIN}/api/v1/post/{x}/comments?all_comments=true&sort=best_first" API_ITEM_COMMENTS = lambda x: f"{WEBWORM_DOMAIN}/api/v1/post/{x}/comments?all_comments=true&sort=best_first"
SITE_LINK = lambda x: f'{WEBWORM_DOMAIN}/p/{x}' SITE_LINK = lambda x: f"{WEBWORM_DOMAIN}/p/{x}"
SITE_AUTHOR_LINK = lambda x : f'{WEBWORM_DOMAIN}/people/{x}' SITE_AUTHOR_LINK = lambda x : f"{WEBWORM_DOMAIN}/people/{x}"
def api(route, ref=None): def api(route, ref=None):
try: try:
@ -55,17 +56,21 @@ def bylines(b):
a['link'] = SITE_AUTHOR_LINK(b.get('id')) a['link'] = SITE_AUTHOR_LINK(b.get('id'))
return a return a
def unix(date_str):
return int(datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ').timestamp())
def comment(i): def comment(i):
if 'body' not in i: if 'body' not in i:
return False return False
c = {} c = {}
c['date'] = unix(i.get('date'))
c['author'] = i.get('name', '') c['author'] = i.get('name', '')
c['score'] = o.get('reactions').get('') c['score'] = o.get('reactions').get('')
c['date'] = i.get('created_at_i', 0)
c['text'] = clean(i.get('body', '') or '') c['text'] = clean(i.get('body', '') or '')
c['comments'] = [comment(j) for j in i['children']] c['comments'] = [comment(j) for j in i['children']]
c['comments'] = list(filter(bool, c['comments'])) c['comments'] = list(filter(bool, c['comments']))
return c return c
def comment_count(i): def comment_count(i):
@ -87,14 +92,11 @@ def story(ref):
return False return False
s = {} s = {}
authors = list(filter(None, [bylines(byline) for byline in r.get('publishedBylines')]))
s['author'] = '' s['author'] = ''
s['author_link'] = '' s['author_link'] = ''
if len(authors):
s['author'] = authors[0].get('name') s['date'] = unix(r.get('post_date'))
s['author_link'] = authors[0].get('link')
s['score'] = r.get('reactions').get('') s['score'] = r.get('reactions').get('')
s['date'] = r.get('post_date', 0)
s['title'] = r.get('title', '') s['title'] = r.get('title', '')
s['link'] = r.get('canonical_url', '') s['link'] = r.get('canonical_url', '')
s['url'] = r.get('canonical_url', '') s['url'] = r.get('canonical_url', '')
@ -102,6 +104,11 @@ def story(ref):
s['comments'] = list(filter(bool, s['comments'])) s['comments'] = list(filter(bool, s['comments']))
s['num_comments'] = r.get('comment_count', 0) s['num_comments'] = r.get('comment_count', 0)
authors = list(filter(None, [bylines(byline) for byline in r.get('publishedBylines')]))
if len(authors):
s['author'] = authors[0].get('name')
s['author_link'] = authors[0].get('link')
if 'text' in r and r['text']: if 'text' in r and r['text']:
s['text'] = clean(r['text'] or '') s['text'] = clean(r['text'] or '')