Compare commits

..

No commits in common. "88d22166278d3828de82e6d48525f166de023464" and "b46ce36c637db3483aae909dc61d8b1ffa45068f" have entirely different histories.

8 changed files with 26 additions and 112 deletions

View File

@ -1,50 +0,0 @@
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()[:15]]
feed += [(x, 'hackernews') for x in hackernews.feed()[:10]]
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=10).headers['content-type']
return requests.get(url, headers=headers, timeout=2).headers['content-type']
except:
return ''
return 'text/'
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+AcademicPhilosophy+DepthHub+Foodforthought+HistoryofIdeas+LaymanJournals+PhilosophyofScience+PoliticsPDFs+Scholar+StateOfTheUnion+TheAgora+TrueFilm+TrueReddit+UniversityofReddit+culturalstudies+hardscience+indepthsports+indepthstories+ludology+neurophilosophy+resilientcommunities+worldevents'
SUBREDDITS = 'Economics+Foodforthought+TrueReddit+business+privacy'
SITE_LINK = lambda x : 'https://old.reddit.com{}'.format(x)
SITE_AUTHOR_LINK = lambda x : 'https://old.reddit.com/u/{}'.format(x)
@ -67,9 +67,6 @@ 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,10 +40,6 @@ 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(('', 33842), flask_app)
http_server = WSGIServer(('', 43842), flask_app)
def feed_thread():
global news_index

View File

@ -15,7 +15,6 @@ class Article extends React.Component {
this.state = {
story: cache[id] || false,
error: false,
pConv: [],
};
}
@ -44,22 +43,10 @@ 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'>
@ -78,20 +65,8 @@ class Article extends React.Component {
{infoLine(story)}
{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>
{story.text ?
<div className='story-text' dangerouslySetInnerHTML={{ __html: story.text }} />
:
<p>Problem getting article :(</p>
}

View File

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

View File

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