From 3b7baf7507b55a3657252dbe5f19bc06ffd32bf9 Mon Sep 17 00:00:00 2001 From: moutella Date: Fri, 21 Feb 2020 03:13:09 -0300 Subject: [PATCH] no longer uses forex, using UOL quotes instead --- requirements.txt | 3 +-- update_bot.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3272f28..ae64d9e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ python-decouple -tweepy -forex-python \ No newline at end of file +tweepy \ No newline at end of file diff --git a/update_bot.py b/update_bot.py index ce7f83a..8f7cda1 100644 --- a/update_bot.py +++ b/update_bot.py @@ -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') @@ -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: @@ -40,7 +43,6 @@ data['exchange'] = dolar_real else: - data['exchange'] = dolar_real tweet = True first_tweet = True if tweet: @@ -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'])) \ No newline at end of file