Sanitize html

This commit is contained in:
2019-12-01 22:18:41 +00:00
parent e231cd5c31
commit ebcbf1b624
4 changed files with 50 additions and 11 deletions

View File

@@ -3,8 +3,14 @@ logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
if __name__ == '__main__':
import sys
sys.path.insert(0,'.')
import requests
from utils import clean
API_TOPSTORIES = lambda x: 'https://hacker-news.firebaseio.com/v0/topstories.json'
API_ITEM = lambda x : 'https://hn.algolia.com/api/v1/items/{}'.format(x)
@@ -34,7 +40,7 @@ def comment(i):
c['author'] = i.get('author', '')
c['score'] = i.get('points', 0)
c['date'] = i.get('created_at_i', 0)
c['text'] = i.get('text', '')
c['text'] = clean(i.get('text', '') or '')
c['comments'] = [comment(j) for j in i['children']]
c['comments'] = list(filter(bool, c['comments']))
return c
@@ -65,7 +71,7 @@ def story(ref):
s['num_comments'] = comment_count(s) - 1
if 'text' in r and r['text']:
s['text'] = r['text']
s['text'] = clean(r['text'] or '')
return s