21 lines
835 B
Python
21 lines
835 B
Python
|
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}')
|