almost working
This commit is contained in:
parent
3072e0a7b9
commit
98162a99e8
27
.vscode/launch.json
vendored
Normal file
27
.vscode/launch.json
vendored
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -58,7 +58,6 @@ def get_file(file_id, cache_path):
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
SPREADSHEET_ID = os.getenv("SPREADSHEET_ID") #'1OHI2PA62LNrEbViq87AyUlX1ni3Gr9gttxPLvkOzZ6g'
|
SPREADSHEET_ID = os.getenv("SPREADSHEET_ID")
|
||||||
RANGE = os.getenv("RANGE")#'Risposte del modulo 1!A2:E'
|
RANGE = os.getenv("RANGE")
|
||||||
|
|
||||||
creds = get_google_credentials()
|
creds = get_google_credentials()
|
||||||
|
|
|
@ -9,7 +9,7 @@ CACHE_DIRECTORY = "cache"
|
||||||
CACHE_PATH = os.path.join("artbound_python", "static", "res", CACHE_DIRECTORY)
|
CACHE_PATH = os.path.join("artbound_python", "static", "res", CACHE_DIRECTORY)
|
||||||
|
|
||||||
db = []
|
db = []
|
||||||
last_updated = None
|
last_updated = ""
|
||||||
|
|
||||||
with suppress(FileExistsError):
|
with suppress(FileExistsError):
|
||||||
os.makedirs(CACHE_PATH)
|
os.makedirs(CACHE_PATH)
|
||||||
|
@ -31,13 +31,12 @@ def clear_cache():
|
||||||
shutil.rmtree(CACHE_PATH)
|
shutil.rmtree(CACHE_PATH)
|
||||||
|
|
||||||
def handle_fanart(fanart):
|
def handle_fanart(fanart):
|
||||||
fanart_id = fanart["id"]
|
fanart["content"] = download_fanart(fanart["id"])
|
||||||
fanart["content"] = download_fanart(fanart_id)
|
|
||||||
return fanart
|
return fanart
|
||||||
|
|
||||||
def handle_row(row):
|
def handle_row(row):
|
||||||
fanart_date = datetime.strptime(row[0], "%d/%m/%Y %H.%M.%S")
|
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 {
|
return {
|
||||||
'id': fanart_id,
|
'id': fanart_id,
|
||||||
'date': fanart_date.strftime("%Y-%m"),
|
'date': fanart_date.strftime("%Y-%m"),
|
||||||
|
@ -45,20 +44,20 @@ def handle_row(row):
|
||||||
'enabled': 1
|
'enabled': 1
|
||||||
}
|
}
|
||||||
|
|
||||||
def update_database():
|
class DB():
|
||||||
global db
|
def update_database(self):
|
||||||
global last_updated
|
self.db = [ handle_row(x) for x in get_rows() ]
|
||||||
db = [ handle_row(x) for x in get_rows() ]
|
if len(self.db) == 0:
|
||||||
if len(db) == 0:
|
|
||||||
print("No fanarts!")
|
print("No fanarts!")
|
||||||
exit(1)
|
exit(1)
|
||||||
last_updated = datetime.now()
|
self.last_updated = datetime.now()
|
||||||
|
|
||||||
def get_fanarts(month):
|
def __init__(self):
|
||||||
return [ handle_fanart(x) for x in db if x["date"] == month ]
|
self.db = []
|
||||||
|
self.update_database()
|
||||||
|
|
||||||
update_database()
|
def get_fanarts(self, month):
|
||||||
|
return [ handle_fanart(x) for x in self.db if x["date"] == month ]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def get_last_updated(self):
|
||||||
print(handle_fanart({ 'id': '1_DUo-dW40So3T24a91SyGrEcAGKfP0l_'}))
|
return self.last_updated.strftime("%d/%m/%Y %H:%M")
|
||||||
#clear_cache()
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ function getNewCardHtml(element) {
|
||||||
|
|
||||||
async function updateFanartList() {
|
async function updateFanartList() {
|
||||||
main_container_div.hidden = false;
|
main_container_div.hidden = false;
|
||||||
content_div.innerHTML = ""
|
//content_div.innerHTML = ""
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (fanart of fanarts) {
|
for (fanart of fanarts) {
|
||||||
|
@ -212,7 +212,6 @@ async function postData(url = "", data = {}, contentType = "application/x-www-fo
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArtworks() {
|
function getArtworks() {
|
||||||
document.getElementById("")
|
|
||||||
postData("/", { month: month_input.value }, "application/json").then((data) => {
|
postData("/", { month: month_input.value }, "application/json").then((data) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
fanarts = data;
|
fanarts = data;
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
</svg>
|
</svg>
|
||||||
ArtBound Panel 2.0
|
ArtBound Panel 2.0
|
||||||
</h1>
|
</h1>
|
||||||
<p class="lead" onclick="debugFn()">Perché semplice è meglio.</p>
|
<a href="/update" class="lead">{{ last_updated }}</a>
|
||||||
<div id="month_div">
|
<div id="month_div">
|
||||||
<label for="month_input" style="margin-right: 10px;">Scegli il mese: </label><input id="month_input"
|
<label for="month_input" style="margin-right: 10px;">Scegli il mese: </label><input id="month_input"
|
||||||
type="month" value="2022-08">
|
type="month" value="2022-08">
|
||||||
<a href="#" class="btn my-2 btn-go" onclick="handleAuthClick()" id="authorize_button" hidden>Vai</a>
|
<a href="#" class="btn my-2 btn-go" onclick="handleAuthClick()" id="authorize_button" hidden>Vai</a>
|
||||||
<a href="#" class="btn btn-secondary my-2" onclick="getArtworks()">getArtworks</a>
|
<a href="#" class="btn btn-secondary my-2" onclick="getArtworks()">Ottieni</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="controls" hidden>
|
<div id="controls" hidden>
|
||||||
<a href="#" class="btn btn-secondary my-2" onclick="selectAllNone(1)" id="selectall_button">✅</a>
|
<a href="#" class="btn btn-secondary my-2" onclick="selectAllNone(1)" id="selectall_button">✅</a>
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
import json
|
import json
|
||||||
from flask import request, redirect, render_template
|
from flask import request, redirect, render_template
|
||||||
from artbound_python import app
|
from artbound_python import app
|
||||||
from artbound_python.cache import get_fanarts
|
from artbound_python.cache import last_updated, DB
|
||||||
|
|
||||||
|
database = DB()
|
||||||
debug_fanarts = [{"id":"1dE8L7w2DuOfQSJwf5oRjAeJ-VZfy5o-6","date":["03","08","2022"],"name":"Saro","content":"/static/res/wm.png","enabled":1,"index":1,"div":{}},{"id":"1ZO2poqaylmh7_FkEjRthozVXFpcP1Edx","date":["18","08","2022"],"name":"suchetto","content":"https://drive.google.com/uc?id=1ZO2poqaylmh7_FkEjRthozVXFpcP1Edx","enabled":1,"index":2,"div":{}},{"id":"1jkpZzqnQUdXv7QiW1khuwnSsdnjudBt-","date":["18","08","2022"],"name":"suca","content":"https://drive.google.com/uc?id=1clZbi1QzJQo_c7PGWx-nmLgfPhXqHdZR","enabled":1,"index":3,"div":{}}]
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def route_index():
|
def route_index():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template("index.html")
|
return render_template("index.html", last_updated=database.get_last_updated())
|
||||||
|
|
||||||
if (request.headers.get('Content-Type') != 'application/json'):
|
if (request.headers.get('Content-Type') != 'application/json'):
|
||||||
return 'Content-Type not supported. Please use "application/json".'
|
return 'Content-Type not supported. Please use "application/json".'
|
||||||
|
|
||||||
month = request.json["month"]
|
month = request.json["month"]
|
||||||
fanarts = get_fanarts(month)
|
fanarts = database.get_fanarts(month)
|
||||||
return json.dumps(fanarts)
|
return json.dumps(fanarts)
|
||||||
|
|
||||||
|
@app.route('/update')
|
||||||
|
def route_update():
|
||||||
|
database.update_database()
|
||||||
|
return redirect("/")
|
Loading…
Reference in New Issue
Block a user