updated for stats ; added images, links, files.

This commit is contained in:
Cyrille L 2023-04-05 00:28:41 +02:00
parent de2533480e
commit af963b07bd
9 changed files with 215 additions and 176 deletions

View File

@ -99,7 +99,6 @@ def check_all(option):
continue
found = True
print(' ├ [%s] > %s'%(db.title, db.post_src))
check_process(args.target)
if post_err: logs.out("44", args.target, False)
@ -183,6 +182,8 @@ def check_process(target):
#print("In Dev: return from process...")
if post_err: return
print('\n ├─ [%s] > %s'%(title, db.uri_file))
# Check for valid contents
check_content(post_bottom)
@ -264,10 +265,12 @@ def count_words(post_bottom):
#---------------------------------------------#
def if_icodes_bcodes_quotes(post_bottom):
global icode, quote, bcode, post_err
global nbr_titles, nbr_quotes, nbr_bcodes, nbr_ancs, nbr_coms
global post_titles, nbr_quotes, nbr_bcodes, nbr_ancs, post_comments
global post_images, post_raws, fcodes
icode = quote = in_quote = bcode = in_bcode = in_bq = False
nbr_titles = nbr_quotes = nbr_bcodes = nbr_ancs = nbr_coms = 0
post_titles = nbr_quotes = nbr_bcodes = nbr_ancs = 0
post_images = post_comments = post_raws = fcodes = 0
for ln, line in enumerate(post_bottom.rsplit('\n'), 1):
# Stat Comments, Titles, Anchors
@ -295,15 +298,21 @@ def if_icodes_bcodes_quotes(post_bottom):
if in_bq:
continue
elif line.startswith(tyto.titles_tags) and not in_bq:
nbr_titles += 1
elif line.startswith(tyto.titles_tags):
post_titles += 1
continue
elif line.startswith('#') and not in_bq:
nbr_coms += 1
elif line.startswith('#'):
post_comments += 1
continue
elif line.startswith(tyto.single_tags[1][0]) and not in_bq:
elif line.startswith(tyto.single_tags[1][0]):
nbr_ancs += 1
continue
elif line.startswith('_image:'):
post_images += 1
elif line.startswith('_raw:'):
post_raws += 1
elif line.startswith('_code:'):
fcodes += 1
# icodes
elif tyto.words_tags[9][0] or tyto.words_tags[9][1] in line:
@ -398,13 +407,13 @@ def check_date(date):
#-------------------------------------------#
def check_opt_tags(post_header):
global stat_links, stat_images, stat_files, stat_raws, stat_codes
global stat_snpics, snpic_url, stat_abbrs, post_abbrs
global opt_tags_post_name
global post_links, stat_snpics, snpic_url, stat_abbrs, post_abbrs
global post_files, opt_tags_post_name
global files_post
# Statistics
stat_links = stat_images = stat_files = stat_raws = stat_codes = 0
stat_snpics = post_abbrs = stat_abbrs = 0
post_links = post_files = stat_snpics = post_abbrs = stat_abbrs = 0
files_post = (())
# Set default post pic
@ -413,12 +422,12 @@ def check_opt_tags(post_header):
# Search for term in article
opt_tags_post_name = \
{
'link' : "_%s",
'image' : "_image:%s",
'file' : "__%s",
'raw' : "_raw:%s",
'code' : '_code:%s',
'abbr' : "(%s)"
"link" : "_%s",
"image" : "_image:%s",
"file" : "__%s",
"raw" : "_raw:%s",
"code" : '_code:%s',
"abbr" : "(%s)"
}
# Check post header for each optional tags
@ -427,6 +436,9 @@ def check_opt_tags(post_header):
if line.startswith('%s:'%tag):
check_3lines(tag, ln, line)
print("> post_files =", post_files)
print("> post_links =", post_links)
#============================================#
# Do stats, check 3 lines tags from ln #
@ -434,8 +446,8 @@ def check_opt_tags(post_header):
# Exception for snpic (Different conditions) #
#--------------------------------------------#
def check_3lines(tag, ln, line):
global post_err, db_tag, files_post
global post_abbrs
global post_err, db_tag, files_post, post_bottom
global post_abbrs, post_links, post_files
stat_tag = "stat_%ss"%tag
@ -478,6 +490,12 @@ def check_3lines(tag, ln, line):
globals()[db_tag] = ((opt_tags_post_name[tag]%name),)
if tag == "file":
post_files = post_files + post_bottom.count('__%s'%name)
post_bottom = post_bottom.replace('__%s'%name, '[file-link]')
elif tag == "link":
post_links = post_links + post_bottom.count('_%s'%name)
# URI/URL and Alt-Text
#---------------------
# loop 1,2. Next real line from start tag
@ -688,8 +706,7 @@ def check_content(post_bottom):
tyto.words_tags[13][4],
tyto.markers_lists,
db.uri_file
), False
)
), False)
post_err = True
@ -769,7 +786,7 @@ def create_database():
'title = "%s"\n'%title + \
'about = "%s"\n'%about + \
'author = "%s"\n'%author + \
'tags = "%s"\n'%tags + \
'meta_tags = "%s"\n'%tags + \
'date = "%s"\n'%date_tr + \
'snpic = "%s"\n'%snpic_url + \
'\n# Used files\n' + \
@ -824,10 +841,10 @@ def create_database():
# Statistics configurations
#--------------------------
stat_words = post_words - nbr_titles # Count real words
stat_words = post_words - post_titles # Count real words
db_stats = \
'# Statistics configurations\n' + \
'# Statistics from header\'s tags\n' + \
'uniq_anchors = %d\n'%nbr_ancs + \
'uniq_abbrs = %d\n'%stat_abbrs + \
'uniq_links = %d\n'%stat_links + \
@ -835,27 +852,33 @@ def create_database():
'uniq_files = %d\n'%stat_files + \
'uniq_codes = %d\n'%stat_codes + \
'uniq_raws = %d\n'%stat_raws + \
'\n# Statistics from post content\n' + \
'post_coms = %d\n'%nbr_coms + \
'post_tags = %d\n'%stat_tags + \
'post_lines = %d\n'%ln_article + \
'post_words = %d\n'%stat_words + \
'post_titles = %d\n'%nbr_titles + \
'post_paragraphs = %d\n'%post_paragraphs + \
'post_anchors = %d\n'%post_anchors + \
'post_abbrs = %d\n'%post_abbrs + \
'post_strongs = %d\n'%post_strongs + \
'post_bolds = %d\n'%post_bolds + \
'post_emphasis = %d\n'%post_emphasis + \
'post_italics = %d\n'%post_italics + \
'post_dels = %d\n'%post_dels + \
'post_underlines = %d\n'%post_underlines + \
'post_cites = %d\n'%post_cites + \
'post_customs = %d\n'%post_customs + \
'post_icodes = %d\n'%tyto.nbr_icodes + \
'post_bcodes = %d\n'%nbr_bcodes + \
'post_quotes = %d\n'%nbr_quotes + \
'post_lists = %d\n'%post_lists
'\n# Statistics from post contents\n' + \
'comments = %d\n'%post_comments + \
'tags = %d\n'%stat_tags + \
'lines = %d\n'%ln_article + \
'words = %d\n'%stat_words + \
'titles = %d\n'%post_titles + \
'paragraphs = %d\n'%post_paragraphs + \
'links = %d\n'%post_links + \
'images = %d\n'%post_images + \
'anchors = %d\n'%post_anchors + \
'abbrs = %d\n'%post_abbrs + \
'strongs = %d\n'%post_strongs + \
'bolds = %d\n'%post_bolds + \
'emphasis = %d\n'%post_emphasis + \
'italics = %d\n'%post_italics + \
'dels = %d\n'%post_dels + \
'underlines = %d\n'%post_underlines + \
'cites = %d\n'%post_cites + \
'customs = %d\n'%post_customs + \
'icodes = %d\n'%tyto.nbr_icodes + \
'bcodes = %d\n'%nbr_bcodes + \
'quotes = %d\n'%nbr_quotes + \
'lists = %d\n'%post_lists + \
'\n# Included files in post\'s contents\n' + \
'files = %d\n'%post_files + \
'raws = %d\n'%post_raws + \
'codes = %d\n'%fcodes
# Create Post DB
#---------------

