Update main.py

This commit is contained in:
Eduard Prigoana 2025-07-18 18:42:59 +03:00 committed by GitHub
parent 8d23ca1a79
commit 8e8c59919b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

20
main.py
View file

@ -6,16 +6,17 @@ import zipfile
import csv
import re
from bs4 import BeautifulSoup
from flask import Flask, send_file, render_template
from flask_cors import CORS # ✅ NEW IMPORT
from flask import send_from_directory
from flask import Flask, send_file, render_template, send_from_directory
from flask_cors import CORS
app = Flask(__name__, template_folder="templates")
CORS(app) # ✅ ENABLE CORS FOR ALL ROUTES
# Constants
ZIP_URL = "https://docs.google.com/spreadsheets/d/1DpuNNPfr5NwAnr1enVHjHjs_zhWiKwXd6KCpGXGjqxw/export?format=zip"
XLSX_URL = "https://docs.google.com/spreadsheets/d/1DpuNNPfr5NwAnr1enVHjHjs_zhWiKwXd6KCpGXGjqxw/export?format=xlsx"
ZIP_FILE = "Trackerhub.zip"
XLSX_FILE = "artists.xlsx"
EXTRACT_FOLDER = "sheet"
HTML_FILE = os.path.join(EXTRACT_FOLDER, "Artists.html")
CSV_FILE = "artists.csv"
@ -58,6 +59,11 @@ def fetch_and_process():
with zipfile.ZipFile(ZIP_FILE, 'r') as zip_ref:
zip_ref.extractall(EXTRACT_FOLDER)
print("[*] Downloading XLSX...")
r = requests.get(XLSX_URL)
with open(XLSX_FILE, "wb") as f:
f.write(r.content)
print("[*] Parsing HTML...")
with open(HTML_FILE, "r", encoding="utf-8") as f:
soup = BeautifulSoup(f, "html.parser")
@ -107,7 +113,7 @@ def fetch_and_process():
writer.writerow(["artist name", "URL", "credits", "updated", "links work"])
writer.writerows(data)
print("[✓] Done! CSV updated.")
print("[✓] Done! CSV and XLSX updated.")
except Exception as e:
print(f"[!] Error: {e}")
@ -134,6 +140,12 @@ def serve_csv():
return send_file(CSV_FILE, mimetype="text/csv", as_attachment=False)
return "CSV not ready yet.", 503
@app.route("/artists.xlsx")
def serve_xlsx():
if os.path.exists(XLSX_FILE):
return send_file(XLSX_FILE, mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", as_attachment=False)
return "XLSX not ready yet.", 503
@app.route("/artists.html")
def serve_artists_html():
if os.path.exists(HTML_FILE):