Skip to content

Commit

Permalink
no longer uses forex, using UOL quotes instead
Browse files Browse the repository at this point in the history
  • Loading branch information
moutella committed Feb 21, 2020
1 parent 3a151bd commit 3b7baf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
python-decouple
tweepy
forex-python
tweepy
14 changes: 9 additions & 5 deletions update_bot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import json
import tweepy
import requests

from forex_python.converter import CurrencyRates
from decouple import config

consumer_key = config('consumer_key')
Expand All @@ -23,14 +23,17 @@
pokemons_file = open('pokedex.json', 'r')
pokemon = json.load(pokemons_file)

currency_rates = CurrencyRates()
dolar_real = str(round(currency_rates.get_rate('USD','BRL'), 2))

uol_quote = requests.get('http://cotacoes.economia.uol.com.br/cambioJSONChart.html?type=d&cod=BRL&mt=off')
dolar_json = json.loads(uol_quote.content)
dolar_real = "{:.2f}".format(dolar_json[1][-1]['ask'])

data = {}
subiu = False
first_tweet = False
data['exchange'] = dolar_real
if 'exchange' in config:
data['exchange'] = config['exchange']

if data['exchange'] == dolar_real:
tweet = False
else:
Expand All @@ -40,7 +43,6 @@
data['exchange'] = dolar_real

else:
data['exchange'] = dolar_real
tweet = True
first_tweet = True
if tweet:
Expand All @@ -62,3 +64,5 @@
api.update_with_media(imagepath, status)
config_file = open('config.json', 'w')
json.dump(data, config_file)
else:
print("Não mudou {}".format(data['exchange']))

0 comments on commit 3b7baf7

Please sign in to comment.