View File

@ -93,7 +93,7 @@ if args.target \
'title',
'about',
'author',
'tags',
'meta_tags',
'date',
'snpic',
'uris',
@ -103,25 +103,30 @@ if args.target \
'uniq_images',
'uniq_files',
'uniq_raws',
'post_coms',
'post_tags',
'post_words',
'post_titles',
'post_paragraphs',
'post_anchors',
'post_abbrs',
'post_strongs',
'post_bolds',
'post_emphasis',
'post_italics',
'post_dels',
'post_underlines',
'post_cites',
'post_customs',
'post_icodes',
'post_bcodes',
'post_quotes',
'post_lists'
'comments',
'tags',
'words',
'titles',
'paragraphs',
'links',
'images',
'anchors',
'abbrs',
'strongs',
'bolds',
'emphasis',
'italics',
'dels',
'underlines',
'cites',
'customs',
'icodes',
'bcodes',
'quotes',
'lists',
'files',
'raws',
'codes',
)
for value in values:

View File

@ -250,8 +250,8 @@ def create_domain(target):
#-------------------------------------
root_srv_dom = '%s/%s'%(srv, shortname)
srv_wip_tpl = "%s/wip/template/"%root_srv_dom
stats_wip_f = "%s/wip/tyto_wip_statoolinfos.conf"%root_srv_dom
stats_www_f = "%s/www/tyto_www_statoolinfos.conf"%root_srv_dom
stats_wip_f = "%s/wip/tyto_wip_statoolinfos.properties"%root_srv_dom
stats_www_f = "%s/www/tyto_www_statoolinfos.properties"%root_srv_dom
srv_www_tpl = "%s/www/template/"%root_srv_dom
set_f = \

