Move feed and Praw config to settings.py
This commit is contained in:
parent
7acce407e9
commit
ca78a6d7a9
12
README.md
12
README.md
|
@ -35,7 +35,7 @@ $ source env/bin/activate
|
||||||
(env) $ pip install -r requirements.txt
|
(env) $ pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
Configure Praw for your Reddit account:
|
Configure Praw for your Reddit account (optional):
|
||||||
|
|
||||||
* Go to https://www.reddit.com/prefs/apps
|
* Go to https://www.reddit.com/prefs/apps
|
||||||
* Click "Create app"
|
* Click "Create app"
|
||||||
|
@ -44,16 +44,14 @@ Configure Praw for your Reddit account:
|
||||||
* Description: blank
|
* Description: blank
|
||||||
* About URL: blank
|
* About URL: blank
|
||||||
* Redirect URL: your GitHub profile
|
* Redirect URL: your GitHub profile
|
||||||
* Submit, copy the client ID and client secret into `praw.ini`:
|
* Submit, copy the client ID and client secret into `settings.py` below
|
||||||
|
|
||||||
```text
|
```text
|
||||||
(env) $ vim praw.ini
|
(env) $ vim settings.py.example
|
||||||
[bot]
|
|
||||||
client_id=paste here
|
|
||||||
client_secret=paste here
|
|
||||||
user_agent=script by github/your-username-here
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Edit it and save it as `settings.py`.
|
||||||
|
|
||||||
Now you can run the server:
|
Now you can run the server:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|
2
apiserver/.gitignore
vendored
2
apiserver/.gitignore
vendored
|
@ -105,7 +105,7 @@ ENV/
|
||||||
# DB
|
# DB
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
||||||
praw.ini
|
settings.py
|
||||||
data.db
|
data.db
|
||||||
data.db.bak
|
data.db.bak
|
||||||
data/archive/*
|
data/archive/*
|
||||||
|
|
|
@ -7,6 +7,7 @@ import requests
|
||||||
import time
|
import time
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
import settings
|
||||||
from feeds import hackernews, reddit, tildes, manual
|
from feeds import hackernews, reddit, tildes, manual
|
||||||
|
|
||||||
OUTLINE_API = 'https://api.outline.com/v3/parse_article'
|
OUTLINE_API = 'https://api.outline.com/v3/parse_article'
|
||||||
|
@ -17,9 +18,15 @@ TWO_DAYS = 60*60*24*2
|
||||||
|
|
||||||
def list():
|
def list():
|
||||||
feed = []
|
feed = []
|
||||||
feed += [(x, 'hackernews') for x in hackernews.feed()[:15]]
|
if settings.NUM_HACKERNEWS:
|
||||||
feed += [(x, 'reddit') for x in reddit.feed()[:10]]
|
feed += [(x, 'hackernews') for x in hackernews.feed()[:settings.NUM_HACKERNEWS]]
|
||||||
feed += [(x, 'tildes') for x in tildes.feed()[:5]]
|
|
||||||
|
if settings.NUM_REDDIT:
|
||||||
|
feed += [(x, 'reddit') for x in reddit.feed()[:settings.NUM_REDDIT]]
|
||||||
|
|
||||||
|
if settings.NUM_TILDES:
|
||||||
|
feed += [(x, 'tildes') for x in tildes.feed()[:settings.NUM_TILDES]]
|
||||||
|
|
||||||
return feed
|
return feed
|
||||||
|
|
||||||
def get_article(url):
|
def get_article(url):
|
||||||
|
|
|
@ -12,18 +12,24 @@ from praw.exceptions import PRAWException
|
||||||
from praw.models import MoreComments
|
from praw.models import MoreComments
|
||||||
from prawcore.exceptions import PrawcoreException
|
from prawcore.exceptions import PrawcoreException
|
||||||
|
|
||||||
|
import settings
|
||||||
from utils import render_md, clean
|
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'
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
reddit = praw.Reddit('bot')
|
if settings.NUM_REDDIT:
|
||||||
|
reddit = praw.Reddit(
|
||||||
|
client_id=settings.REDDIT_CLIENT_ID,
|
||||||
|
client_secret=settings.REDDIT_CLIENT_SECRET,
|
||||||
|
user_agent=settings.REDDIT_USER_AGENT,
|
||||||
|
)
|
||||||
|
|
||||||
|
subs = '+'.join(settings.SUBREDDITS)
|
||||||
|
|
||||||
def feed():
|
def feed():
|
||||||
try:
|
try:
|
||||||
return [x.id for x in reddit.subreddit(SUBREDDITS).hot()]
|
return [x.id for x in reddit.subreddit(subs).hot()]
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
except PRAWException as e:
|
except PRAWException as e:
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[bot]
|
|
||||||
client_id=
|
|
||||||
client_secret=
|
|
||||||
user_agent=
|
|
40
apiserver/settings.py.example
Normal file
40
apiserver/settings.py.example
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# QotNews settings
|
||||||
|
# edit this file and save it as settings.py
|
||||||
|
|
||||||
|
# Feed Lengths
|
||||||
|
# Number of top items from each site to pull
|
||||||
|
# set to 0 to disable that site
|
||||||
|
NUM_HACKERNEWS = 15
|
||||||
|
NUM_REDDIT = 10
|
||||||
|
NUM_TILDES = 5
|
||||||
|
|
||||||
|
# Reddit account info
|
||||||
|
# leave blank if not using Reddit
|
||||||
|
REDDIT_CLIENT_ID = ''
|
||||||
|
REDDIT_CLIENT_SECRET = ''
|
||||||
|
REDDIT_USER_AGENT = ''
|
||||||
|
|
||||||
|
SUBREDDITS = [
|
||||||
|
'Economics',
|
||||||
|
'AcademicPhilosophy',
|
||||||
|
'DepthHub',
|
||||||
|
'Foodforthought',
|
||||||
|
'HistoryofIdeas',
|
||||||
|
'LaymanJournals',
|
||||||
|
'PhilosophyofScience',
|
||||||
|
'PoliticsPDFs',
|
||||||
|
'Scholar',
|
||||||
|
'StateOfTheUnion',
|
||||||
|
'TheAgora',
|
||||||
|
'TrueFilm',
|
||||||
|
'TrueReddit',
|
||||||
|
'UniversityofReddit',
|
||||||
|
'culturalstudies',
|
||||||
|
'hardscience',
|
||||||
|
'indepthsports',
|
||||||
|
'indepthstories',
|
||||||
|
'ludology',
|
||||||
|
'neurophilosophy',
|
||||||
|
'resilientcommunities',
|
||||||
|
'worldevents',
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user