Move feed and Praw config to settings.py

This commit is contained in:
Tanner Collin 2020-11-02 02:26:54 +00:00
parent 7acce407e9
commit ca78a6d7a9
6 changed files with 66 additions and 19 deletions

View File

@ -35,7 +35,7 @@ $ source env/bin/activate
(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
* Click "Create app"
@ -44,16 +44,14 @@ Configure Praw for your Reddit account:
* Description: blank
* About URL: blank
* 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
(env) $ vim praw.ini
[bot]
client_id=paste here
client_secret=paste here
user_agent=script by github/your-username-here
(env) $ vim settings.py.example
```
Edit it and save it as `settings.py`.
Now you can run the server:
```text

View File

@ -105,7 +105,7 @@ ENV/
# DB
db.sqlite3
praw.ini
settings.py
data.db
data.db.bak
data/archive/*

View File

@ -7,6 +7,7 @@ import requests
import time
from bs4 import BeautifulSoup
import settings
from feeds import hackernews, reddit, tildes, manual
OUTLINE_API = 'https://api.outline.com/v3/parse_article'
@ -17,9 +18,15 @@ TWO_DAYS = 60*60*24*2
def list():
feed = []
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]]
if settings.NUM_HACKERNEWS:
feed += [(x, 'hackernews') for x in hackernews.feed()[:settings.NUM_HACKERNEWS]]
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
def get_article(url):

View File

@ -12,18 +12,24 @@ from praw.exceptions import PRAWException
from praw.models import MoreComments
from prawcore.exceptions import PrawcoreException
import settings
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_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():
try:
return [x.id for x in reddit.subreddit(SUBREDDITS).hot()]
return [x.id for x in reddit.subreddit(subs).hot()]
except KeyboardInterrupt:
raise
except PRAWException as e:

View File

@ -1,4 +0,0 @@
[bot]
client_id=
client_secret=
user_agent=

View 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',
]