Support all EBRA websites

Better formatting
This commit is contained in:
Cyril NOVEL 2026-07-28 15:47:32 +02:00
commit 8f76a16e5a

View file

@ -1,18 +1,30 @@
import json
import locale import locale
import paramiko
import os import os
from datetime import datetime from datetime import datetime
from gen_feed import generate_feed
import paramiko
from dotenv import load_dotenv from dotenv import load_dotenv
from gen_feed import generate_feed
def get_publisher(link): def get_publisher(link):
if "ledauphine.com" in link: publishers = {
return "Le Dauphiné Libéré" "ledauphine.com": "Le Dauphiné Libéré",
if "bienpublic.com" in link: "bienpublic.com": "Le Bien Public",
return "Le Bien Public" "leprogres.fr": "Le Progrès",
if "leprogres.fr" in link: "lalsace.fr": "L'Alsace",
return "Le Progrès" "dna.fr": "Dernières Nouvelles d'Alsace",
"estrepublicain.fr": "L'Est Républicain",
"lejsl.com": "Journal de Saône-et-Loire",
"republicain-lorrain.fr": "Le Républicain Lorrain",
"vosgesmatin.fr": "Vosges Matin",
}
for k,v in publishers.items():
if k in link:
return v
return "" return ""
@ -44,7 +56,7 @@ def generate_web():
towns = [] towns = []
print("Getting articles for each link...") print("Getting articles for each link...")
for link in urls: for link in urls:
town_id = link.rsplit('/', 1)[-1] town_id = link.rsplit("/", 1)[-1]
town_xml = town_id + ".xml" town_xml = town_id + ".xml"
town_rss = website + "/" + town_xml town_rss = website + "/" + town_xml
if not generate_feed(link, town_rss, town_xml): if not generate_feed(link, town_rss, town_xml):
@ -53,7 +65,7 @@ def generate_web():
towns.append((town_id, town_rss, get_publisher(link), town_xml)) towns.append((town_id, town_rss, get_publisher(link), town_xml))
print("Updating HTML template...") print("Updating HTML template...")
with open("template.html", 'r', encoding="utf-8") as template: with open("template.html", "r", encoding="utf-8") as template:
data = template.read() data = template.read()
li = "" li = ""
@ -61,10 +73,12 @@ def generate_web():
li += f'<li><a href="{town[1]}">{town[0]}</a> ({town[2]})</li>' li += f'<li><a href="{town[1]}">{town[0]}</a> ({town[2]})</li>'
data = data.replace("$$$TOWN_LIST$$$", li) data = data.replace("$$$TOWN_LIST$$$", li)
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
now = datetime.now() now = datetime.now()
data = data.replace("$$$GENERATED_DATETIME$$$", now.strftime("%H:%M le %A %d %B %Y")) data = data.replace(
with open("index.html", 'w', encoding="utf-8") as out: "$$$GENERATED_DATETIME$$$", now.strftime("%H:%M le %A %d %B %Y")
)
with open("index.html", "w", encoding="utf-8") as out:
out.write(data) out.write(data)
print("Uploading to FTP...") print("Uploading to FTP...")
@ -74,6 +88,6 @@ def generate_web():
return True return True
if __name__ == '__main__': if __name__ == "__main__":
load_dotenv() load_dotenv()
generate_web() generate_web()