From 9077cd81e058c3781fd0cd4113b980e994bc12ac Mon Sep 17 00:00:00 2001 From: sbiego Date: Thu, 6 Jun 2019 03:17:30 +0200 Subject: [PATCH] qr api, not working --- TODO | 10 ++---- index.html | 5 +-- pomelo.py | 23 +++++++++++--- submit.php | 54 +++++++++++++++------------------ templates/tournament_index.html | 2 +- 5 files changed, 51 insertions(+), 43 deletions(-) diff --git a/TODO b/TODO index 2f38701..bbc8444 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,8 @@ - -//TODO: - non aggiorna e aggiunge il nuovo torneo all'index +//TODO: + rivedere funzione crea torneo che faccia tutto nella cartella, e che il dizionario abbia tutti i campi //TODO: - per i futuro aggiungere variabile url per il torneo e + variabili _GET per alert sull'azione o errore del submit //TODO: git sui json ad ogni submit di dati così da avere una timeline (commit con ora data e tipo di azione) @@ -11,8 +10,5 @@ //TODO: ampliare ad ogni tipo di torneo (anche punteggi) -## TODO - nel GET url usare per mostrare rank se agg/elim giocatre, partite se agg partita e messaggio alert - //TODO: POMELO, alla creazione di un torneo forzare la creazione di una password, poi viene salvata in un auth.php? (pure questa con accesso) e importata da submit.php. o cattiva idea? \ No newline at end of file diff --git a/index.html b/index.html index 9d24925..abfb2db 100644 --- a/index.html +++ b/index.html @@ -97,10 +97,11 @@ diff --git a/pomelo.py b/pomelo.py index 93ceed2..a37c0ea 100755 --- a/pomelo.py +++ b/pomelo.py @@ -3,7 +3,7 @@ import math import sys import json -import os.path +import os import time # cartella dei tornei @@ -31,21 +31,36 @@ def nuovoTorneo(nome): # percorso del file e cartella che conterra' il dizionario dir_path = tornei_dir + '/' + nome file_path = dir_path + '/' + nome + '.json' + imgs_path = dir_path + '/img' + qr_path = imgs_path + '/qr.png' + logo_path = imgs_path + '/logo.png' # dizionario torneo base vuoto # vecchio: torneo = {'NOME': nome, 'FILE': file_path, - torneo = {'NOME': nome, 'FOLDER': dir_path, 'JSON_DATA': 'file_path', + torneo = {'NOME': nome, 'FOLDER': dir_path, 'JSON_DATA': file_path, 'GIOCATORI': {}, 'MATCHES': [], 'RANKING': []} # controlla se esiste la cartella col nome del torneo if not os.path.exists(dir_path): os.makedirs(dir_path) + os.makedirs(imgs_path) # controlla se esiste il file json del torneo se no lo crea e ci mette il contenuto dell'attuale dizionario if not os.path.exists(file_path): + # data with open(file_path, 'w') as fp: json.dump(torneo, fp) + # qr + with open(qr_path, 'w') as fp: + command = "wget -O r/" + nome + "/img/qr.png https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=" + "http://flowin.space/pomelo/r/" + nome + print("\n\nCOMMAND\n", command, '\n\n') + # os.system(command) + + # logo + # with open(file_path, 'w') as fp: + # json.dump(torneo, fp) + costruisciIndexHtml(nome) costruisciIndexHtml('index') @@ -379,11 +394,11 @@ def listTornei(out='none'): elif(out == 'html'): select = '' - for torneo in dirs: + for torneo in sorted(dirs): select += "\n" return select else: - return os.listdir(tornei_dir) + return dirs ###################################################################################################################################################### #COMANDO: A COSA SERVE: diff --git a/submit.php b/submit.php index 001fbb0..30c5c1e 100644 --- a/submit.php +++ b/submit.php @@ -1,33 +1,23 @@ - - - -alert('$msg');"; - // } - - // $valid_passwords = array ("uova" => "frittata"); - // $valid_users = array_keys($valid_passwords); - - // $user = $_SERVER['PHP_AUTH_USER']; - // $pass = $_SERVER['PHP_AUTH_PW']; - - // $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]); + -1) { @@ -51,14 +41,19 @@ $torneo = $_POST["torneo"]; // check ALPHANUMERIC - // if (ctype_alnum($torneo) and $torneo != "") { + if (ctype_alnum($torneo) and $torneo != "") { $command = "./pomelo.py \"".$_POST["torneo"]."\" -n 2>&1"; + + // creates and downloads the qr-code from ext api + $apiQR = 'https://api.qrserver.com/v1/create-qr-code/?size=100x100&data='; + // $url'http://flowin.space/pomelo/r/prova' + // echo shell_exec("wget -O img/QR.gif ".$apiQR.$url." 2>&1"); // updates the main index // echo shell_exec("./pomelo.py \"".$torneo."\" --gen-index 2>&1"); // updates the tournament index // echo shell_exec("./pomelo.py \"".$torneo."\" --gen-index 2>&1"); $alert_msg = "Creato un nuovo torneo: ".$_POST["torneo"]; - // } + } } } @@ -82,10 +77,10 @@ $giocatore = $_POST["nuovoGiocatore"]; // check ALPHANUMERIC - // if (ctype_alnum($giocatore) and $giocatore != "") { + if (ctype_alnum($giocatore) and $giocatore != "") { $command = "./pomelo.py \"$torneo\" -a \"$giocatore\" 2>&1"; $alert_msg = "$giocatore. ora fa parte del torneo \"$torneo\""; - // } + } } else { $command = ''; @@ -109,12 +104,13 @@ // alert($alert_msg); } - echo 'POST
'; + // debug + echo '
POST
'; foreach ($_POST as $key => $value) { echo '

'.$key.": ".$value.'

'; } - echo 'GET
'; + echo '
GET
'; foreach ($_GET as $key => $value) { echo '

'.$key.": ".$value.'

'; } diff --git a/templates/tournament_index.html b/templates/tournament_index.html index 6591593..0cf19fd 100644 --- a/templates/tournament_index.html +++ b/templates/tournament_index.html @@ -134,7 +134,7 @@
- qr url
+ qr url
Usa il codice QR per condividere la pagina!

-- 2.18.1