From 42c527dbe44144956a1f681f50a18ab6d7e1bebd Mon Sep 17 00:00:00 2001 From: anon Date: Tue, 31 May 2022 11:31:50 -0300 Subject: [PATCH] test --- .gitignore | 3 ++- monerojnet/views.py | 46 ++++++++++++++++++++++++------------------- moneropro/settings.py | 8 ++++---- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 6cd884a..e9e3b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ venv/ *.sqlite3 migrations/ -service_account_credentials.json \ No newline at end of file +service_account_credentials.json +settings.json \ No newline at end of file diff --git a/monerojnet/views.py b/monerojnet/views.py index ead6300..8e52809 100644 --- a/monerojnet/views.py +++ b/monerojnet/views.py @@ -14,17 +14,15 @@ import locale import pandas as pd from operator import truediv import pygsheets -import feedparser from requests import Session from psaw import PushshiftAPI #library Pushshift from django.contrib.staticfiles.storage import staticfiles_storage locale.setlocale(locale.LC_ALL, 'en_US.utf8') - api = PushshiftAPI() ########################################### -# Próximos gráficos +# Useful Functions ########################################### def data_prep_posts(subreddit, start_time, end_time, filters, limit): @@ -43,25 +41,28 @@ def data_prep_comments(term, start_time, end_time, filters, limit): return pd.DataFrame(comments) def get_latest(): - url = '' - parameters = { - 'convert':'USD', - } - headers = { - 'Accepts': 'application/json', - 'X-CMC_PRO_API_KEY': '', - } + with open("settings.json") as file: + data = json.load(file) - session = Session() - session.headers.update(headers) + url = data["metrics_provider"][0]["price_url"] + parameters = { + 'convert':'USD', + } + headers = { + 'Accepts': 'application/json', + data["metrics_provider"][0]["api_key_name"]: data["metrics_provider"][0]["api_key_value"], + } - try: - response = session.get(url, params=parameters) - data = json.loads(response.text) - print(data) - except (ConnectionError, Timeout, TooManyRedirects) as e: - data = False + session = Session() + session.headers.update(headers) + try: + response = session.get(url, params=parameters) + data = json.loads(response.text) + except (ConnectionError, Timeout, TooManyRedirects) as e: + data = False + + file.close() return data def load_dominance(coin): @@ -209,6 +210,7 @@ def index(request): now_inflation = 0.001 now_units = 0 supply = 0 + get_latest() #load_dominance('xmr') #load_rank('xmr') @@ -3474,7 +3476,11 @@ def get_prices(symbol): if getthem: test = True count = 1 - request = '' + data = '' + with open("settings.json") as file: + data = json.load(file) + file.close() + request = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] while test: print('page ' + str(count)) count += 1 diff --git a/moneropro/settings.py b/moneropro/settings.py index 15f6b9d..a6d87ca 100644 --- a/moneropro/settings.py +++ b/moneropro/settings.py @@ -29,12 +29,12 @@ STATICFILES_DIRS = [ # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '' +SECRET_KEY = 'asdfasdfhasdfjasdf7ads7f7sd8fasdf7tasdfgasjhfgsjakgh' # SECURITY WARNING: don't run with debug turned on in production! -#DEBUG = True -DEBUG = False -STATIC_ROOT = "/var/www/moneropro/static/" +DEBUG = True +#DEBUG = False +#STATIC_ROOT = "/var/www/moneropro/static/" ALLOWED_HOSTS = ['www.moneroj.net', 'localhost', '127.0.0.1', 'moneroj.net']