RSS updated (multi-langs). Logs updated

This commit is contained in:
Cyrille L 2023-04-04 10:54:09 +02:00
parent 6f67fd1d01
commit 99389285b0
10 changed files with 119 additions and 94 deletions

View File

@ -858,6 +858,6 @@ def create_database():
# Create Post DB # Create Post DB
#--------------- #---------------
database = '%s\n%s\n%s'%(database, opt_tags, db_stats) database = '%s\n%s\n%s'%(database, opt_tags, db_stats)
tyto.set_file(db.config, 'new', database) tyto.set_file(db.config, 'New', database)
logs.out("21", db.uri_file, False) logs.out("21", db.uri_file, False)

View File

@ -37,7 +37,6 @@
from datetime import datetime from datetime import datetime
import os, sys, re, locale, importlib import os, sys, re, locale, importlib
import logs, dom, tyto, html, show, langs import logs, dom, tyto, html, show, langs
# locale translation directory # locale translation directory
@ -184,7 +183,6 @@ def create_domain(target):
# Start registering variables in domain database # Start registering variables in domain database
#----------------------------------------------- #-----------------------------------------------
global navbars_conf
local_user = '%s/.local/tyto/%s/'%(dom.home_dir, shortname) local_user = '%s/.local/tyto/%s/'%(dom.home_dir, shortname)
modules_dir = '%s/articles/_configs/'%dom.folder modules_dir = '%s/articles/_configs/'%dom.folder
footer_about_f = '%sfooter_about.html'%modules_dir footer_about_f = '%sfooter_about.html'%modules_dir
@ -215,7 +213,6 @@ def create_domain(target):
'wip_url = "%s"\n'%wip_url 'wip_url = "%s"\n'%wip_url
tyto.set_file(dom.config, True, set_f) tyto.set_file(dom.config, True, set_f)
logs.out("32", dom.config, False)
# Get srv root # Get srv root
@ -254,7 +251,8 @@ def create_domain(target):
root_srv_dom = '%s/%s'%(srv, shortname) root_srv_dom = '%s/%s'%(srv, shortname)
srv_wip_tpl = "%s/wip/template/"%root_srv_dom srv_wip_tpl = "%s/wip/template/"%root_srv_dom
srv_www_tpl = "%s/www/template/"%root_srv_dom srv_www_tpl = "%s/www/template/"%root_srv_dom
set_f = '# Servers directories\n' + \ set_f = \
'# Servers directories\n' + \
'srv_root = "%s/"\n'%srv + \ 'srv_root = "%s/"\n'%srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \ 'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \ 'srv_wip = "%s/wip/"\n'%root_srv_dom + \
@ -758,8 +756,7 @@ def create_metas(option):
'<meta name="medium" content="website" />\n' + \ '<meta name="medium" content="website" />\n' + \
'<meta name="revisit-after" content="3 days" />' '<meta name="revisit-after" content="3 days" />'
tyto.set_file(dom.metas_f, 'new', metas_tags) tyto.set_file(dom.metas_f, 'New', metas_tags)
logs.out("32", dom.metas_f, False)
# Create an empty html file in wip/www server if not exists # Create an empty html file in wip/www server if not exists
if not tyto.exists(dom.wip_metas_f): if not tyto.exists(dom.wip_metas_f):
@ -820,8 +817,7 @@ def create_navbar(option):
navbar_lang = navbar_lang%(tyto.Tyto, dom.navbar_f) navbar_lang = navbar_lang%(tyto.Tyto, dom.navbar_f)
tyto.set_file(dom.navbar_f, 'new', navbar_lang) tyto.set_file(dom.navbar_f, 'New', navbar_lang)
logs.out("32", dom.navbar_f, False)
# Create wip navbar file # Create wip navbar file
html.create_navbar('wip') html.create_navbar('wip')
@ -836,7 +832,6 @@ def create_sidebar(option):
# Create an empty html file in wip/www server if not exists # Create an empty html file in wip/www server if not exists
if not tyto.exists(dom.wip_sidebar_f): if not tyto.exists(dom.wip_sidebar_f):
tyto.set_file(dom.wip_sidebar_f, 'new', '') tyto.set_file(dom.wip_sidebar_f, 'new', '')
logs.out("32", dom.wip_sidebar_f, False)
# Create new config file, or ask if exists with option = 'reset' # Create new config file, or ask if exists with option = 'reset'
if tyto.exists(dom.sidebar_f): if tyto.exists(dom.sidebar_f):
@ -887,8 +882,7 @@ def create_sidebar(option):
dom.sidebar_items dom.sidebar_items
) )
tyto.set_file(dom.sidebar_f, 'new', sidebar_lang) tyto.set_file(dom.sidebar_f, 'New', sidebar_lang)
logs.out("32", dom.sidebar_f, False)
#=============================# #=============================#
@ -1054,8 +1048,7 @@ def create_footer(option):
if option == "form": return if option == "form": return
logs.out("255", '', True) logs.out("255", '', True)
tyto.set_file(dom.footer_f, 'new', footer) tyto.set_file(dom.footer_f, 'New', footer)
logs.out("32", dom.footer_f, False)
# Create footer file in wip server if not exists # Create footer file in wip server if not exists
if not tyto.exists(dom.wip_footer_f): if not tyto.exists(dom.wip_footer_f):
@ -1083,4 +1076,4 @@ def create_footer_about(option):
'<p id="footer_about">%s</p>'%dom.about '<p id="footer_about">%s</p>'%dom.about
tyto.set_file(dom.footer_about_f, False, set_f) tyto.set_file(dom.footer_about_f, False, set_f)
logs.out("32", dom.footer_about_f, False)

