refactor: replace Google Sheets with ODS processing
Some checks are pending
Docker / build (push) Waiting to run

Replaced the use of Google Sheets (pygsheets and related
dependencies) with local .ods file processing using Pandas.
This simplifies the data handling by removing external
dependencies and streamlining updates directly within .ods files.

Fixes issues related to reliance on Google API and enhances
performance by processing data locally.
This commit is contained in:
Kumi 2024-11-13 12:55:17 +01:00
parent f95782b093
commit 06794c3cea
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 20 additions and 27 deletions

View file

@ -15,7 +15,6 @@ from .models import (
) )
from requests import Session from requests import Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import pygsheets
import pytz import pytz
from django.conf import settings from django.conf import settings
@ -394,23 +393,22 @@ def update_dominance(data):
) )
dominance.save() dominance.save()
df = pd.read_excel(DATA_FILE, engine="odf", sheet_name="Sheet7")
start_row, end_row = 2, 9999
gc = pygsheets.authorize(service_file="service_account_credentials.json") start_col, end_col = 0, 2
sh = gc.open("zcash_bitcoin") values_mat = df.iloc[start_row:end_row, start_col:end_col].to_numpy()
wks = sh.worksheet_by_title("Sheet7")
values_mat = wks.get_values(start=(3, 1), end=(9999, 2), returnas="matrix")
k = len(values_mat) k = len(values_mat)
date_aux = datetime.datetime.strptime(values_mat[k - 1][0], "%Y-%m-%d") 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.strftime(date.today(), "%Y-%m-%d")
date_aux2 = datetime.datetime.strptime(date_aux2, "%Y-%m-%d") date_aux2 = datetime.datetime.strptime(date_aux2, "%Y-%m-%d")
if date_aux < date_aux2: if date_aux < date_aux2:
cell = "B" + str(k + 3) values_mat[k][1] = dominance.dominance
wks.update_value(cell, dominance.dominance) values_mat[k][0] = dominance.date
cell = "A" + str(k + 3)
wks.update_value(cell, 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") print("spreadsheet updated")
else: else:
print("spreadsheet already with the latest data") 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.rank = int(data["data"]["XMR"]["cmc_rank"])
rank.save() rank.save()
gc = pygsheets.authorize(service_file="service_account_credentials.json") df = pd.read_excel(DATA_FILE, engine="odf", sheet_name="Sheet8")
sh = gc.open("zcash_bitcoin") start_row, end_row = 2, 9999
wks = sh.worksheet_by_title("Sheet8") start_col, end_col = 0, 2
values_mat = df.iloc[start_row:end_row, start_col:end_col].to_numpy()
values_mat = wks.get_values(start=(3, 1), end=(9999, 2), returnas="matrix")
k = len(values_mat) k = len(values_mat)
date_aux = datetime.datetime.strptime(values_mat[k - 1][0], "%Y-%m-%d") 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.strftime(date.today(), "%Y-%m-%d")
date_aux2 = datetime.datetime.strptime(date_aux2, "%Y-%m-%d") date_aux2 = datetime.datetime.strptime(date_aux2, "%Y-%m-%d")
if date_aux < date_aux2: if date_aux < date_aux2:
cell = "B" + str(k + 3) values_mat[k][1] = rank.rank
wks.update_value(cell, rank.rank) values_mat[k][0] = rank.date
cell = "A" + str(k + 3)
wks.update_value(cell, 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") print("spreadsheet updated")
else: else:
print("spreadsheet already with the latest data") print("spreadsheet already with the latest data")

View file

@ -15,10 +15,6 @@ django-bootstrap4==24.4
django-csp==3.8 django-csp==3.8
feedparser==6.0.11 feedparser==6.0.11
frozenlist==1.5.0 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? gunicorn # TODO: Should this really be a project dependency?
httplib2==0.20.4 httplib2==0.20.4
multidict==6.1.0 multidict==6.1.0
@ -31,12 +27,10 @@ psaw==0.1.0 # TODO: Unmaintained, recommends switch to https://github.com/mattpo
psycopg2-binary psycopg2-binary
pyasn1==0.6.1 pyasn1==0.6.1
pyasn1-modules==0.4.1 pyasn1-modules==0.4.1
pygsheets==2.0.6
pyparsing==3.2.0 pyparsing==3.2.0
python-dateutil==2.9.0.post0 python-dateutil==2.9.0.post0
pytz pytz
requests<3.0.0 requests<3.0.0
requests-oauthlib==1.3.1 # TODO: 2.0.0
rsa==4.9 rsa==4.9
sgmllib3k==1.0.0 sgmllib3k==1.0.0
six==1.16.0 six==1.16.0