View File

@ -60,7 +60,7 @@ def create_metas_page():
#-------------------
metas_page = ''
scale = 'width=device-width, initial-scale=1.0'
all_tags = dom.tags + ',' + db.tags
all_tags = dom.tags + ',' + db.meta_tags
css_ref = 'href="%stemplate/%s"'%(db.sub_uri, dom.css)
rss_ref = 'type="application/rss+xml" ' + \
'href="%s%s" title="RSS 2.0. %s %s %s"'%(

View File

@ -63,13 +63,13 @@ def loop_articles(process):
global sti_articles
# Get databases of articles
for post_db in os.listdir(dom.articles_db_d):
if not post_db.endswith('.config'):
for db in os.listdir(dom.articles_db_d):
if not db.endswith('.config'):
continue
# Load DB
post_db = '%s%s'%(dom.articles_db_d, post_db)
exec(open(post_db).read(),globals())
db = '%s%s'%(dom.articles_db_d, db)
exec(open(db).read(),globals())
# Check hash status (wip/www)
hash_srv = ''
@ -108,26 +108,31 @@ def count_stats(add):
"sti_uniq_files" : uniq_files,
"sti_uniq_codes" : uniq_codes,
"sti_uniq_raws" : uniq_raws,
"sti_post_coms" : post_coms,
"sti_post_tags" : post_tags,
"sti_post_lines" : post_lines,
"sti_post_words" : post_words,
"sti_post_titles" : post_titles,
"sti_post_paragraphs" : post_paragraphs,
"sti_post_anchors" : post_anchors,
"sti_post_abbrs" : post_abbrs,
"sti_post_strongs" : post_strongs,
"sti_post_bolds" : post_bolds,
"sti_post_emphasis" : post_emphasis,
"sti_post_italics" : post_italics,
"sti_post_dels" : post_dels,
"sti_post_underlines" : post_underlines,
"sti_post_cites" : post_cites,
"sti_post_customs" : post_customs,
"sti_post_icodes" : post_icodes,
"sti_post_bcodes" : post_bcodes,
"sti_post_quotes" : post_quotes,
"sti_post_lists" : post_lists,
"sti_comments" : comments,
"sti_tags" : tags,
"sti_lines" : lines,
"sti_words" : words,
"sti_titles" : titles,
"sti_paragraphs" : paragraphs,
"sti_links" : links,
"sti_images" : images,
"sti_anchors" : anchors,
"sti_abbrs" : abbrs,
"sti_strongs" : strongs,
"sti_bolds" : bolds,
"sti_emphasis" : emphasis,
"sti_italics" : italics,
"sti_dels" : dels,
"sti_underlines" : underlines,
"sti_cites" : cites,
"sti_customs" : customs,
"sti_icodes" : icodes,
"sti_bcodes" : bcodes,
"sti_quotes" : quotes,
"sti_lists" : lists,
"sti_files" : files,
"sti_raws" : raws,
"sti_codes" : codes,
}
# Count
@ -148,45 +153,53 @@ def create_stats_file(file_uri):
'# Generated: %s\n'%tyto.nowdate() + \
'\n' + \
'# Uniq statistics from articles\' headers\n' + \
'stats_articles = %d\n'%int(sti_articles) + \
'stats_uniq_anchors = %d\n'%stats["sti_uniq_anchors"] + \
'stats_uniq_abbrs = %d\n'%stats["sti_uniq_abbrs"] + \
'stats_uniq_links = %d\n'%stats["sti_uniq_links"] + \
'stats_uniq_images = %d\n'%stats["sti_uniq_images"] + \
'stats_uniq_files = %d\n'%stats["sti_uniq_files"] + \
'stats_uniq_codes = %d\n'%stats["sti_uniq_codes"] + \
'stats_uniq_raws = %d\n'%stats["sti_uniq_raws"] + \
'articles = %d\n'%int(sti_articles) + \
'uniq_anchors = %d\n'%stats["sti_uniq_anchors"] + \
'uniq_abbrs = %d\n'%stats["sti_uniq_abbrs"] + \
'uniq_links = %d\n'%stats["sti_uniq_links"] + \
'uniq_images = %d\n'%stats["sti_uniq_images"] + \
'uniq_files = %d\n'%stats["sti_uniq_files"] + \
'uniq_codes = %d\n'%stats["sti_uniq_codes"] + \
'uniq_raws = %d\n'%stats["sti_uniq_raws"] + \
'\n' + \
'# Statistics from articles\' contents\n' + \
'stats_posts_coms = %d\n'%stats["sti_post_coms"] + \
'stats_posts_tags = %d\n'%stats["sti_post_tags"] + \
'stats_posts_lines = %d\n'%stats["sti_post_lines"] + \
'stats_posts_words = %d\n'%stats["sti_post_words"] + \
'stats_posts_titles = %d\n'%stats["sti_post_titles"] + \
'stats_posts_paragraphs = %d\n'%stats["sti_post_paragraphs"] + \
'stats_posts_anchors = %d\n'%stats["sti_post_anchors"] + \
'stats_posts_abbrs = %d\n'%stats["sti_post_abbrs"] + \
'stats_posts_strongs = %d\n'%stats["sti_post_strongs"] + \
'stats_posts_bolds = %d\n'%stats["sti_post_bolds"] + \
'stats_posts_emphasis = %d\n'%stats["sti_post_emphasis"] + \
'stats_posts_italics = %d\n'%stats["sti_post_italics"] + \
'stats_posts_dels = %d\n'%stats["sti_post_dels"] + \
'stats_posts_underlines = %d\n'%stats["sti_post_underlines"] + \
'stats_posts_cites = %d\n'%stats["sti_post_cites"] + \
'stats_posts_customs = %d\n'%stats["sti_post_customs"] + \
'stats_posts_icodes = %d\n'%stats["sti_post_icodes"] + \
'stats_posts_bcodes = %d\n'%stats["sti_post_bcodes"] + \
'stats_posts_quotes = %d\n'%stats["sti_post_quotes"] + \
'stats_posts_lists = %d\n'%stats["sti_post_lists"]
'comments = %d\n'%stats["sti_comments"] + \
'tags = %d\n'%stats["sti_tags"] + \
'lines = %d\n'%stats["sti_lines"] + \
'words = %d\n'%stats["sti_words"] + \
'titles = %d\n'%stats["sti_titles"] + \
'paragraphs = %d\n'%stats["sti_paragraphs"] + \
'links = %d\n'%stats["sti_links"] + \
'images = %d\n'%stats["sti_images"] + \
'anchors = %d\n'%stats["sti_anchors"] + \
'abbrs = %d\n'%stats["sti_abbrs"] + \
'strongs = %d\n'%stats["sti_strongs"] + \
'bolds = %d\n'%stats["sti_bolds"] + \
'emphasis = %d\n'%stats["sti_emphasis"] + \
'italics = %d\n'%stats["sti_italics"] + \
'dels = %d\n'%stats["sti_dels"] + \
'underlines = %d\n'%stats["sti_underlines"] + \
'cites = %d\n'%stats["sti_cites"] + \
'customs = %d\n'%stats["sti_customs"] + \
'icodes = %d\n'%stats["sti_icodes"] + \
'bcodes = %d\n'%stats["sti_bcodes"] + \
'quotes = %d\n'%stats["sti_quotes"] + \
'lists = %d\n'%stats["sti_lists"] + \
'\n' + \
'# Included files in article\'s contents\n' + \
'files = %d\n'%stats["sti_files"] + \
'codes = %d\n'%stats["sti_codes"] + \
'raws = %d\n'%stats["sti_raws"]
tyto.set_file(file_uri, 'New', sti)
try:
print('', langs.site.stats_f%(
sti_articles, stats["sti_post_words"]
sti_articles, stats["sti_words"]
)
)
except:
print(' └ Articles = %s ; Words = %s'%(
sti_articles, stats["sti_post_words"]
sti_articles, stats["sti_words"]
)
)

