Compare commits

..

8 Commits

8 changed files with 112 additions and 26 deletions

50
apiserver/delete-story.py Normal file
View File

@ -0,0 +1,50 @@
import database
import search
import sys
import json
import requests
database.init()
search.init()
def database_del_story(sid):
try:
session = database.Session()
session.query(database.Story).filter(database.Story.sid==sid).delete()
session.commit()
except:
session.rollback()
raise
finally:
session.close()
def search_del_story(sid):
try:
r = requests.delete(search.MEILI_URL + 'indexes/qotnews/documents/'+sid, timeout=2)
if r.status_code != 202:
raise Exception('Bad response code ' + str(r.status_code))
return r.json()
except KeyboardInterrupt:
raise
except BaseException as e:
logging.error('Problem deleting MeiliSearch story: {}'.format(str(e)))
return False
if __name__ == '__main__':
if len(sys.argv) == 2:
sid = sys.argv[1]
else:
print('Usage: python delete-story.py [story id]')
exit(1)
story = database.get_story(sid)
if story:
print('Deleting story:')
print(story.title)
database_del_story(sid)
search_del_story(sid)
database.del_ref(story.ref)
else:
print('Story not found. Exiting.')

View File

@ -18,7 +18,7 @@ TWO_DAYS = 60*60*24*2
def list(): def list():
feed = [] feed = []
feed += [(x, 'hackernews') for x in hackernews.feed()[:10]] feed += [(x, 'hackernews') for x in hackernews.feed()[:15]]
feed += [(x, 'reddit') for x in reddit.feed()[:10]] feed += [(x, 'reddit') for x in reddit.feed()[:10]]
feed += [(x, 'tildes') for x in tildes.feed()[:5]] feed += [(x, 'tildes') for x in tildes.feed()[:5]]
return feed return feed
@ -65,9 +65,9 @@ def get_content_type(url):
try: try:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'} headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'}
return requests.get(url, headers=headers, timeout=2).headers['content-type'] return requests.get(url, headers=headers, timeout=10).headers['content-type']
except: except:
return 'text/' return ''
def update_story(story, is_manual=False): def update_story(story, is_manual=False):
res = {} res = {}

View File

@ -14,7 +14,7 @@ from prawcore.exceptions import PrawcoreException
from utils import render_md, clean from utils import render_md, clean
SUBREDDITS = 'Economics+Foodforthought+TrueReddit+business+privacy' SUBREDDITS = 'Economics+AcademicPhilosophy+DepthHub+Foodforthought+HistoryofIdeas+LaymanJournals+PhilosophyofScience+PoliticsPDFs+Scholar+StateOfTheUnion+TheAgora+TrueFilm+TrueReddit+UniversityofReddit+culturalstudies+hardscience+indepthsports+indepthstories+ludology+neurophilosophy+resilientcommunities+worldevents'
SITE_LINK = lambda x : 'https://old.reddit.com{}'.format(x) SITE_LINK = lambda x : 'https://old.reddit.com{}'.format(x)
SITE_AUTHOR_LINK = lambda x : 'https://old.reddit.com/u/{}'.format(x) SITE_AUTHOR_LINK = lambda x : 'https://old.reddit.com/u/{}'.format(x)
@ -67,6 +67,9 @@ def story(ref):
s['comments'] = list(filter(bool, s['comments'])) s['comments'] = list(filter(bool, s['comments']))
s['num_comments'] = r.num_comments s['num_comments'] = r.num_comments
if s['score'] < 25 and s['num_comments'] < 10:
return False
if r.selftext: if r.selftext:
s['text'] = render_md(clean(r.selftext)) s['text'] = render_md(clean(r.selftext))

View File

@ -40,6 +40,10 @@ def update_attributes():
if r.status_code != 202: if r.status_code != 202:
raise Exception('Bad response code ' + str(r.status_code)) raise Exception('Bad response code ' + str(r.status_code))
return r.json() return r.json()
r = requests.delete(MEILI_URL + 'indexes/qotnews/settings/displayed-attributes', timeout=2)
if r.status_code != 202:
raise Exception('Bad response code ' + str(r.status_code))
return r.json()
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except BaseException as e: except BaseException as e:

View File

@ -145,7 +145,7 @@ def static_story(sid):
url=url, url=url,
description=description) description=description)
http_server = WSGIServer(('', 43842), flask_app) http_server = WSGIServer(('', 33842), flask_app)
def feed_thread(): def feed_thread():
global news_index global news_index

View File

@ -15,6 +15,7 @@ class Article extends React.Component {
this.state = { this.state = {
story: cache[id] || false, story: cache[id] || false,
error: false, error: false,
pConv: [],
}; };
} }
@ -43,10 +44,22 @@ class Article extends React.Component {
); );
} }
pConvert = (n) => {
this.setState({ pConv: [...this.state.pConv, n]});
}
render() { render() {
const id = this.props.match ? this.props.match.params.id : 'CLOL'; const id = this.props.match ? this.props.match.params.id : 'CLOL';
const story = this.state.story; const story = this.state.story;
const error = this.state.error; const error = this.state.error;
const pConv = this.state.pConv;
let nodes = null;
if (story.text) {
let domparser = new DOMParser();
let doc = domparser.parseFromString(story.text, 'text/html');
nodes = doc.querySelector('body').children;
}
return ( return (
<div className='article-container'> <div className='article-container'>
@ -65,8 +78,20 @@ class Article extends React.Component {
{infoLine(story)} {infoLine(story)}
{story.text ? {nodes ?
<div className='story-text' dangerouslySetInnerHTML={{ __html: story.text }} /> <div className='story-text'>
{Object.entries(nodes).map(([k, v]) =>
pConv.includes(k) ?
v.innerHTML.split('\n\n').map(x =>
<p dangerouslySetInnerHTML={{ __html: x }} />
)
:
<>
<v.localName dangerouslySetInnerHTML={{ __html: v.innerHTML }} />
{v.localName == 'pre' && <button onClick={() => this.pConvert(k)}>Convert Code to Paragraph</button>}
</>
)}
</div>
: :
<p>Problem getting article :(</p> <p>Problem getting article :(</p>
} }

View File

@ -60,27 +60,30 @@ class Results extends React.Component {
</Helmet> </Helmet>
{error && <p>Connection error?</p>} {error && <p>Connection error?</p>}
{stories ? {stories ?
<div> <>
{stories.length ? <p>Search results:</p>
stories.map((x, i) => <div className='comment lined'>
<div className='item' key={i}> {stories.length ?
<div className='title'> stories.map((x, i) =>
<Link className='link' to={'/' + x.id}> <div className='item' key={i}>
<img className='source-logo' src={logos[x.source]} alt='source logo' /> {x.title} <div className='title'>
</Link> <Link className='link' to={'/' + x.id}>
<img className='source-logo' src={logos[x.source]} alt='source logo' /> {x.title}
</Link>
<span className='source'> <span className='source'>
&#8203;({sourceLink(x)}) &#8203;({sourceLink(x)})
</span> </span>
</div>
{infoLine(x)}
</div> </div>
)
{infoLine(x)} :
</div> <p>none</p>
) }
: </div>
<p>no results</p> </>
}
</div>
: :
<p>loading...</p> <p>loading...</p>
} }

View File

@ -4,6 +4,7 @@ body {
color: #000000; color: #000000;
margin-bottom: 100vh; margin-bottom: 100vh;
word-break: break-word; word-break: break-word;
font-kerning: normal;
} }
a { a {