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():
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, 'tildes') for x in tildes.feed()[:5]]
return feed
@ -65,9 +65,9 @@ def get_content_type(url):
try:
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:
return 'text/'
return ''
def update_story(story, is_manual=False):
res = {}

View File

@ -14,7 +14,7 @@ from prawcore.exceptions import PrawcoreException
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_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['num_comments'] = r.num_comments
if s['score'] < 25 and s['num_comments'] < 10:
return False
if r.selftext:
s['text'] = render_md(clean(r.selftext))

View File

@ -40,6 +40,10 @@ def update_attributes():
if r.status_code != 202:
raise Exception('Bad response code ' + str(r.status_code))
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:
raise
except BaseException as e:

View File

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

View File

@ -15,6 +15,7 @@ class Article extends React.Component {
this.state = {
story: cache[id] || false,
error: false,
pConv: [],
};
}
@ -43,10 +44,22 @@ class Article extends React.Component {
);
}
pConvert = (n) => {
this.setState({ pConv: [...this.state.pConv, n]});
}
render() {
const id = this.props.match ? this.props.match.params.id : 'CLOL';
const story = this.state.story;
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 (
<div className='article-container'>
@ -65,8 +78,20 @@ class Article extends React.Component {
{infoLine(story)}
{story.text ?
<div className='story-text' dangerouslySetInnerHTML={{ __html: story.text }} />
{nodes ?
<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>
}

View File

@ -60,7 +60,9 @@ class Results extends React.Component {
</Helmet>
{error && <p>Connection error?</p>}
{stories ?
<div>
<>
<p>Search results:</p>
<div className='comment lined'>
{stories.length ?
stories.map((x, i) =>
<div className='item' key={i}>
@ -78,9 +80,10 @@ class Results extends React.Component {
</div>
)
:
<p>no results</p>
<p>none</p>
}
</div>
</>
:
<p>loading...</p>
}

View File

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