annotate doc/collect_demo3.py @ 34:916fa83b4144

Clean up repository. 'Update README.creole' * /doc added for the old demos. * Added comments to config.ini.
author Magnus Schieder <mschieder@intevation.de>
date Mon, 26 Nov 2018 16:08:27 +0100
parents examples/collect_demo3.py@7a523e13fcb3
children
rev   line source
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python3
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
2 """Connect to roundup-tracker and save status to db for example demo1.
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
3
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
4 Run periodically as often as you want data points to be saved.
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
5 demo1 only tracks issues with a priority.
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
6 """
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
7
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
8 import json
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
9 import configparser
21
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
10 import argparse
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
11
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
12 from collect_issues import save_stats_in_db
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
13 import roundup_content_data as rcd
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
14
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
15 COLUMNS = "critical, urgent, bug, feature, wish"
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
16
21
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
17 parser = argparse.ArgumentParser()
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
18 parser.add_argument("config_file", type=str, metavar="[config file]")
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
19 args = parser.parse_args()
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
20
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
21 config = configparser.ConfigParser()
21
7a523e13fcb3 Argpars added for the configuration file.
Magnus Schieder <mschieder@intevation.de>
parents: 20
diff changeset
22 config.read(args.config_file)
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
23
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
24 base_url = config.get("URL", "BaseURL")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
25
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
26 user = config.get("LOGIN","Username")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
27 password = config.get("LOGIN", "Password")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
28
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
29 LOGIN_PARAMETERS_DEMO = (
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
30 ("__login_name", user),
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
31 ("__login_password", password),
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
32 ("@action", "Login"),
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
33 )
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
34
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
35 database_file = config.get("DB", "DatabaseFile")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
36
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
37 keywords = config.get("SEARCH", "Keywords", fallback="").split(", ")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
38
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
39 list_of_columns = config.get("SEARCH", "Columns", fallback=COLUMNS).split(", ")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
40
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
41 status = config.get("SEARCH", "Status", fallback="").split(", ")
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
42
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
43 include_no_prio = config.getboolean("SEARCH", "IncludeNoPrio", fallback= False)
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
44
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
45 if include_no_prio:
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
46 list_of_columns += ["None"]
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
47
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
48 select_all, select_where, create_db, insert_new = \
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
49 rcd.build_sql_commands(list_of_columns)
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
50
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
51 save_stats_in_db(LOGIN_PARAMETERS_DEMO, base_url, database_file,
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
52 list_of_columns, create_db, insert_new, keywords, status)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)