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
#---------------
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)

View File

@ -37,7 +37,6 @@
from datetime import datetime
import os, sys, re, locale, importlib
import logs, dom, tyto, html, show, langs
# locale translation directory
@ -184,7 +183,6 @@ def create_domain(target):
# Start registering variables in domain database
#-----------------------------------------------
global navbars_conf
local_user = '%s/.local/tyto/%s/'%(dom.home_dir, shortname)
modules_dir = '%s/articles/_configs/'%dom.folder
footer_about_f = '%sfooter_about.html'%modules_dir
@ -215,7 +213,6 @@ def create_domain(target):
'wip_url = "%s"\n'%wip_url
tyto.set_file(dom.config, True, set_f)
logs.out("32", dom.config, False)
# Get srv root
@ -254,33 +251,34 @@ def create_domain(target):
root_srv_dom = '%s/%s'%(srv, shortname)
srv_wip_tpl = "%s/wip/template/"%root_srv_dom
srv_www_tpl = "%s/www/template/"%root_srv_dom
set_f = '# Servers directories\n' + \
'srv_root = "%s/"\n'%srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \
'srv_wip_tpl_d = "%s"\n'%srv_wip_tpl + \
'srv_wip_images_d = "%s/wip/images/"\n'%root_srv_dom + \
'srv_wip_files_d = "%s/wip/files/"\n'%root_srv_dom + \
'srv_www = "%s/www/"\n'%root_srv_dom + \
'srv_www_tpl_d = "%s"\n'%srv_www_tpl + \
'srv_www_images_d = "%s/www/images/"\n'%root_srv_dom + \
'srv_www_files_d = "%s/www/files/"\n'%root_srv_dom + \
'\n' + \
'# Servers files (wip)\n' + \
'wip_logo_f = "%s%s"\n'%(srv_wip_tpl, logo) + \
'wip_css_f = "%sstyles.css"\n'%srv_wip_tpl + \
'wip_navbar_f = "%snavbar.html"\n'%srv_wip_tpl + \
'wip_sidebar_f = "%ssidebar.html"\n'%srv_wip_tpl + \
'wip_metas_f = "%smetas.html"\n'%srv_wip_tpl + \
'wip_footer_f = "%sfooter.html"\n'%srv_wip_tpl + \
'\n' + \
'# Servers files (www)\n' + \
'www_logo_f = "%s%s"\n'%(srv_www_tpl, logo) + \
'www_css_f = "%sstyles.css"\n'%srv_www_tpl + \
'www_navbar_f = "%snavbar.html"\n'%srv_www_tpl + \
'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \
'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \
'www_footer_f = "%sfooter.html"'%srv_www_tpl
set_f = \
'# Servers directories\n' + \
'srv_root = "%s/"\n'%srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \
'srv_wip_tpl_d = "%s"\n'%srv_wip_tpl + \
'srv_wip_images_d = "%s/wip/images/"\n'%root_srv_dom + \
'srv_wip_files_d = "%s/wip/files/"\n'%root_srv_dom + \
'srv_www = "%s/www/"\n'%root_srv_dom + \
'srv_www_tpl_d = "%s"\n'%srv_www_tpl + \
'srv_www_images_d = "%s/www/images/"\n'%root_srv_dom + \
'srv_www_files_d = "%s/www/files/"\n'%root_srv_dom + \
'\n' + \
'# Servers files (wip)\n' + \
'wip_logo_f = "%s%s"\n'%(srv_wip_tpl, logo) + \
'wip_css_f = "%sstyles.css"\n'%srv_wip_tpl + \
'wip_navbar_f = "%snavbar.html"\n'%srv_wip_tpl + \
'wip_sidebar_f = "%ssidebar.html"\n'%srv_wip_tpl + \
'wip_metas_f = "%smetas.html"\n'%srv_wip_tpl + \
'wip_footer_f = "%sfooter.html"\n'%srv_wip_tpl + \
'\n' + \
'# Servers files (www)\n' + \
'www_logo_f = "%s%s"\n'%(srv_www_tpl, logo) + \
'www_css_f = "%sstyles.css"\n'%srv_www_tpl + \
'www_navbar_f = "%snavbar.html"\n'%srv_www_tpl + \
'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \
'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \
'www_footer_f = "%sfooter.html"'%srv_www_tpl
tyto.set_file(dom.config, False, set_f)
@ -758,8 +756,7 @@ def create_metas(option):
'<meta name="medium" content="website" />\n' + \
'<meta name="revisit-after" content="3 days" />'
tyto.set_file(dom.metas_f, 'new', metas_tags)
logs.out("32", dom.metas_f, False)
tyto.set_file(dom.metas_f, 'New', metas_tags)
# Create an empty html file in wip/www server if not exists
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)
tyto.set_file(dom.navbar_f, 'new', navbar_lang)
logs.out("32", dom.navbar_f, False)
tyto.set_file(dom.navbar_f, 'New', navbar_lang)
# Create wip navbar file
html.create_navbar('wip')
@ -836,7 +832,6 @@ def create_sidebar(option):
# Create an empty html file in wip/www server if not exists
if not tyto.exists(dom.wip_sidebar_f):
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'
if tyto.exists(dom.sidebar_f):
@ -887,8 +882,7 @@ def create_sidebar(option):
dom.sidebar_items
)
tyto.set_file(dom.sidebar_f, 'new', sidebar_lang)
logs.out("32", dom.sidebar_f, False)
tyto.set_file(dom.sidebar_f, 'New', sidebar_lang)
#=============================#
@ -1054,8 +1048,7 @@ def create_footer(option):
if option == "form": return
logs.out("255", '', True)
tyto.set_file(dom.footer_f, 'new', footer)
logs.out("32", dom.footer_f, False)
tyto.set_file(dom.footer_f, 'New', footer)
# Create footer file in wip server if not exists
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
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)
else: user_metas = '%s%s'%(tab, line)
tyto.set_file(target, True, user_metas)
logs.out("32", target, False)
tyto.set_file(target, 'New', user_metas)
#==============================================#
@ -366,7 +365,6 @@ def create_navbar(option):
if not navbar_items:
if not tyto.exists(target):
tyto.set_file(target, 'New', '')
logs.out("32", target, False)
logs.out('28', '%s'%langs.log.navbar, False)
return
@ -382,7 +380,6 @@ def create_navbar(option):
), True)
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 tyto.exists(target):
tyto.set_file(target, 'New', '')
logs.out("32", target, False)
logs.out('28', '%s'%langs.log.sidebar, False)
return
@ -504,7 +500,6 @@ def create_sidebar(option):
), True)
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)
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),
'43' : '%s%s%s'%(CY, langs.log.dom_no, CS),
'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),
'60' : '\n%s'%langs.log.status_r,
'255' : '%s'%langs.log.laterout