View File

@ -270,8 +270,7 @@ def create_user_metas(option):
if user_metas: user_metas = "%s\n%s%s"%(user_metas, tab, line) if user_metas: user_metas = "%s\n%s%s"%(user_metas, tab, line)
else: user_metas = '%s%s'%(tab, line) else: user_metas = '%s%s'%(tab, line)
tyto.set_file(target, True, user_metas) tyto.set_file(target, 'New', user_metas)
logs.out("32", target, False)
#==============================================# #==============================================#
@ -366,7 +365,6 @@ def create_navbar(option):
if not navbar_items: if not navbar_items:
if not tyto.exists(target): if not tyto.exists(target):
tyto.set_file(target, 'New', '') tyto.set_file(target, 'New', '')
logs.out("32", target, False)
logs.out('28', '%s'%langs.log.navbar, False) logs.out('28', '%s'%langs.log.navbar, False)
return return
@ -382,7 +380,6 @@ def create_navbar(option):
), True) ), True)
tyto.set_file(target, 'New', menu_html) tyto.set_file(target, 'New', menu_html)
logs.out("32", target, False)
#==============================================# #==============================================#
@ -483,7 +480,6 @@ def create_sidebar(option):
if not sidebar_items: if not sidebar_items:
if not tyto.exists(target): if not tyto.exists(target):
tyto.set_file(target, 'New', '') tyto.set_file(target, 'New', '')
logs.out("32", target, False)
logs.out('28', '%s'%langs.log.sidebar, False) logs.out('28', '%s'%langs.log.sidebar, False)
return return
@ -504,7 +500,6 @@ def create_sidebar(option):
), True) ), True)
tyto.set_file(target, True, sidebar_content) tyto.set_file(target, True, sidebar_content)
logs.out("32", target, False)
#===================================================# #===================================================#
@ -533,5 +528,4 @@ def create_user_footer(option):
else: footer = '%s%s'%(tab, line) else: footer = '%s%s'%(tab, line)
tyto.set_file(target, 'New', footer) tyto.set_file(target, 'New', footer)
logs.out("32", target, False)

View File

@ -90,6 +90,8 @@ def out(nbr, value, out):
'42' : '%s%s%s > "%s"'%(CG, langs.log.dom_act, CS, value), '42' : '%s%s%s > "%s"'%(CG, langs.log.dom_act, CS, value),
'43' : '%s%s%s'%(CY, langs.log.dom_no, CS), '43' : '%s%s%s'%(CY, langs.log.dom_no, CS),
'44' : '%s%s%s "tyto check %s"'%(CY, langs.log.check_m, CS, value), '44' : '%s%s%s "tyto check %s"'%(CY, langs.log.check_m, CS, value),
'45' : '%s%s %s%s > %s'%(CY, langs.log.meta_t, langs.log.no_up, CS, value),
'46' : '%s%s %s%s > %s'%(CY, langs.log.time_t, langs.log.no_up, CS, value),
'51' : '%s%s%s > %s'%(CY, langs.log.data_inc, CS, value), '51' : '%s%s%s > %s'%(CY, langs.log.data_inc, CS, value),
'60' : '\n%s'%langs.log.status_r, '60' : '\n%s'%langs.log.status_r,
'255' : '%s'%langs.log.laterout '255' : '%s'%langs.log.laterout

View File

