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():
|
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 = {}
|
||||||
|
|
|
@ -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))
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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>
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,9 @@ class Results extends React.Component {
|
||||||
</Helmet>
|
</Helmet>
|
||||||
{error && <p>Connection error?</p>}
|
{error && <p>Connection error?</p>}
|
||||||
{stories ?
|
{stories ?
|
||||||
<div>
|
<>
|
||||||
|
<p>Search results:</p>
|
||||||
|
<div className='comment lined'>
|
||||||
{stories.length ?
|
{stories.length ?
|
||||||
stories.map((x, i) =>
|
stories.map((x, i) =>
|
||||||
<div className='item' key={i}>
|
<div className='item' key={i}>
|
||||||
|
@ -78,9 +80,10 @@ class Results extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
<p>no results</p>
|
<p>none</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
:
|
:
|
||||||
<p>loading...</p>
|
<p>loading...</p>
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user