Skip to content

Commit

Permalink
Merge pull request #18 from 16bravo/feature/ajout_json_page_html_stat…
Browse files Browse the repository at this point in the history
…ique

Feature/ajout json page html statique
  • Loading branch information
16bravo authored Dec 20, 2023
2 parents c9c9fff + 86ff125 commit dc17740
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/gen_json.yml
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.
39 changes: 39 additions & 0 deletions scripts/json_generation.py
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.

0 comments on commit dc17740

Please sign in to comment.