modified white nonsense bot code to be used with any text file with a list of sayings; added notify function to globals and made pushover optional
This commit is contained in:
20
dog_facts.py
20
dog_facts.py
@ -5,16 +5,6 @@ from collections import namedtuple as nt
|
||||
from munch import DefaultMunch
|
||||
from globals import *
|
||||
|
||||
|
||||
def notify(priority, message):
|
||||
r = post("https://api.pushover.net/1/messages.json", data = {
|
||||
"token": po_bots_token,
|
||||
"user": po_user_token,
|
||||
"message": "dog facts: " + message,
|
||||
"priority": priority
|
||||
})
|
||||
|
||||
|
||||
post_endpoint = f"{bots_endpoint}/api/v1/statuses"
|
||||
api_url = 'https://dogapi.dog/api/v2/facts'
|
||||
headers = {
|
||||
@ -27,8 +17,10 @@ if response.reason == "OK":
|
||||
payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "unlisted"}
|
||||
response = post(post_endpoint, headers=headers, json=payload)
|
||||
if response.reason == "OK":
|
||||
notify(-1, loads(response.text)['uri'])
|
||||
else:
|
||||
notify(1, response.reason)
|
||||
if po_user_token:
|
||||
notify(-1, 'dog facts post url: ' + loads(response.text)['uri'])
|
||||
else:
|
||||
notify(1, 'dog facts post error: ' + response.reason)
|
||||
else:
|
||||
notify(1, response.reason)
|
||||
if po_user_token:
|
||||
notify(1, 'dog facts api call failed: ' + response.reason)
|
||||
|
Reference in New Issue
Block a user