From 98162a99e80cffcf4fb4ae0e338545bf9e3d2df1 Mon Sep 17 00:00:00 2001 From: BiRabittoh Date: Fri, 4 Aug 2023 16:50:59 +0200 Subject: [PATCH] almost working --- .vscode/launch.json | 27 +++++++++++++++++ artbound_python/api.py | 5 ++-- artbound_python/cache.py | 43 ++++++++++++++-------------- artbound_python/static/script.js | 3 +- artbound_python/templates/index.html | 4 +-- artbound_python/views.py | 14 +++++---- 6 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9c20180 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Flask", + "type": "python", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "artbound_python", + "FLASK_DEBUG": "1" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload", + "--port", + "1111" + ], + "jinja": true, + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/artbound_python/api.py b/artbound_python/api.py index 5a56cea..ef52b57 100644 --- a/artbound_python/api.py +++ b/artbound_python/api.py @@ -58,7 +58,6 @@ def get_file(file_id, cache_path): return file_name load_dotenv() -SPREADSHEET_ID = os.getenv("SPREADSHEET_ID") #'1OHI2PA62LNrEbViq87AyUlX1ni3Gr9gttxPLvkOzZ6g' -RANGE = os.getenv("RANGE")#'Risposte del modulo 1!A2:E' - +SPREADSHEET_ID = os.getenv("SPREADSHEET_ID") +RANGE = os.getenv("RANGE") creds = get_google_credentials() diff --git a/artbound_python/cache.py b/artbound_python/cache.py index d5a8d52..7c36880 100644 --- a/artbound_python/cache.py +++ b/artbound_python/cache.py @@ -9,7 +9,7 @@ CACHE_DIRECTORY = "cache" CACHE_PATH = os.path.join("artbound_python", "static", "res", CACHE_DIRECTORY) db = [] -last_updated = None +last_updated = "" with suppress(FileExistsError): os.makedirs(CACHE_PATH) @@ -31,34 +31,33 @@ def clear_cache(): shutil.rmtree(CACHE_PATH) def handle_fanart(fanart): - fanart_id = fanart["id"] - fanart["content"] = download_fanart(fanart_id) + fanart["content"] = download_fanart(fanart["id"]) return fanart def handle_row(row): fanart_date = datetime.strptime(row[0], "%d/%m/%Y %H.%M.%S") - fanart_id = row[3].strip("https://drive.google.com/open?id=") + fanart_id = row[3][33:] return { 'id': fanart_id, 'date': fanart_date.strftime("%Y-%m"), 'name': row[1], 'enabled': 1 } - -def update_database(): - global db - global last_updated - db = [ handle_row(x) for x in get_rows() ] - if len(db) == 0: - print("No fanarts!") - exit(1) - last_updated = datetime.now() - -def get_fanarts(month): - return [ handle_fanart(x) for x in db if x["date"] == month ] - -update_database() - -if __name__ == "__main__": - print(handle_fanart({ 'id': '1_DUo-dW40So3T24a91SyGrEcAGKfP0l_'})) - #clear_cache() + +class DB(): + def update_database(self): + self.db = [ handle_row(x) for x in get_rows() ] + if len(self.db) == 0: + print("No fanarts!") + exit(1) + self.last_updated = datetime.now() + + def __init__(self): + self.db = [] + self.update_database() + + def get_fanarts(self, month): + return [ handle_fanart(x) for x in self.db if x["date"] == month ] + + def get_last_updated(self): + return self.last_updated.strftime("%d/%m/%Y %H:%M") diff --git a/artbound_python/static/script.js b/artbound_python/static/script.js index 157514e..11b8430 100644 --- a/artbound_python/static/script.js +++ b/artbound_python/static/script.js @@ -101,7 +101,7 @@ function getNewCardHtml(element) { async function updateFanartList() { main_container_div.hidden = false; - content_div.innerHTML = "" + //content_div.innerHTML = "" let i = 0; for (fanart of fanarts) { @@ -212,7 +212,6 @@ async function postData(url = "", data = {}, contentType = "application/x-www-fo } function getArtworks() { - document.getElementById("") postData("/", { month: month_input.value }, "application/json").then((data) => { console.log(data); fanarts = data; diff --git a/artbound_python/templates/index.html b/artbound_python/templates/index.html index 53d1662..c3f40be 100644 --- a/artbound_python/templates/index.html +++ b/artbound_python/templates/index.html @@ -26,12 +26,12 @@ ArtBound Panel 2.0 -

Perché semplice è meglio.

+ {{ last_updated }}
- getArtworks + Ottieni