Create module wrdem and script get_elevation.
[philipp/winterrodeln/wrpylib.git] / scripts / updatewrinncache.py
1 #!/usr/bin/python3
2 """Updates the wrinncache table (by calling wrpylib.wrmwcache.update_wrinncache()).
3 Can be used in a python session or at the command line.
4
5 Command line usage:
6 $ python updatewrinncache.py inifile1.ini ...
7
8 One or more .ini configuration files can be given.
9 At the end, the following entries have to be present:
10
11     [mysql]
12     host=localhost
13     dbname=philipp_winterrodeln_wiki
14     user_name=philipp_www
15     user_pass=YYYYYY
16 """
17 import argparse
18 import configparser
19 from sqlalchemy.engine import create_engine
20 import wrpylib.wrmwcache
21
22
23 def update_wrinncache(inifile):
24     """
25     :param inifile: filename of an .ini file or a list of .ini files.
26     """
27     config = configparser.ConfigParser()
28     config.read(inifile)
29
30     host = config.get('mysql', 'host')
31     dbname = config.get('mysql', 'dbname')
32     user = config.get('mysql', 'user_name')
33     passwd = config.get('mysql', 'user_pass')
34
35     engine = create_engine(f'mysql://{user}@{host}:3306/{dbname}?passwd={passwd}&charset=utf8mb4')
36     wrpylib.wrmwcache.update_wrinncache(engine.connect())
37
38
39 if __name__ == '__main__':
40     parser = argparse.ArgumentParser(description='Updates the wrinncache table.')
41     parser.add_argument('inifile', nargs='+', help='inifile.ini, see: https://www.winterrodeln.org/trac/wiki/ConfigIni')
42     args = parser.parse_args()
43     update_wrinncache(args.inifile)