Compare commits
8 Commits
b46ce36c63
...
88d2216627
Author | SHA1 | Date | |
---|---|---|---|
88d2216627 | |||
6cf2f01b08 | |||
607573dd44 | |||
c554ecd890 | |||
6576eb1bac | |||
472af76d1a | |||
4727d34eb6 | |||
0e086b60b8 |
50
apiserver/delete-story.py
Normal file
50
apiserver/delete-story.py
Normal 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.')
|
|
@ -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 = {}
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
}
|
||||
|
|
|
@ -60,27 +60,30 @@ class Results extends React.Component {
|
|||
</Helmet>
|
||||
{error && <p>Connection error?</p>}
|
||||
{stories ?
|
||||
<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>
|
||||
<>
|
||||
<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>
|
||||
|
||||
<span className='source'>
|
||||
​({sourceLink(x)})
|
||||
</span>
|
||||
<span className='source'>
|
||||
​({sourceLink(x)})
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{infoLine(x)}
|
||||
</div>
|
||||
|
||||
{infoLine(x)}
|
||||
</div>
|
||||
)
|
||||
:
|
||||
<p>no results</p>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
:
|
||||
<p>none</p>
|
||||
}
|
||||
</div>
|
||||
</>
|
||||
:
|
||||
<p>loading...</p>
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ body {
|
|||
color: #000000;
|
||||
margin-bottom: 100vh;
|
||||
word-break: break-word;
|
||||
font-kerning: normal;
|
||||
}
|
||||
|
||||
a {
|
||||
|
|
Loading…
Reference in New Issue
Block a user