]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/blob - scripts/update_wrsledrunjsoncache.py
VAO is missing important streets in Switzerland.
[philipp/winterrodeln/wrpylib.git] / scripts / update_wrsledrunjsoncache.py
1 #!/usr/bin/python3
2 """Updates the wrsledrunjsoncache table (by calling wrpylib.wrmwcache.update_wrsledrunjsoncache()).
3
4 Command line usage:
5 $ python updatewrsledrunjsoncache.py inifile1.ini ...
6
7 One or more .ini configuration files can be given.
8 At the end, the following entries have to be present:
9
10     [mysql]
11     host=localhost
12     dbname=philipp_winterrodeln_wiki
13     user_name=philipp_www
14     user_pass=YYYYYY
15
16     [robot]
17     wikiurl=https://www.winterrodeln.org/mediawiki/api.php
18 """
19 import argparse
20 import configparser
21 import urllib.parse
22 from sqlalchemy.engine import create_engine
23 import wrpylib.wrmwcache
24
25
26 def update_wrsledrunjsoncache(inifile):
27     """
28     :param inifile: filename of an .ini file or a list of .ini files.
29     """
30     config = configparser.ConfigParser()
31     config.read(inifile)
32
33     host = config.get('mysql', 'host')
34     dbname = config.get('mysql', 'dbname')
35     user = config.get('mysql', 'user_name')
36     passwd = config.get('mysql', 'user_pass')
37
38     engine = create_engine(f'mysql://{user}@{host}:3306/{dbname}?passwd={passwd}&charset=utf8mb4')
39     api_url = urllib.parse.urlparse(config.get('robot', 'wikiurl'))
40     wrpylib.wrmwcache.update_wrsledrunjsoncache(api_url, engine.connect())
41
42
43 if __name__ == '__main__':
44     parser = argparse.ArgumentParser(description='Updates the wrsledrunjsoncache table.')
45     parser.add_argument('inifile', nargs='+', help='inifile.ini, see: https://www.winterrodeln.org/trac/wiki/ConfigIni')
46     args = parser.parse_args()
47     update_wrsledrunjsoncache(args.inifile)