Support all EBRA websites
Better formatting
This commit is contained in:
parent
e56f58a0e9
commit
8f76a16e5a
1 changed files with 33 additions and 19 deletions
|
|
@ -1,18 +1,30 @@
|
|||
import json
|
||||
import locale
|
||||
import paramiko
|
||||
import os
|
||||
from datetime import datetime
|
||||
from gen_feed import generate_feed
|
||||
|
||||
import paramiko
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from gen_feed import generate_feed
|
||||
|
||||
|
||||
def get_publisher(link):
|
||||
if "ledauphine.com" in link:
|
||||
return "Le Dauphiné Libéré"
|
||||
if "bienpublic.com" in link:
|
||||
return "Le Bien Public"
|
||||
if "leprogres.fr" in link:
|
||||
return "Le Progrès"
|
||||
publishers = {
|
||||
"ledauphine.com": "Le Dauphiné Libéré",
|
||||
"bienpublic.com": "Le Bien Public",
|
||||
"leprogres.fr": "Le Progrès",
|
||||
"lalsace.fr": "L'Alsace",
|
||||
"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 ""
|
||||
|
||||
|
||||
|
|
@ -44,29 +56,31 @@ def generate_web():
|
|||
towns = []
|
||||
print("Getting articles for each link...")
|
||||
for link in urls:
|
||||
town_id = link.rsplit('/', 1)[-1]
|
||||
town_id = link.rsplit("/", 1)[-1]
|
||||
town_xml = town_id + ".xml"
|
||||
town_rss = website + "/" + town_xml
|
||||
if not generate_feed(link, town_rss, town_xml):
|
||||
print(f"Failed to generate feed for {town_id}")
|
||||
return False
|
||||
towns.append((town_id, town_rss, get_publisher(link), town_xml))
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
li = ""
|
||||
for town in towns:
|
||||
li += f'<li><a href="{town[1]}">{town[0]}</a> ({town[2]})</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()
|
||||
data = data.replace("$$$GENERATED_DATETIME$$$", now.strftime("%H:%M le %A %d %B %Y"))
|
||||
with open("index.html", 'w', encoding="utf-8") as out:
|
||||
data = data.replace(
|
||||
"$$$GENERATED_DATETIME$$$", now.strftime("%H:%M le %A %d %B %Y")
|
||||
)
|
||||
with open("index.html", "w", encoding="utf-8") as out:
|
||||
out.write(data)
|
||||
|
||||
|
||||
print("Uploading to FTP...")
|
||||
upload_to_sftp(towns)
|
||||
|
||||
|
|
@ -74,6 +88,6 @@ def generate_web():
|
|||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
load_dotenv()
|
||||
generate_web()
|
||||
generate_web()
|
||||
|
|
|
|||
Loading…
Reference in a new issue