-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompts.py
33 lines (25 loc) · 1.02 KB
/
prompts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#python reddit api wrapper
import praw
#to choose from a random prompt
import random
import os
#reddit bot id, secret, and username and password for my account
REDDIT_ID = os.environ.get('REDDIT_ID')
REDDIT_SECRET = os.environ.get('REDDIT_SECRET')
REDDIT_PWD = os.environ.get('REDDIT_PWD')
REDDIT_USERNAME = os.environ.get('REDDIT_USERNAME')
def promptgen():
#reddit instance
reddit = praw.Reddit(client_id= REDDIT_ID,
client_secret= REDDIT_SECRET,
password= REDDIT_PWD,
user_agent='CreatiBot',
username= REDDIT_USERNAME)
#gets subreddit instance
subreddit = reddit.subreddit('writingprompts')
#newest 50 writing prompts
new50prompts = []
#for submission in the Writing Prompts flair, get list of prompts, stripping [WP] from the front
for submission in subreddit.search('flair:"Writing Prompt"', limit=50):
new50prompts.append(submission.title.replace("[WP]", ''))
return random.choice(new50prompts)