From 9483f721703b39d19e213dbf9df9eb2f9f892d63 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Sat, 3 Dec 2022 14:21:25 +0100 Subject: [PATCH] RSS: create rss.xml, for wip, or www server with "X" ready items --- src/usr/local/bin/tyto | 5 +- src/var/lib/tyto/program/check.py | 6 +- src/var/lib/tyto/program/publish.py | 9 +++ src/var/lib/tyto/program/rss.py | 102 ++++++++++++++++++++++++++++ src/var/lib/tyto/program/sidebar.py | 2 +- src/var/lib/tyto/program/wip.py | 3 +- 6 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 src/var/lib/tyto/program/publish.py create mode 100644 src/var/lib/tyto/program/rss.py diff --git a/src/usr/local/bin/tyto b/src/usr/local/bin/tyto index 9b85801..9ee6d8e 100755 --- a/src/usr/local/bin/tyto +++ b/src/usr/local/bin/tyto @@ -34,7 +34,7 @@ Directories that must be writeable by Tyto # Import needed libs and tyto's libs import sys sys.path.insert(0, '/var/lib/tyto/program') -import check, wip, domain, log, sidebar +import check, wip, domain, log, sidebar, publish #=======# # Tools # @@ -54,7 +54,8 @@ def tyto_args(ta): 'wip' : wip.manage_wip, 'domain' : domain.manage_domain, 'log' : log.manage_log, - 'sidebar' : sidebar.manage_sidebar + 'sidebar' : sidebar.manage_sidebar, + 'publish' : publish.manage_publish } # Dict for Options diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index df1758f..f389de9 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -55,6 +55,9 @@ def post_IDs(file_post): print(':< Unused argument file') sys.exit(1) + global post_srv + post_srv = file_post.replace('.tyto','.html') + # Check if file exists or exit global post_uri post_uri = '%s%s'%(domain.domain_articles, file_post) @@ -73,7 +76,7 @@ def post_IDs(file_post): post_url = '%s%s/%s'%( domain.domain_protocol, domain.domain_name, file_html ) - + # From argument file_post # Set WEB link prefix. Count / in uri global weburi @@ -1223,6 +1226,7 @@ def create_DB(post_db): 'post_db = "%s"'%post_db, 'post_tmp = "%s"'%post_tmp, 'post_url = "%s"'%post_url, + 'post_srv = "%s"'%post_srv, '\n# Article Status', 'post_chk = (\'%s\', \'%s\')'%(hash_chk,time_chk), 'post_wip = (\'%s\', \'%s\')'%(hash_wip,time_wip), diff --git a/src/var/lib/tyto/program/publish.py b/src/var/lib/tyto/program/publish.py new file mode 100644 index 0000000..83c6229 --- /dev/null +++ b/src/var/lib/tyto/program/publish.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +import rss, domain + +def manage_publish(file_post, Force): + + # At ending process... + # Create rss.xml for www + rss.find_www(domain.srv_www, 'www') diff --git a/src/var/lib/tyto/program/rss.py b/src/var/lib/tyto/program/rss.py new file mode 100644 index 0000000..e67cdfc --- /dev/null +++ b/src/var/lib/tyto/program/rss.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# Name: Tyto - Littérateur +# Type: Global functions for HTML page +# Description: Create RSS for wip, publish +# file: rss.py +# Folder: /var/lib/tyto/programs/ +# By echolib (XMPP: im@echolib.re) +# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 + +#------------ +# funny stats +#------------ +# lines: +# functions: +# comments: +#---------------------------------------------------------------------- + +#********************************************************************** + +import os, glob +import domain, html, log + +rss_headers = '\n' + \ + '\n' + \ + ' \n' + \ + ' %s %s %s %s Flux RSS 2.0\n'%( + domain.domain_title, + domain.sep_titles, + domain.domain_name, + domain.sep_titles + ) + \ + ' %s\n'%domain.domain_url + \ + ' %s\n'%domain.domain_about + \ + ' %s\n'%domain.domain_lang + \ + ' %s\n'%log.nowdate() + \ + ' %s\n'%domain.domain_license + \ + ' %s\n'%domain.domain_mail + \ + ' Tyto - Littérateur\n' + + +#==================================# +# Create RSS.xmp at ending process # +# srv: srv_www or srv_wip # +#----------------------------------# +def find_www(srv, srv_type): + # Create sidebar.html + rss_file = srv + 'rss.xml' + file = open(rss_file, 'w') + file.write(rss_headers) + file.close() + + # Get conf file, sort by ctime, and reverse + files = glob.glob("%s*.conf"%domain.domain_db) + files.sort(key=lambda x: os.path.getctime(x)) + files.reverse() # last created first + + # Check db_file if article is in www + rss_item = 0 + for db_file in files: + exec(open(db_file).read(),globals()) + + # Check srv_type (www or wip) + if srv_type == 'www': hash_srv = post_www + elif srv_type == 'wip': hash_srv = post_wip + post_uri_www = '%s%s'%(srv, post_srv) + + if not hash_srv[0]: + continue + + if not os.path.exists('%s%s'%(srv, post_srv)): + msg_log = 'RSS > Unused Article in www: %s'%post_uri_www + log.append_f(domain.tyto_logs, msg_log, 1) + continue + + rss_item += 1 + rss_post = ' \n' + \ + ' %s\n'%post_title + \ + ' %s\n'%post_url + \ + ' %s\n'%post_url + \ + ' %s'%hash_srv[1] + \ + ' %s\n'%post_about + \ + ' %s\n' + \ + ' ' + + file = open(rss_file, 'a') + file.write(rss_post) + file.close() + + # Close tags + file = open(rss_file, 'a') + file.write(' \n') + file.close() + + # Log + + msg_log = 'RSS > Create file with %s items in www: %s'%( + rss_item, rss_file + ) + log.append_f(domain.tyto_logs, msg_log, 0) + + + diff --git a/src/var/lib/tyto/program/sidebar.py b/src/var/lib/tyto/program/sidebar.py index e17cfb9..59124b8 100644 --- a/src/var/lib/tyto/program/sidebar.py +++ b/src/var/lib/tyto/program/sidebar.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # Name: Tyto - Littérateur # Type: Global functions for HTML page -# Description: Create final HTML Page +# Description: Create sidebar from file tyto.sidebar # file: sidebar.py # Folder: /var/lib/tyto/programs/ # By echolib (XMPP: im@echolib.re) diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 911725e..770fec4 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -17,7 +17,7 @@ #********************************************************************** import sys, os, re -import check, log, domain, html +import check, log, domain, html, rss Post_Err = False @@ -153,7 +153,6 @@ def manage_wip(file_post, Force): msg_log = 'Edit Database: %s'%check.post_db log.append_f(check.post_logs, msg_log, 0) - #============================# # HTML CONVERTERS # # wip_tmp: new replacedlines #