RSS: create rss.xml, for wip, or www server with "X" ready items
This commit is contained in:
parent
4e864d0d1e
commit
9483f72170
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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')
|
|
@ -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 = '<?xml version="1.0" encoding="utf-8"?>\n' + \
|
||||
'<rss version="2.0">\n' + \
|
||||
' <channel>\n' + \
|
||||
' <title>%s %s %s %s Flux RSS 2.0</title>\n'%(
|
||||
domain.domain_title,
|
||||
domain.sep_titles,
|
||||
domain.domain_name,
|
||||
domain.sep_titles
|
||||
) + \
|
||||
' <link>%s</link>\n'%domain.domain_url + \
|
||||
' <description>%s</description>\n'%domain.domain_about + \
|
||||
' <language>%s</language>\n'%domain.domain_lang + \
|
||||
' <lastBuildDate>%s</lastBuildDate>\n'%log.nowdate() + \
|
||||
' <copyright>%s</copyright>\n'%domain.domain_license + \
|
||||
' <webMaster>%s</webMaster>\n'%domain.domain_mail + \
|
||||
' <generator>Tyto - Littérateur</generator>\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 = ' <item>\n' + \
|
||||
' <title>%s</title>\n'%post_title + \
|
||||
' <link>%s</link>\n'%post_url + \
|
||||
' <guid>%s</guid>\n'%post_url + \
|
||||
' <pubDate>%s</pubDate>'%hash_srv[1] + \
|
||||
' <description>%s</description>\n'%post_about + \
|
||||
' <author>%s</author>\n' + \
|
||||
' </item>'
|
||||
|
||||
file = open(rss_file, 'a')
|
||||
file.write(rss_post)
|
||||
file.close()
|
||||
|
||||
# Close tags
|
||||
file = open(rss_file, 'a')
|
||||
file.write(' </channel>\n</rss>')
|
||||
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)
|
||||
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
|
@ -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 #
|
||||
|
|
Loading…
Reference in New Issue