View File

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

View File

@ -1,11 +1,27 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: ATOM/RSS template
# Description: Create raw RSS template
# file: rss.py
# Folder: /var/lib/tyto/program/
# By echolib (XMPP: im@echolib.re)
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
# Tyto - Littérateur
#
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License
# 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
@ -33,42 +49,48 @@ def create_feed():
'<rss version="2.0">\n' + \
' <channel>\n' + \
' <title>%s - %s - Flux RSS 2.0</title>\n'%(
db.domain_title, db.domain_www_url
) + \
' <link>%s</link>\n'%db.domain_www_url + \
' <description>%s %s (%s)</description>\n'%(
tyto.trans[19][tyto.n], db.domain_title, db.domain_about
) + \
dom.title, dom.www_url
) + \
' <link>%s</link>\n'%dom.www_url + \
' <description>RSS 2.0 - %s (%s)</description>\n'%(
dom.title, dom.about
) + \
' <image>\n' + \
' <url>%s/%s</url>\n'%(db.domain_www_url, db.domain_logo) + \
' <title>logo %s</title>\n'%db.domain_title + \
' <link>%s</link>\n'%db.domain_www_url + \
' <url>%s/%s</url>\n'%(dom.www_url, dom.logo) + \
' <title>logo %s</title>\n'%dom.title + \
' <link>%s</link>\n'%dom.www_url + \
' </image>\n' + \
' <language>%s</language>\n'%db.domain_lang + \
' <category>%s</category>\n'%db.domain_tags + \
' <language>%s</language>\n'%dom.lang_site + \
' <category>%s</category>\n'%dom.tags + \
' <lastBuildDate>%s</lastBuildDate>\n'%tyto.nowdate() + \
' <copyright>%s</copyright>\n'%db.domain_license + \
' <webMaster>%s</webMaster>\n'%db.domain_mail + \
' <copyright>%s</copyright>\n'%dom.license + \
' <webMaster>%s</webMaster>\n'%dom.mail + \
' <generator>%s</generator>'%tyto.Tyto
# 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,
reverse=True
)
rss_item = False
nbr_item = 0
# Loop published articles. Get databases of 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
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
nbr_item += 1
if nbr_item > dom.rss_items: break
if nbr_item > dom.rss_items:
break
set_f = \
'%s\n'%set_f + \
@ -81,7 +103,7 @@ def create_feed():
' <author>%s</author>\n'%author + \
' <image>\n' + \
' <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 + \
' </image>\n' + \
' <category>%s</category>\n'%tags + \
@ -98,6 +120,5 @@ def create_feed():
' </channel>\n' + \
'</rss>'
tyto.set_file(db.www_rss, 'New', set_f)
logs.out("33", db.www_rss, False)
tyto.set_file(dom.www_rss_f, 'New', set_f)

View File

@ -241,11 +241,12 @@ def edit_file(edit_file):
logs.out("1", "/usr/bin/nano", True)
#=================#
# Create a file #
# Or append text #
# new: True/false #
#-----------------#
#=====================#
# Create a file #
# Or append text #
# new: True = create #
# False = Append #
#---------------------#
def set_file(path, new, text):
if new: opt = "w"
else: opt = "a"
@ -254,6 +255,8 @@ def set_file(path, new, text):
file = open(path, opt)
file.write(text + '\n')
file.close()
if opt == 'w':
logs.out("32", path, False)
except:
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)
logs.out("33", '%s%s'%(dom.srv_wip, db.direc_src), False)
tyto.set_file(db.post_wip, 'New', html.main_page)
logs.out("32", db.post_wip, False)
# Copy needed files (Also create sub-folders)
tyto.files_to_srv('wip')

View File

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

View File

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