From 1f8ba6b5f15862ad63a65740e40665820515841d Mon Sep 17 00:00:00 2001 From: Mathieu Loiseau <mathieu.loiseau@liris.cnrs.fr> Date: Sat, 30 Sep 2023 23:44:38 +0200 Subject: [PATCH] =?UTF-8?q?log.sqlite=20param=C3=A9trable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 ++++++++++++--- requirements.txt | 2 +- wikstraktor.py | 14 ++++++++++---- wikstraktor.sqlite | Bin 32768 -> 36864 bytes 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3b52a76..f6916ed 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,14 @@ str(f) #convert content to json #### Bash ``` usage: wikstraktor.py [-h] [-l LANGUAGE] [-w WIKI_LANGUAGE] [-m MOT] - [-f DESTINATION_FILE] [-A] [-C] + [-f DESTINATION_FILE] [-A] [-C] [-n] [-r] [-L LOG_FILE] Interroger un wiktionnaire ex : ‣./wikstraktor.py -m blue - ‣./wikstraktor.py -m blue -f blue.json -A -C - ‣./wikstraktor.py -l en -w fr -m blue -f blue.json -A -C + ‣./wikstraktor.py -m blue -f blue.json -AC + ‣./wikstraktor.py -l en -w fr -m yellow -L /var/log/wikstraktor.sqlite + ‣./wikstraktor.py -l en -w fr -m blue -f blue.json -n -ACr options: -h, --help show this help message and exit @@ -75,6 +76,14 @@ options: le fichier dans lequel stocker le résultat -A, --force_ascii json avec que des caractères ascii -C, --compact json sans indentation + -n, --no_id json sans id + -r, --follow_redirections + pour suivre les redirections (ex: did → do) + -L LOG_FILE, --log_file LOG_FILE + le fichier sqlite où stocker les log + (bien vérifier que l'utilisateur qui lance le script a + accès en écriture à ce fichier + et au dossier qui le contient) ``` ### Wikstraktor Server diff --git a/requirements.txt b/requirements.txt index 9a6b3d4..89d5182 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ #necessary pywikibot>=8.1.2 wikitextparser>=0.51.0 -importlib>=1.0.4 +#importlib>=1.0.4 provided by default #for setup script GitPython==3.1.31 diff --git a/wikstraktor.py b/wikstraktor.py index 35dfe17..27d43be 100755 --- a/wikstraktor.py +++ b/wikstraktor.py @@ -534,12 +534,12 @@ class ParserContext: class Wikstraktor: @classmethod - def get_instance(cls, wiki_language, entry_language): + def get_instance(cls, wiki_language, entry_language, logfile="wikstraktor.sqlite"): try: m_name = f"{wiki_language}_{entry_language}".capitalize() instance = getattr(importlib.import_module(f"parsers.{m_name.lower()}"), f"{m_name}_straktor")() instance.version = the_version - instance.log = Wikstraklog(the_version, entry_language, wiki_language) + instance.log = Wikstraklog(the_version, entry_language, wiki_language, logfile) except ModuleNotFoundError: print(f"parsers.{m_name.lower()} module not found or {m_name}_straktor not found in module") instance = None @@ -769,7 +769,8 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description="""Interroger un wiktionnaire \033[1m\033[32mex :\033[0m ‣\033[0m\033[32m./wikstraktor.py -m blue\033[0m - ‣\033[0m\033[32m./wikstraktor.py -m blue -f blue.json -A -C\033[0m + ‣\033[0m\033[32m./wikstraktor.py -m blue -f blue.json -AC\033[0m + ‣\033[0m\033[32m./wikstraktor.py -l en -w fr -m yellow -L /var/log/wikstraktor.sqlite\033[0m ‣\033[0m\033[32m./wikstraktor.py -l en -w fr -m blue -f blue.json -n -ACr\033[0m""") parser.add_argument("-l", "--language", help="la langue du mot", type=str, default = "en") parser.add_argument("-w", "--wiki_language", help="la langue du wiki", type=str, default = "en") @@ -779,10 +780,15 @@ if __name__ == "__main__": parser.add_argument("-C", "--compact", help="json sans indentation", action="store_true") parser.add_argument("-n", "--no_id", help="json sans id", action="store_true") parser.add_argument("-r", "--follow_redirections", help="pour suivre les redirections (ex: did → do)", action="store_true") + parser.add_argument("-L", "--log_file", help="le fichier sqlite où stocker les log\n(bien vérifier que l'utilisateur qui lance le script a\naccès en écriture à ce fichier\net au dossier qui le contient)", type=str, default=None) + args = parser.parse_args() if args.mot != None: - w = Wikstraktor.get_instance(args.wiki_language, args.language) + if args.log_file != None: + w = Wikstraktor.get_instance(args.wiki_language, args.language, args.log_file) + else: + w = Wikstraktor.get_instance(args.wiki_language, args.language) resp = None if w.fetch(args.mot, args.follow_redirections) > 0: resp = w.export(not args.no_id, args.force_ascii, args.compact) diff --git a/wikstraktor.sqlite b/wikstraktor.sqlite index 660ec27727267941a1d46949f21b24669ef6d801..92143d2d1b070c712a39af7d177eb677f90613f7 100644 GIT binary patch delta 2367 zcmZo@U}{*vG(noRj)8%JbE1MhW8KDtCHx|6{EvVF44nMG`M>dh<bT8eod3~gMS+w2 z69ZV7IPy0?mzNDt6J+?uz%R~c%<ILI#$C%blXC;d8TQ9)|JlS?jaWRHGnncaZ!-Lw zSa>C*F(RMKI95<ll*O|#-pIhnSl7T(*T_u4(A3J*)XLZ}$;j9&IVH)!)XX%^!r0it zFww%u)WpOfDapvdEXB;sA|=hxB+W7@H7_-<D8D$BrHe~x@<B5#*S!4ln&kYPoczMl z%*33U#JrT6y!^c45+Eb7D5bVmp}M*tvA9H`AhD<<GdZ&$CsiRottK_ErYN&G6{s{h zvBcJJa-q6pkWwBe)P<$gbD)Y?W?otjvXwQ(AoqZ53{KC5hDm5+A+@Yjtkjtt7sSg~ zlwV$4Q<R?yBr@`gCqGQqVl<sRF-$c$E(dNY)gnT%QhTyN6*tGsQ(aXx#lY|cS!V*W zjwvmBaznMmWZ%+Mpo;9xCZ%V%RCs|2i;ram1HS@a7H=odeC}V|@?7?uog6FJ_pwW| z*|Em4tk_uC!V=PGTnkS%qOcG$Hc&7!v@$lg0;Ud9QVlS^S=#=7pIm5eAeEM1lnalP z<kXt<oc!Wq+miCkba2GP*1*FkmRi<A!ib9_@#HE*7+Hd&B%&JbOL&yPeQ9h-k}qkL zH>xo52IUUKpEoMuQ2@^ylv+tRZ&bi7rCLPb&KtqT<?wiir*3$eXiB@(T?Y3hJatoQ zExy!U3il;EP~p~@42slUf|0r@cOd@MT?~%`c<QFqO2VnT2yQ9WA_8CPE`-NBX6iOJ XBB@j(rR*+%`w}yClW8r^)U5&lZhFjo delta 111 zcmV-#0FeKHpaOt^0+1U8YybcN2$3K^0c^2gqz@7W59a^?000ON`w#XH@ek||=d&RY z#1D~x5VPtZ8c-e$1W5o77Y;KGN(^QTeF~Wgun5ct;|Bi*76mc{NwIM!1OtI)Ym<O` R7?VwPWs@*^YqK<U%nB0=B1ixL -- GitLab