View File

@ -35,7 +35,7 @@
import os, sys, re, subprocess, locale, base64, datetime, shutil
from hashlib import blake2b
import args, dom, logs, langs, form
import args, dom, logs
# :D
Tyto = 'Tyto - Littérateur'
@ -56,9 +56,9 @@ needed_header_tags = \
# Optional header tags
opt_header_tags = \
(
'link',
'image',
'file',
'image',
'link',
'abbr',
'raw',
'code',
@ -545,19 +545,3 @@ def files_to_srv(server):
logs.out("32", f_dst, False)
except:
logs.out('4', f_dst, True)
#
#
#
def process_all(process):
# if target == 'all':
if args.target == "again":
form.asking("%s%s "%(
langs.site.wip_again, langs.site.q
), True)
elif args.target == "all":
print('%s again current matches articles'%process)
elif args.target == "newer":
print('%s newer articles'%process)

View File

@ -97,7 +97,16 @@ def manage(target):
#----------------------------------------#
def wip_all(process):
# Ask or show what to do
tyto.process_all('Wip')
if args.target == "again":
form.asking("%s%s "%(
langs.site.wip_again, langs.site.q
), True)
elif args.target == "all":
print('%s'%langs.site.wip_older)
elif args.target == "newer":
print('%s'%langs.site.wip_newer)
# Sort by newer articles (created by last check)
db_articles = sorted(Path(dom.articles_db_d).iterdir(),
@ -121,7 +130,7 @@ def wip_all(process):
# Article has changed and not check
if db.old_chk:
logs.out("9", post_db, False)
logs.out("9", db.post_src, False)
continue
# newer: article not yet wip
@ -137,7 +146,6 @@ def wip_all(process):
continue
found = True
print(' ├ [%s] > %s'%(db.title, db.post_src))
wip_article(db.post_src)
if not found: logs.out("28", '(wip)', True)
@ -151,16 +159,18 @@ def wip_article(target):
# Convert file to strings
file_to_string(target)
print('\n ├─ [%s] > %s'%(db.title, db.post_src))
global post_header
global post_bottom
# Protect block-codes and quotes
if db.post_bcodes or db.post_quotes > 0:
if db.bcodes or db.quotes > 0:
tyto.protect_bcodes_quotes('wip', post_bottom)
post_bottom = tyto.protect_article
# Protect inline-codes
if db.post_icodes > 0:
if db.icodes > 0:
tyto.protect_icodes(post_bottom)
post_bottom = tyto.protect_article
@ -281,7 +291,7 @@ def wip_words_tags():
for ln, line in enumerate(post_bottom.rsplit('\n')):
# Paragraphs
# Open tag
if db.post_paragraphs > 0:
if db.paragraphs > 0:
if line.startswith(tyto.words_tags[10][0]):
set_css = tyto.get_css(line)
replace_in_post(post_bottom.rsplit('\n')[ln],
@ -293,7 +303,7 @@ def wip_words_tags():
tyto.words_tags[10][3]
)
# Open anchors link
if db.post_anchors == 0: continue
if db.anchors == 0: continue
anchor_links = re.findall(r'>_(.+?):', line)
for item in anchor_links:
@ -462,7 +472,7 @@ def quote_params(qline):
# Convert quote in article #
#--------------------------#
def wip_quotes() :
if db.post_quotes == 0: return
if db.quotes == 0: return
global author, link, lang, book, date
@ -609,7 +619,7 @@ def wip_quotes() :
# Content is HTML ready #
#--------------------------#
def wip_icodes():
if db.post_icodes == 0: return
if db.icodes == 0: return
matches = re.findall(r'I64.(.*?).I64', post_bottom)
for match in matches:
@ -625,7 +635,7 @@ def wip_icodes():
# Content is raw, and have to be converted in HTML #
#--------------------------------------------------#
def wip_bcodes():
if db.post_bcodes == 0: return
if db.bcodes == 0: return
matches = re.findall(r'B64.(.*?).B64', post_bottom)
for match in matches:
@ -664,7 +674,7 @@ def wip_bcodes():
# Check between titles to set div or not #
#----------------------------------------#
def wip_titles():
if db.post_titles == 0: return
if db.titles == 0: return
global post_bottom
@ -760,7 +770,7 @@ def wip_filecode(target):
# Search lines for list marker #
#------------------------------#
def wip_lists():
if not db.post_lists > 0: return
if not db.lists > 0: return
global post_bottom

View File

@ -70,13 +70,15 @@ generator = "Generator"
post_chg = "Article was edited. Check it"
# Wip
wip_new = "Create new HTML page in wip"
wip_again = "Create again already converted pages"
wip_new = "Create a new HTML page in 'wip' server again"
wip_again = "Create already converted pages again"
wip_newer = "Create missing HTML pages"
wip_older = "Update HTMl pages"
# Form
#----------------------------------------------------------------------
form_edit = "Edit the domain with the form"
form_start = ' ├─────────────────────────────────────────────\n' + \
form_start = ' ├─────────────────────────────────────────────\n' + \
' │ Configure a new domain for current directory │\n' + \
' │ Answer Y/y = yes. Enter to keep {default}\n' + \
' │ Empty Answer cancel process, except for │\n' + \

View File

@ -69,8 +69,10 @@ generator = "Generateur"
post_chg = "Article édité. Le vérifier"
# Wip
wip_new = "Créer une nouvelle page HTML dans wip"
wip_new = "Créer encore une page HTML dans le serveur 'wip'"
wip_again = "Créer encore les pages déjà converties"
wip_newer = "Créer les pages HTML manquantes"
wip_older = "Mise à jour des pages HTML"
# Formulaire
#----------------------------------------------------------------------