diff --git a/app/charts/synchronous.py b/app/charts/synchronous.py index 3964102..c5ebb2e 100644 --- a/app/charts/synchronous.py +++ b/app/charts/synchronous.py @@ -15,7 +15,6 @@ from .models import ( ) from requests import Session from requests.exceptions import ConnectionError, Timeout, TooManyRedirects -import pygsheets import pytz from django.conf import settings @@ -394,23 +393,22 @@ def update_dominance(data): ) dominance.save() - - - gc = pygsheets.authorize(service_file="service_account_credentials.json") - sh = gc.open("zcash_bitcoin") - wks = sh.worksheet_by_title("Sheet7") - - values_mat = wks.get_values(start=(3, 1), end=(9999, 2), returnas="matrix") + df = pd.read_excel(DATA_FILE, engine="odf", sheet_name="Sheet7") + start_row, end_row = 2, 9999 + start_col, end_col = 0, 2 + values_mat = df.iloc[start_row:end_row, start_col:end_col].to_numpy() k = len(values_mat) date_aux = datetime.datetime.strptime(values_mat[k - 1][0], "%Y-%m-%d") date_aux2 = datetime.datetime.strftime(date.today(), "%Y-%m-%d") date_aux2 = datetime.datetime.strptime(date_aux2, "%Y-%m-%d") if date_aux < date_aux2: - cell = "B" + str(k + 3) - wks.update_value(cell, dominance.dominance) - cell = "A" + str(k + 3) - wks.update_value(cell, dominance.date) + values_mat[k][1] = dominance.dominance + values_mat[k][0] = dominance.date + + df.iloc[start_row:end_row, start_col:end_col] = values_mat + df.to_excel(DATA_FILE, sheet_name="Sheet7", index=False) + print("spreadsheet updated") else: print("spreadsheet already with the latest data") @@ -432,21 +430,22 @@ def update_rank(data=None): rank.rank = int(data["data"]["XMR"]["cmc_rank"]) rank.save() - gc = pygsheets.authorize(service_file="service_account_credentials.json") - sh = gc.open("zcash_bitcoin") - wks = sh.worksheet_by_title("Sheet8") - - values_mat = wks.get_values(start=(3, 1), end=(9999, 2), returnas="matrix") + df = pd.read_excel(DATA_FILE, engine="odf", sheet_name="Sheet8") + start_row, end_row = 2, 9999 + start_col, end_col = 0, 2 + values_mat = df.iloc[start_row:end_row, start_col:end_col].to_numpy() k = len(values_mat) date_aux = datetime.datetime.strptime(values_mat[k - 1][0], "%Y-%m-%d") date_aux2 = datetime.datetime.strftime(date.today(), "%Y-%m-%d") date_aux2 = datetime.datetime.strptime(date_aux2, "%Y-%m-%d") if date_aux < date_aux2: - cell = "B" + str(k + 3) - wks.update_value(cell, rank.rank) - cell = "A" + str(k + 3) - wks.update_value(cell, rank.date) + values_mat[k][1] = rank.rank + values_mat[k][0] = rank.date + + df.iloc[start_row:end_row, start_col:end_col] = values_mat + df.to_excel(DATA_FILE, sheet_name="Sheet8", index=False) + print("spreadsheet updated") else: print("spreadsheet already with the latest data") diff --git a/requirements.txt b/requirements.txt index c5afd81..50ba413 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,10 +15,6 @@ django-bootstrap4==24.4 django-csp==3.8 feedparser==6.0.11 frozenlist==1.5.0 -google-api-core<3.0.0 -google-api-python-client<3.0.0 -google-auth<3.0.0 -googleapis-common-protos<2.0.0 gunicorn # TODO: Should this really be a project dependency? httplib2==0.20.4 multidict==6.1.0 @@ -31,12 +27,10 @@ psaw==0.1.0 # TODO: Unmaintained, recommends switch to https://github.com/mattpo psycopg2-binary pyasn1==0.6.1 pyasn1-modules==0.4.1 -pygsheets==2.0.6 pyparsing==3.2.0 python-dateutil==2.9.0.post0 pytz requests<3.0.0 -requests-oauthlib==1.3.1 # TODO: 2.0.0 rsa==4.9 sgmllib3k==1.0.0 six==1.16.0