|
| 1 | +import os |
| 2 | +import time |
| 3 | +import sqlite3 |
| 4 | +import requests |
| 5 | +from datetime import datetime |
| 6 | + |
| 7 | +REPOS = [ |
| 8 | + "huggingface/transformers", |
| 9 | + "openai/openai-python", |
| 10 | + "pytorch/pytorch", |
| 11 | + "tensorflow/tensorflow", |
| 12 | + "langchain/langchain", |
| 13 | + "microsoft/ML-For-Beginners", |
| 14 | + "microsoft/AI-For-Beginners", |
| 15 | + "karpathy/nn-zero-to-hero", |
| 16 | + "Significant-Gravitas/AutoGPT", |
| 17 | + "stabilityai/stablediffusion", |
| 18 | +] |
| 19 | +INTERVAL = 300 |
| 20 | +DB_FILE = os.path.join(os.path.dirname(__file__), "github_releases.db") |
| 21 | +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") |
| 22 | + |
| 23 | +conn = sqlite3.connect(DB_FILE) |
| 24 | +cur = conn.cursor() |
| 25 | +cur.execute(""" |
| 26 | +CREATE TABLE IF NOT EXISTS releases ( |
| 27 | + id TEXT PRIMARY KEY, |
| 28 | + repo TEXT, |
| 29 | + tag TEXT, |
| 30 | + name TEXT, |
| 31 | + published TIMESTAMP, |
| 32 | + body TEXT, |
| 33 | + html_url TEXT |
| 34 | +) |
| 35 | +""") |
| 36 | +conn.commit() |
| 37 | + |
| 38 | +headers = {"Accept": "application/vnd.github+json"} |
| 39 | +if GITHUB_TOKEN: |
| 40 | + headers["Authorization"] = f"Bearer {GITHUB_TOKEN}" |
| 41 | + |
| 42 | +def fetch_releases(repo): |
| 43 | + url = f"https://api.github.com/repos/{repo}/releases" |
| 44 | + r = requests.get(url, headers=headers) |
| 45 | + r.raise_for_status() |
| 46 | + return r.json() |
| 47 | + |
| 48 | +def save_release(repo, release): |
| 49 | + cur.execute(""" |
| 50 | + INSERT OR IGNORE INTO releases (id, repo, tag, name, published, body, html_url) |
| 51 | + VALUES (?, ?, ?, ?, ?, ?, ?) |
| 52 | + """, ( |
| 53 | + release["id"], |
| 54 | + repo, |
| 55 | + release.get("tag_name", ""), |
| 56 | + release.get("name", ""), |
| 57 | + release.get("published_at", datetime.utcnow().isoformat()), |
| 58 | + release.get("body", ""), |
| 59 | + release.get("html_url", "") |
| 60 | + )) |
| 61 | + conn.commit() |
| 62 | + |
| 63 | +def load_seen_ids(): |
| 64 | + cur.execute("SELECT id FROM releases") |
| 65 | + return set(row[0] for row in cur.fetchall()) |
| 66 | + |
| 67 | +def main(): |
| 68 | + print("Initialisation GitHub Releases...") |
| 69 | + seen_ids = load_seen_ids() |
| 70 | + print(f"{len(seen_ids)} releases déjà enregistrées.") |
| 71 | + try: |
| 72 | + while True: |
| 73 | + for repo in REPOS: |
| 74 | + try: |
| 75 | + releases = fetch_releases(repo) |
| 76 | + for rel in releases: |
| 77 | + rel_id = str(rel["id"]) |
| 78 | + if rel_id not in seen_ids: |
| 79 | + print(f"[NOUVELLE RELEASE] {repo} → {rel.get('name','(no name)')}") |
| 80 | + print(" ->", rel.get("html_url", "")) |
| 81 | + save_release(repo, rel) |
| 82 | + seen_ids.add(rel_id) |
| 83 | + except Exception as e: |
| 84 | + print(f"[ERREUR] {repo}: {e}") |
| 85 | + |
| 86 | + print(f"Attente {INTERVAL}s avant prochaine vérification...") |
| 87 | + time.sleep(INTERVAL) |
| 88 | + except KeyboardInterrupt: |
| 89 | + print("Arrêt manuel.") |
| 90 | + finally: |
| 91 | + conn.close() |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + main() |
0 commit comments