diff --git a/app.py b/app.py index 48adb6e..31a1e04 100644 --- a/app.py +++ b/app.py @@ -10,22 +10,22 @@ TOKEN = os.environ['TOKEN'] TOKEN_CG_ID = os.environ['TOKEN_CG_ID'] +TOKEN_NAME = f"{TOKEN}USD" API_PORT = int(os.environ.get('API_PORT', 5000)) ALLORA_VALIDATOR_API_URL = str(os.environ.get('ALLORA_VALIDATOR_API_URL','http://localhost:1317/emissions/v1/network_loss/')) -app = Flask(__name__) DATABASE_PATH = os.environ.get('DATABASE_PATH', 'prices.db') GEN_TEST_DATA = bool(os.environ.get('GEN_TEST_DATA', False)) WORKER_ADDRESS_TEST_1 = str(os.environ.get('WORKER_ADDRESS_TEST_1', "allo1tvh6nv02vq6m4mevsa9wkscw53yxvfn7xt8rud")) -TOKEN_NAME = f"{TOKEN}USD" - HTTP_RESPONSE_CODE_200 = 200 HTTP_RESPONSE_CODE_400 = 400 HTTP_RESPONSE_CODE_404 = 404 HTTP_RESPONSE_CODE_500 = 500 +app = Flask(__name__) + # Define retry decorator @retrying.retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5) def fetch_prices(url): @@ -37,14 +37,15 @@ def check_create_table(): conn = sqlite3.connect(DATABASE_PATH) cursor = conn.cursor() cursor.execute('''CREATE TABLE IF NOT EXISTS prices - (timestamp INTEGER PRIMARY KEY, token TEXT, price REAL)''') + (timestamp INTEGER, token TEXT, price REAL, + PRIMARY KEY (timestamp, token))''') conn.commit() conn.close() @app.route('/update///') @app.route('/update') -def update_price(token_name=TOKEN, token_from=TOKEN_CG_ID, token_to='usd'): +def update_price(token_name=TOKEN_NAME, token_from=TOKEN_CG_ID, token_to='usd'): # Attempt initializing the token data if not already try: init_price_token(token_name, token_from, token_to)