-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_apis.py
More file actions
29 lines (20 loc) · 963 Bytes
/
call_apis.py
File metadata and controls
29 lines (20 loc) · 963 Bytes
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
import requests
import logging
logging.basicConfig(level=logging.INFO,
format="%(asctime)s - %(levelname)s %(name)s:%(lineno)d - %(message)s")
logger = logging.getLogger(__name__)
def get_subreddit_top_post(subreddit="aww", user_agent=""):
url = f"https://www.reddit.com/r/{subreddit}/top.json"
response = requests.get(url, headers={"User-Agent": user_agent})
resp_data = response.json()["data"]["children"][0]["data"]
return {'url': f"https://www.reddit.com/{resp_data['permalink']}", 'title': resp_data['title']}
def post_to_flowdock(flowdock_token, flow_token, bot_name, message, tag="productivity"):
url = f"https://{flowdock_token}@api.flowdock.com/messages/chat/{flow_token}"
payload = \
{"external_user_name": bot_name,
"content": f"{message}",
"tags": tag}
headers = {
'content-type': "application/json"
}
requests.post(url, json=payload, headers=headers)