add quotes code
This commit is contained in:
@ -28,6 +28,9 @@ quip_file = getenv('QUIP_FILE')
|
|||||||
quip_tags = getenv('QUIP_TAGS')
|
quip_tags = getenv('QUIP_TAGS')
|
||||||
quip_token = getenv('QUIP_TOKEN')
|
quip_token = getenv('QUIP_TOKEN')
|
||||||
|
|
||||||
|
## Quotes file path
|
||||||
|
quotes_source = getenv('QUOTES_SOURCE')
|
||||||
|
|
||||||
# Pushover creds
|
# Pushover creds
|
||||||
po_endpoint = getenv('PUSHOVER_ENDPOINT')
|
po_endpoint = getenv('PUSHOVER_ENDPOINT')
|
||||||
po_user_token = getenv('PUSHOVER_USER_TOKEN')
|
po_user_token = getenv('PUSHOVER_USER_TOKEN')
|
||||||
|
20
quotes.py
Normal file
20
quotes.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from requests import get, post
|
||||||
|
from json import loads, dumps
|
||||||
|
from os import getenv
|
||||||
|
from random import randint
|
||||||
|
import csv, io
|
||||||
|
from globals import *
|
||||||
|
|
||||||
|
response = get(quotes_source)
|
||||||
|
if response.reason == "OK":
|
||||||
|
choices = loads(dumps(list(csv.DictReader(io.StringIO(response.text)))))
|
||||||
|
choice = choices[randint(0, len(choices) - 1)]
|
||||||
|
headers = {'Authorization': 'Bearer ' + randomquotes_token}
|
||||||
|
payload = {'status': f"{choice['quote']}\n\n - {choice['author']}\n\n#RandomQuote #quotes #quote #bot", 'visibility': 'public'}
|
||||||
|
result = post(bots_endpoint + '/api/v1/statuses', headers=headers, data=payload)
|
||||||
|
if result.reason == "OK":
|
||||||
|
if po_user_token:
|
||||||
|
notify(-1, f'random quotes post: {loads(result.text)['url']}')
|
||||||
|
else:
|
||||||
|
if po_user_token:
|
||||||
|
notify(0, f'random quotes error: {result.status_code} - {result.reason}')
|
Reference in New Issue
Block a user