From 798e9c718f3cdd230cff8b7186f65473147960cc Mon Sep 17 00:00:00 2001 From: 16bravo Date: Wed, 20 Dec 2023 15:45:27 +0100 Subject: [PATCH 1/2] script generation json --- docs/index.html => index.html | 0 scripts/json_generation.py | 39 +++++++++++++++++++++++++++++++++++ {docs => web}/scripts/main.js | 0 {docs => web}/styles/main.css | 0 4 files changed, 39 insertions(+) rename docs/index.html => index.html (100%) create mode 100644 scripts/json_generation.py rename {docs => web}/scripts/main.js (100%) rename {docs => web}/styles/main.css (100%) diff --git a/docs/index.html b/index.html similarity index 100% rename from docs/index.html rename to index.html diff --git a/scripts/json_generation.py b/scripts/json_generation.py new file mode 100644 index 00000000..23567667 --- /dev/null +++ b/scripts/json_generation.py @@ -0,0 +1,39 @@ +import sqlite3 +import json + +# Connexion à la base de données SQLite +database_path = "./data/BravoRanking.db" +connection = sqlite3.connect(database_path) +cursor = connection.cursor() + +# Exécution de la requête SQL pour sélectionner toutes les lignes de la table +cursor.execute('''WITH year_max AS ( + SELECT MAX(YEAR) FROM Rankings + ), + month_max AS ( + SELECT MAX(MONTH) FROM Rankings WHERE YEAR = (SELECT * FROM year_max) + ) + SELECT r.ranking, t.tricode || '.png' AS flag, r.team, r.points, t.confederation + FROM Rankings r + LEFT JOIN Teams t ON (r.team = t.team) + WHERE year = (SELECT * FROM year_max) AND month = (SELECT * FROM month_max)''' +) + +# Récupération de toutes les lignes sous forme de liste de tuples +rows = cursor.fetchall() + +# Obtention des noms des colonnes +column_names = [description[0] for description in cursor.description] + +# Création d'une liste de dictionnaires pour chaque ligne +data = [dict(zip(column_names, row)) for row in rows] + +# Fermeture de la connexion à la base de données +connection.close() + +# Exportation des données vers un fichier JSON +json_path = "./data/LastMonthRanking.json" +with open(json_path, "w", encoding="utf-8") as json_file: + json.dump(data, json_file, indent=2) + +print(f"Données extraites avec succès et exportées vers {json_path}.") \ No newline at end of file diff --git a/docs/scripts/main.js b/web/scripts/main.js similarity index 100% rename from docs/scripts/main.js rename to web/scripts/main.js diff --git a/docs/styles/main.css b/web/styles/main.css similarity index 100% rename from docs/styles/main.css rename to web/styles/main.css From 86ff12583c4ff2c3e915311e810d8da0c7f2caeb Mon Sep 17 00:00:00 2001 From: 16bravo Date: Wed, 20 Dec 2023 15:48:16 +0100 Subject: [PATCH 2/2] ajout yaml --- .github/workflows/gen_json.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/gen_json.yml diff --git a/.github/workflows/gen_json.yml b/.github/workflows/gen_json.yml new file mode 100644 index 00000000..c3a819f1 --- /dev/null +++ b/.github/workflows/gen_json.yml @@ -0,0 +1,24 @@ +name: JSON Generation +on: + push: + branches: + - main + +jobs: + init_db: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run JSON generation script + run: python scripts/json_generation.py \ No newline at end of file