# -*- coding: utf-8 -*-
#!/usr/local/bin/python3
#
# Written for WiseWomanBot by WiseWoman
# as an adaptation of the Kybot on VroniPlag Wiki by WiseWoman
# May 5, 2016
# updated May 4, 2019
#
# Uses python > =3.7.3 installed as python3
# and the pywikibot library pwb >= 3.1, and a current requests library. If
# requests is missing, do 'pip3 install requests' (sudo as necessary)
#
# If python is misbehaving on account of the locale, start a bash and then enter
# export LC_ALL=en_US.UTF-8
# export LANG=en_US.UTF-8
#
# Log in to Vroniplag as a bot and reply with the password.
#
# python3 pwb.py login
#
#
# First call this:
#
# python3 pwb.py listpages -cat:Xxx > foo
#
# That gives us a list of files. Edit it to remove the sources and any random
# stuff that shows up. Yes, it must be called foo.
# Did Unfragmentierte Fundstellen get listed?
# It is often missing the category and thus missing here.
# Is Befunde there? You will need to edit it out or make a proper
# parameter sometime soon to deal with this. The program generates an empty
# Befunde, if one exists, you can edit it out of the generated newHNR.
#
# Running this current file creates a file newHNR-Xxx.txt for setting up the HNR for case Xxx
# and a file moveHNR-Xxx.txt for moving the files.
# Use the parameters from the moving request page "Verschiebewünsche"
#
# python3 makeHNR.py -pubyear:1997 -startpage:1 -endpage:157 -bcstartpage:-8 -bcendpage:200 -target:Xxx
#
# Check the files created - there are often empty lines or missing lines,
# usually caused by missing categories.
#
#
# Then call:
#
# python3 pwb.py pagefromfile.py -notitle -autosummary -file:newHNR-Xxx.txt
#
# with the target instead of Xxx to make the pages. Ignore all the warnings.
#
#
# Now call
#
# python3 pwb.py movepages.py -noredirect -pairsfile:moveHNR-Xxx.txt
#
# with the target instead of Xxx to move all the Analyse:Xxx files to the HNR.
#
# Pro tip: check the files afterwards with
# https://vroniplag.wikia.org/de/index.php?title=Spezial%3ASemantische_Suche&q=[[Kuerzel%3A%3ABes]]%0D%0A[[Kategorie%3AFragment]]%0D%0A+&po=%3FSeiteArbeit%0D%0A%3FZeileArbeit%0D%0A%3FQuelle%0D%0A%3FSeiteQuelle%0D%0A%3FZeileQuelle%0D%0A%3FTypus%0D%0A%3FFragmentStatus%0D%0A&eq=yes&p[format]=table&sort_num=&order_num=ASC&p[limit]=500&p[offset]=&p[link]=all&p[sort]=&p[headers]=plain&p[mainlabel]=Fragmente&p[intro]=&p[outro]=&p[searchlabel]=%E2%80%A6weitere+Ergebnisse&p[default]=&p[class]=sortable+wikitable+smwtable&eq=yes
# to make sure nothing went wrong (i.e. phantom or duplicate pages).
#
# Log out with
# python3 pwb.py login -logout
#
# Don't forget to add the moved case to the top table in Analyse:Home and delete Analyse:Xxx
#
from __future__ import division
__version__ = '$Id$'
import sys
import codecs
class Config(object):
def __init__(self):
self.namespace = 112
self.target = "Xxx"
self.startpage = 0
self.endpage = 0
self.bcstartpage = 0
self.bcendpage = 0
self.pubyear = 0
config = Config()
def files():
# python3 pwb.py listpages -cat:Xxx > foo
ifile=open('foo','r')
ofile=open('moveHNR-'+config.target+'.txt','w')
# there is a carriage return at the end of the string we have to strip off
temp=[line[5:-1] for line in ifile]
for filename in temp:
ofile.write('[[Analyse:'+filename+']]\n')
ofile.write('[['+filename+']]\n')
print(filename)
ofile.close()
def run():
# set up the outputfile
ofile = open('newHNR-'+config.target+'.txt', 'w')
# generate the main page template
ofile.write('{{-start-}}\n')
ofile.write("'''" + config.target + "'''\n")
ofile.write('__NOTOC__\n')
ofile.write('{{:' + config.target + '/Titelaufnahme}}\n')
ofile.write('\n')
ofile.write('== Seiten ==\n')
ofile.write('<br />\n')
ofile.write('{| class="ueberpruefte-fragmentseiten"\n')
ofile.write('! colspan="20" | Haupttext\n')
ofile.write('|-\n')
if config.startpage != 1:
for n in range(1, config.startpage):
ofile.write('||')
for n in range(config.startpage, config.endpage+1):
page = ''
if len(str(n)) == 1:
page = '00' + str(n)
elif len(str(n)) == 2:
page = '0' + str(n)
else:
page = str(n)
ofile.write('||[[' + config.target + '/' + page + '|' + page + ']]')
if n/20 == n//20 :
ofile.write('\n|-\n')
ofile.write('\n|-\n')
ofile.write('|}\n')
# Now there is a template for the legend, only need target and net number of pages
net_pages = str(config.endpage - config.startpage + 1)
ofile.write('{{Seitenübersicht|' + config.target + '|'+ net_pages +'}}\n')
ofile.write('==Wichtige Seiten==\n')
ofile.write('*[[' + config.target + '/Befunde|Befunde]]\n')
ofile.write('*[[' + config.target + '/Alle_Fragmente|Alle Fragmente]]\n')
ofile.write('*[[Quelle:' + config.target + '|Alle Quellen ({{#ask: [[Kategorie:' + config.target + ']] [[Kategorie:Quelle]] | format=count }})]]\n')
ofile.write('{{UntererTeilHauptseite2a|' + config.target + '|[[' + config.target + '/Unfragmentierte_Fundstellen|Unfragmentierte Fundstellen]]}}\n')
ofile.write('[[Kategorie:'+ config.target + ']]\n')
ofile.write('{{-stop-}}\n')
#generate the title record page
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Titelaufnahme'''\n")
ofile.write("=='''[[" + config.target + "|Eine kritische Auseinandersetzung mit der Dissertation von Dr. " + config.target + "]]'''==\n")
ofile.write('<div class=autobarcode id=autobarcode' + config.target + '><!--[if lte IE 8]>Bitte zur Darstellung der automatischen Barcodes einen aktuellen Browser verwenden!!<[endif]--></div> \n')
ofile.write('{{:VroniPlag_Wiki:Barcodehinweis}}\n')
ofile.write('[[Kategorie:'+ config.target + ']]\n')
ofile.write('[[Kategorie:Titelaufnahme]]\n')
ofile.write('{{-stop-}}\n')
#generate the barcode parameter page
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/AutoBarcodeParameter'''\n")
ofile.write('{ "AutoBarcodeParameter": {\n')
ofile.write('\t"prefix": "' + config.target + '",\n')
ofile.write('\t"reference": "[' + config.target )
if config.pubyear != None:
ofile.write(' ' + str(config.pubyear))
ofile.write(']",\n')
ofile.write('\t"from": ' + str(config.bcstartpage) + ',\n')
ofile.write('\t"to": ' + str(config.bcendpage) + ',\n')
ofile.write('\t"range": {"from": ' + str(config.startpage) + ', "to": ' + str(config.endpage) + '}\n')
ofile.write('\t}\n')
ofile.write('}\n')
ofile.write('{{-stop-}}\n')
#generate the qs pages
ofile.write('\n{{-start-}}\n')
ofile.write("'''Quelle:" + config.target + "'''\n")
ofile.write('{{QuellenListe}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Alle_Fragmente'''\n")
ofile.write('{{Alle_Fragmente|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Verwaist_n'''\n")
ofile.write('{{Verwaist_n|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Sichtung_p'''\n")
ofile.write('{{Sichtung_p|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Sichtung_v'''\n")
ofile.write('{{Sichtung_v|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Sichtung_k'''\n")
ofile.write('{{Sichtung_k|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Sichtung_u'''\n")
ofile.write('{{Sichtung_u|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Gesichtet_u'''\n")
ofile.write('{{Gesichtet_u|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Gesichtet_g'''\n")
ofile.write('{{Gesichtet_g|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Gesichtet_s'''\n")
ofile.write('{{Gesichtet_s|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Gesichtet_v'''\n")
ofile.write('{{Gesichtet_v|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Fragmente/Gesichtet_k'''\n")
ofile.write('{{Gesichtet_k|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
#generate the concept pages
ofile.write('\n{{-start-}}\n')
ofile.write("'''Konzept:" + config.target + "_und_Gt50'''\n")
ofile.write('{{#concept: [[Kategorie:Gt50]] [[Kategorie:' + config.target + ']]\n')
ofile.write('| ' + config.target + ' und Gt50\n')
ofile.write('}}<noinclude>{{DEFAULTSORT:' + config.target + '}}\n')
ofile.write('[[Kategorie:Konzepte]]</noinclude>\n')
ofile.write('{{-stop-}}\n')
ofile.write('\n{{-start-}}\n')
ofile.write("'''Konzept:" + config.target + "_und_Gt75'''\n")
ofile.write('{{#concept: [[Kategorie:Gt75]] [[Kategorie:' + config.target + ']]\n')
ofile.write('| ' + config.target + ' und Gt75\n')
ofile.write('}}<noinclude>{{DEFAULTSORT:' + config.target + '}}\n')
ofile.write('[[Kategorie:Konzepte]]</noinclude>\n')
ofile.write('{{-stop-}}\n')
#generate the discussion monitor page
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Diskussionsmonitor'''\n")
ofile.write('{{Diskussionsmonitor|' + config.target + '}}\n')
ofile.write('{{-stop-}}\n')
#generate the template pages
ofile.write('\n{{-start-}}\n')
ofile.write("'''Vorlage:PlagPage" + config.target + "'''\n")
ofile.write('<includeonly>{{PlagPage|titel=Dissertation|verf=Dr. ' + config.target + '|fragmente=' + config.target + '/Fragment_|oberkategorie=' + config.target + '|bildkategorien=' + config.target + '_}}</includeonly>\n')
ofile.write('<noinclude>[[Kategorie:Vorlagen|PlagPage' + config.target + ']]</noinclude>\n')
ofile.write('{{-stop-}}\n')
#generate the findings page
ofile.write('\n{{-start-}}\n')
ofile.write("'''" + config.target + "/Befunde'''\n")
ofile.write("__NOTOC__\n")
ofile.write("==Kapitelübersicht==\n")
ofile.write("* Die Dissertation enthält zahlreiche wörtliche und sinngemäße Textübernahmen, \n")
ofile.write("die nicht als solche kenntlich gemacht sind. Als betroffen festgestellt wurden \n")
ofile.write("bisher (Stand: TT. MMM 20JJ) folgende Kapitel, die sich teilweise als vollständig \n")
ofile.write("oder nahezu vollständig übernommen erwiesen haben – siehe Klammervermerke:\n")
ofile.write("\n==Herausragende Fundstellen==\n*\n")
ofile.write("\n==Herausragende Quellen==\n*\n")
ofile.write("\n==Andere Beobachtungen==\n*\n")
ofile.write("\n==Statistik==\n")
pagesInFile = config.endpage - config.startpage +1
ofile.write("{{Statistik|" + config.target + "|" + str(pagesInFile) + "}}\n\n")
ofile.write("==Illustration==\n")
ofile.write("{{Illustration2|" + config.target + "|" + config.target + " col.png|650}}\n")
ofile.write("'''Anmerkung:''' Die Grafik repräsentiert den Analysestand vom TT. MMM 20JJ.\n")
ofile.write('{{-stop-}}\n')
ofile.close()
def parseArgs():
# Parse command line arguments
if len (sys.argv) < 7:
print ("[Usage: python3 makeHNR.py -pubyear:2006 -startpage:1 -endpage:100 -bcstartpage:-10 -bcendpage:120 -target:Xxx]")
for arg in sys.argv:
if arg.startswith("-target:"):
config.target = arg[len('-target:'):]
elif arg.startswith("-startpage:"):
config.startpage = int(arg[len('-startpage:'):])
elif arg.startswith("-endpage:"):
config.endpage = int(arg[len('-endpage:'):])
elif arg.startswith("-bcstartpage:"):
config.bcstartpage = int(arg[len('-bcstartpage:'):])
elif arg.startswith("-bcendpage:"):
config.bcendpage = int(arg[len('-bcendpage:'):])
elif arg.startswith("-pubyear:"):
config.pubyear = int(arg[len('-pubyear:'):])
if __name__ == "__main__":
parseArgs()
files()
run()
Zum Inhalt springen
41.015
Seiten