23 lines
839 B
Python
23 lines
839 B
Python
from requests import get, post
|
|
from json import loads, dumps
|
|
from os import getenv
|
|
from random import randint
|
|
import csv, io
|
|
|
|
post_token = getenv('POST_TOKEN')
|
|
post_endpoint = getenv('POST_ENDPOINT')
|
|
source_token = getenv('SOURCE_TOKEN')
|
|
source_endpoint = getenv('SOURCE_ENDPOINT')
|
|
|
|
source_object = get(source_endpoint)
|
|
if source_object.reason == "OK":
|
|
reader = csv.DictReader(io.StringIO(source_object.text))
|
|
source_data = dumps(list(reader))
|
|
choices = loads(source_data)
|
|
choice = choices[randint(0, len(choices) - 1)]
|
|
headers = {'Authorization': 'Bearer ' + post_token}
|
|
payload = {'status': f"{choice['quote']}\n\n - {choice['author']}\n\n#RandomQuote #quotes #quote #bot", 'visibility': 'public'}
|
|
response = post(post_endpoint, headers=headers, data=payload)
|
|
print(response.reason)
|
|
print(loads(response.text)['url'])
|