@ -74,7 +74,7 @@ def manage_publish(target):
publish_article() publish_article()
# Create new ATOM/RSS file # Create new ATOM/RSS file
#rss.create_feed() rss.create_feed()
#===============# #===============#
@ -100,10 +100,8 @@ def publish_article():
#-------------------------------------------------# #-------------------------------------------------#
def replace_lines_pub(): def replace_lines_pub():
html.create_html_time_meta('publish') html.create_html_time_meta('publish')
print(html.time_html_pub)
in_pub = False in_pub = False
time_wip_pub = ''
wip_html_post = open(db.post_wip, 'r').read() wip_html_post = open(db.post_wip, 'r').read()
www_html_post = wip_html_post www_html_post = wip_html_post
@ -116,8 +114,6 @@ def replace_lines_pub():
elif line.startswith('<!--/Tyto_Published-->'): elif line.startswith('<!--/Tyto_Published-->'):
time_wip_pub = '%s\n%s'%(time_wip_pub, line) time_wip_pub = '%s\n%s'%(time_wip_pub, line)
in_pub = False in_pub = False
print('> time_wip_pub')
print(time_wip_pub)
break break
elif line.startswith('<!--Tyto_Meta-->'): elif line.startswith('<!--Tyto_Meta-->'):
@ -127,15 +123,27 @@ def replace_lines_pub():
if in_pub: if in_pub:
time_wip_pub = '%s\n%s'%(time_wip_pub, line) time_wip_pub = '%s\n%s'%(time_wip_pub, line)
www_html_post = www_html_post.replace(time_wip_pub, # Update file with new time meta
try:
www_html_post = \
www_html_post.replace(time_wip_meta,
html.meta_pub
)
except:
logs.out("45", db.post_www, False)
# update file with new article time
try:
www_html_post = \
www_html_post.replace(time_wip_pub,
html.time_html_pub html.time_html_pub
) )
except:
logs.out("46", db.post_www, False)
www_html_post = www_html_post.replace(time_wip_meta, html.meta_pub)
#print(www_html_post) #print(www_html_post)
tyto.set_file(db.post_www, 'new', www_html_post) tyto.set_file(db.post_www, 'New', www_html_post)
logs.out("32", db.post_www, False)
#================================# #================================#

View File

@ -1,11 +1,27 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Name: Tyto - Littérateur # Tyto - Littérateur
# Type: ATOM/RSS template #
# Description: Create raw RSS template # Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
# file: rss.py #
# Folder: /var/lib/tyto/program/ # This program is free software: you can redistribute it and/or modify
# By echolib (XMPP: im@echolib.re) # it under the terms of the GNU Affero General Public License
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 # as published by the Free Software Foundation, either version 3 of the
# License, or of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re)
#
# Description: Create feed RSS/Atom
# File: /var/lib/tyto/program/rss.py
#----------------------------------------------------------------------
#------------ #------------
# funny stats # funny stats
@ -33,42 +49,48 @@ def create_feed():
'<rss version="2.0">\n' + \ '<rss version="2.0">\n' + \
' <channel>\n' + \ ' <channel>\n' + \
' <title>%s - %s - Flux RSS 2.0</title>\n'%( ' <title>%s - %s - Flux RSS 2.0</title>\n'%(
db.domain_title, db.domain_www_url dom.title, dom.www_url
) + \ ) + \
' <link>%s</link>\n'%db.domain_www_url + \ ' <link>%s</link>\n'%dom.www_url + \
' <description>%s %s (%s)</description>\n'%( ' <description>RSS 2.0 - %s (%s)</description>\n'%(
tyto.trans[19][tyto.n], db.domain_title, db.domain_about dom.title, dom.about
) + \ ) + \
' <image>\n' + \ ' <image>\n' + \
' <url>%s/%s</url>\n'%(db.domain_www_url, db.domain_logo) + \ ' <url>%s/%s</url>\n'%(dom.www_url, dom.logo) + \
' <title>logo %s</title>\n'%db.domain_title + \ ' <title>logo %s</title>\n'%dom.title + \
' <link>%s</link>\n'%db.domain_www_url + \ ' <link>%s</link>\n'%dom.www_url + \
' </image>\n' + \ ' </image>\n' + \
' <language>%s</language>\n'%db.domain_lang + \ ' <language>%s</language>\n'%dom.lang_site + \
' <category>%s</category>\n'%db.domain_tags + \ ' <category>%s</category>\n'%dom.tags + \
' <lastBuildDate>%s</lastBuildDate>\n'%tyto.nowdate() + \ ' <lastBuildDate>%s</lastBuildDate>\n'%tyto.nowdate() + \
' <copyright>%s</copyright>\n'%db.domain_license + \ ' <copyright>%s</copyright>\n'%dom.license + \
' <webMaster>%s</webMaster>\n'%db.domain_mail + \ ' <webMaster>%s</webMaster>\n'%dom.mail + \
' <generator>%s</generator>'%tyto.Tyto ' <generator>%s</generator>'%tyto.Tyto
# Sort by newer articles (created by last check) # Sort by newer articles (created by last check)
db_articles = sorted(Path(db.articles_db).iterdir(), db_articles = sorted(Path(dom.articles_db_d).iterdir(),
key=os.path.getmtime, key=os.path.getmtime,
reverse=True reverse=True
) )
rss_item = False rss_item = False
nbr_item = 0 nbr_item = 0
# Loop published articles. Get databases of articles # Loop published articles. Get databases of articles
for post_db in db_articles: for post_db in db_articles:
if not str(post_db).endswith('.conf'): continue if not str(post_db).endswith('.config'):
continue
# Load DB # Load DB
exec(open(post_db).read(),globals()) exec(open(post_db).read(),globals())
if not hash_www or hash_chk != hash_www: continue if not hash_www or hash_chk != hash_www:
continue
rss_item = True rss_item = True
nbr_item += 1 nbr_item += 1
if nbr_item > dom.rss_items: break
if nbr_item > dom.rss_items:
break
set_f = \ set_f = \
'%s\n'%set_f + \ '%s\n'%set_f + \
@ -81,7 +103,7 @@ def create_feed():
' <author>%s</author>\n'%author + \ ' <author>%s</author>\n'%author + \
' <image>\n' + \ ' <image>\n' + \
' <url>%s</url>\n'%snpic + \ ' <url>%s</url>\n'%snpic + \
' <title>%s %s</title>\n'%(tyto.trans[20][tyto.n], title) + \ ' <title>%s</title>\n'%(title) + \
' <link>%s</link>\n'%http_www + \ ' <link>%s</link>\n'%http_www + \
' </image>\n' + \ ' </image>\n' + \
' <category>%s</category>\n'%tags + \ ' <category>%s</category>\n'%tags + \
@ -98,6 +120,5 @@ def create_feed():
' </channel>\n' + \ ' </channel>\n' + \
'</rss>' '</rss>'
tyto.set_file(db.www_rss, 'New', set_f) tyto.set_file(dom.www_rss_f, 'New', set_f)
logs.out("33", db.www_rss, False)

