-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from 16bravo/feature/ajout_json_page_html_stat…
…ique Feature/ajout json page html statique
- Loading branch information
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}.") |
File renamed without changes.
File renamed without changes.