-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutie_bot.py
More file actions
35 lines (30 loc) · 1.11 KB
/
cutie_bot.py
File metadata and controls
35 lines (30 loc) · 1.11 KB
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
from call_apis import get_subreddit_top_post, post_to_flowdock
import logging
import random
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s %(name)s:%(lineno)d - %(message)s")
logger = logging.getLogger(__name__)
subreddits = ["RarePuppers",
"SupermodelCats",
"awwducational",
"corgi",
"PartyParrot",
"TheCatTrapIsWorking",
"Catloaf",
"eyebleach",
"Otters"
]
def send_message(flowdock_token, flow_token, bot_name="cutiebot"):
try:
subreddit = random.choice(subreddits)
result = get_subreddit_top_post(subreddit=subreddit,
user_agent=bot_name)
title = result.get('title')
link = result.get('url')
message = f"Look at this cutie:\n \"{title}\"\n {link}"
post_to_flowdock(flowdock_token,
flow_token,
bot_name,
message,
tag=subreddit)
except BaseException as e:
logger.info(e)