diff --git a/globals.py b/globals.py index ea2264a..5957235 100644 --- a/globals.py +++ b/globals.py @@ -28,6 +28,9 @@ quip_file = getenv('QUIP_FILE') quip_tags = getenv('QUIP_TAGS') quip_token = getenv('QUIP_TOKEN') +## Quotes file path +quotes_source = getenv('QUOTES_SOURCE') + # Pushover creds po_endpoint = getenv('PUSHOVER_ENDPOINT') po_user_token = getenv('PUSHOVER_USER_TOKEN') diff --git a/quotes.py b/quotes.py new file mode 100644 index 0000000..0abedd7 --- /dev/null +++ b/quotes.py @@ -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}')