-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathsingle_tweet_bot.py
48 lines (39 loc) · 2.41 KB
/
single_tweet_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tweepy, time, sys, json
from datetime import datetime
from coti import create_json, write_output, get_output
from config import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET
client = tweepy.Client(
consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET,
access_token=ACCESS_KEY, access_token_secret=ACCESS_SECRET
)
dolarjson = json.loads(get_output())
updated = datetime.strptime(dolarjson['updated'], '%Y-%m-%d %H:%M:%S').strftime('📅 %d/%m ⏳%H:%M')
response = updated + "\n\n" \
"💱\n■ Cambios Chaco:\n"\
"Compra: " + "{:,}".format(dolarjson['dolarpy']['cambioschaco']['compra']).replace(',','.')[:-2] + \
" | Venta: " + "{:,}".format(dolarjson['dolarpy']['cambioschaco']['venta']).replace(',','.')[:-2] + \
"\n■ Mundial:\n" \
"Compra: " + "{:,}".format(dolarjson['dolarpy']['mundialcambios']['compra']).replace(',','.')[:-2] + \
" | Venta: " + "{:,}".format(dolarjson['dolarpy']['mundialcambios']['venta']).replace(',','.')[:-2] + \
"\n■ MyD Cambios:\n" \
"Compra: " + "{:,}".format(dolarjson['dolarpy']['mydcambios']['compra']).replace(',','.')[:-2] + \
" | Venta: " + "{:,}".format(dolarjson['dolarpy']['mydcambios']['venta']).replace(',','.')[:-2] + \
"\n■ Maxicambios:\n" \
"Compra: " + "{:,}".format(dolarjson['dolarpy']['maxicambios']['compra']).replace(',','.')[:-2] + \
" | Venta: " + "{:,}".format(dolarjson['dolarpy']['maxicambios']['venta']).replace(',','.')[:-2] + \
"\n\n🏛\n■ BCP:\n"\
"Compra: " + "{:,}".format(int(dolarjson['dolarpy']['bcp']['compra'])).replace(',','.') + \
" | Venta: " + "{:,}".format(int(dolarjson['dolarpy']['bcp']['venta'])).replace(',','.') + \
"\n■ SET:\n" \
"Compra: " + "{:,}".format(int(dolarjson['dolarpy']['set']['compra'])).replace(',','.') +\
" | Venta: " + "{:,}".format(int(dolarjson['dolarpy']['set']['venta'])).replace(',','.')
client.create_tweet(text=response)
try: # Mastodon integration
from mastodon import Mastodon
from config import MASTODON_ACCESS_TOKEN, MASTODON_API_BASE
mastodon = Mastodon(access_token=MASTODON_ACCESS_TOKEN, api_base_url = MASTODON_API_BASE)
mastodon.status_post(response, language='es', visibility="unlisted")
except Exception as e:
print(e)