-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreddit.py
46 lines (44 loc) · 1.74 KB
/
reddit.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
34
35
36
37
38
39
40
41
42
43
44
45
46
import praw
from secret import *
import random
def generate_text():
print("Generating Text")
reddit = praw.Reddit(client_id=REDDIT_CLIENT_ID,
client_secret=REDDIT_CLIENT_SECRET,
user_agent=REDDIT_APP_NAME,
username=REDDIT_USERNAME,
password=REDDIT_PASSWORD)
subreddit = reddit.subreddit('WritingPrompts')
r = random.randint(3, 49)
top_subreddit = subreddit.hot(limit = 50)
submission = [i for i in top_subreddit][r]
num = 1
prompt = submission.title[5:]
author = submission.author
if author:
print("author found")
author = author.name
print(author)
else:
author = " a reddit user "
comment_author = submission.comments[num].author
if comment_author:
comment_author = comment_author.name
else:
comment_author = " a reddit user "
story = submission.comments[num].body
print(author)
title = prompt[:20]
text = "Hey Guys, This is the Writing Prompt Channel. Here, we take posts from reddit and read out loud the best stories with the help of a bot. Enjoy this amazing story.\n\n"
print("Opening File")
file = open("wp.txt", "w")
text += "The Writing Prompt by user " + author + "\n"
text += prompt + "\n\n\n"
text += "Here is the amazing story made with the help of the prompt by user "+ comment_author + " \n\n\n"
text += story +"\n\n THE END \n\n"
text += "Thank you guys for checking out this channel. Please subscribe, like and share this video. See you in next one. Thank You and Good Bye."
print("Writing File")
file.write(text)
file.close()
print("Text generated")
return {"text": text, "title":title}