View File

@ -241,11 +241,12 @@ def edit_file(edit_file):
logs.out("1", "/usr/bin/nano", True) logs.out("1", "/usr/bin/nano", True)
#=================# #=====================#
# Create a file # # Create a file #
# Or append text # # Or append text #
# new: True/false # # new: True = create #
#-----------------# # False = Append #
#---------------------#
def set_file(path, new, text): def set_file(path, new, text):
if new: opt = "w" if new: opt = "w"
else: opt = "a" else: opt = "a"
@ -254,6 +255,8 @@ def set_file(path, new, text):
file = open(path, opt) file = open(path, opt)
file.write(text + '\n') file.write(text + '\n')
file.close() file.close()
if opt == 'w':
logs.out("32", path, False)
except: except:
logs.out("4", path, True) logs.out("4", path, True)

View File

@ -178,7 +178,6 @@ def wip_article(target):
os.makedirs('%s%s'%(dom.srv_wip, db.direc_src), exist_ok=True) os.makedirs('%s%s'%(dom.srv_wip, db.direc_src), exist_ok=True)
logs.out("33", '%s%s'%(dom.srv_wip, db.direc_src), False) logs.out("33", '%s%s'%(dom.srv_wip, db.direc_src), False)
tyto.set_file(db.post_wip, 'New', html.main_page) tyto.set_file(db.post_wip, 'New', html.main_page)
logs.out("32", db.post_wip, False)
# Copy needed files (Also create sub-folders) # Copy needed files (Also create sub-folders)
tyto.files_to_srv('wip') tyto.files_to_srv('wip')

View File

@ -13,10 +13,13 @@
# Generic # Generic
sidebar = 'Sidebar' sidebar = 'Sidebar'
navbar = 'Navbar' navbar = 'Navbar'
meta_t = '<meta> tag'
time_t = '<time> tag'
metas = 'Metas Tags' metas = 'Metas Tags'
footer = 'Footer' footer = 'Footer'
line = "Ligne" line = "Ligne"
no_up = "not updated"
ntd = "Nothing to do" ntd = "Nothing to do"
unused_r = "Unused ressource" unused_r = "Unused ressource"
unused_c = "Unused database value" unused_c = "Unused database value"

View File

@ -13,11 +13,13 @@
# Generique # Generique
sidebar = 'Barre Latérale' sidebar = 'Barre Latérale'
navbar = 'Barre de navigation' navbar = 'Barre de navigation'
meta_t = 'Balise <meta>'
time_t = 'Balise <time>'
metas = 'Balises Metas' metas = 'Balises Metas'
footer = "Pied de Page" footer = "Pied de Page"
line = "Line" line = "Line"
no_up = "non mise à jour"
ntd = "Rien à faire" ntd = "Rien à faire"
unused_r = "Ressource manquante" unused_r = "Ressource manquante"
unused_c = "Valeur de la base de donnée manquante" unused_c = "Valeur de la base de donnée manquante"