comparison collect_issues.py @ 20:3bb3d9a9f1b7

Filter by keywords and states. Configuration via configuration file. "No prio" grapf is displayed. (./display_issues_demo.py is not yet dynamic, it needs all states)
author Magnus Schieder <mschieder@intevation.de>
date Mon, 22 Oct 2018 16:49:58 +0200
parents adca5b3780d2
children 10167e40a657 7161ce4e7ab1
comparison
equal deleted inserted replaced
19:8ffd584065a4 20:3bb3d9a9f1b7
22 import sqlite3 as db 22 import sqlite3 as db
23 import os 23 import os
24 24
25 25
26 CHECK_ROUNDUP_ORDER = "priority?@action=export_csv&@columns=id,order" 26 CHECK_ROUNDUP_ORDER = "priority?@action=export_csv&@columns=id,order"
27 CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id&@filter=open&open=1" 27 CHECK_KEYWORD_ORDER = "keyword?@action=export_csv&@columns=id,name"
28 SEARCH_ROUNDUP = "issue?@action=export_csv&@columns=priority&@filter=status&@pagesize=500&@startwith=0&status=-1,{search_values}" 28 CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id,name&@filter=open&open=1"
29 SEARCH_ROUNDUP = "issue?@action=export_csv&@columns=priority&@filter=status,keyword&@pagesize=500&@startwith=0&status={search_values}&keyword={keyword_values}"
29 30
30 31
31 def connect_to_server(params, baseurl): 32 def connect_to_server(params, baseurl):
32 enc_data = urllib.parse.urlencode(params).encode() 33 enc_data = urllib.parse.urlencode(params).encode()
33 cj = http.cookiejar.CookieJar() 34 cj = http.cookiejar.CookieJar()
40 def get_csv_from_server(opener, roundup_url, sub_url): 41 def get_csv_from_server(opener, roundup_url, sub_url):
41 csv_req = urllib.request.Request(url=roundup_url+sub_url) 42 csv_req = urllib.request.Request(url=roundup_url+sub_url)
42 f = opener.open(csv_req) 43 f = opener.open(csv_req)
43 csv_reader = csv.DictReader(io.TextIOWrapper(f)) 44 csv_reader = csv.DictReader(io.TextIOWrapper(f))
44 return csv_reader 45 return csv_reader
45
46
47 def set_search_paramters_on_URL(url, search_param_csv):
48
49 id_list = []
50
51 for row in search_param_csv:
52 id_list.append(row["id"])
53
54 new_url = url.format(search_values = ",".join(id_list))
55
56 return new_url
57 46
58 47
59 def check_create_database(database_file, sql_create_db): 48 def check_create_database(database_file, sql_create_db):
60 if not os.path.isfile(database_file): 49 if not os.path.isfile(database_file):
61 con = None 50 con = None
73 finally: 62 finally:
74 if cur: 63 if cur:
75 cur.close() 64 cur.close()
76 if con: 65 if con:
77 con.close() 66 con.close()
67
68 def get_keyword_ids(opener, baseurl, keywords):
69 if keywords == [""]:
70 return ""
71
72 keywords_csv = get_csv_from_server(opener, baseurl, CHECK_KEYWORD_ORDER)
73 keywords_dict = {}
74 for x in keywords_csv:
75 keywords_dict[x["name"]] = x["id"]
76
77 keywords_ids = []
78 for x in keywords:
79 keywords_ids.append(keywords_dict[x])
80
81 return ",".join(keywords_ids)
82
83 def get_status_ids(opener, baseurl, status):
84
85 status_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES)
86
87 if status == [""]:
88 return ""
89
90 status_dict = {}
91 for x in status_csv:
92 status_dict[x["name"]] = x["id"]
93
94 staus_ids = ["-1"]
95 for x in status:
96 staus_ids.append(status_dict[x])
97
98 return ",".join(staus_ids)
78 99
79 100
80 def issues_to_quantities(issue_csv, columns, orders_csv): 101 def issues_to_quantities(issue_csv, columns, orders_csv):
81 """Count issues per priority. 102 """Count issues per priority.
82 103
124 cur.close() 145 cur.close()
125 if con: 146 if con:
126 con.close() 147 con.close()
127 148
128 149
129 def save_stats_in_db(login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, searchurl=False, include_no_prio=False): 150 def save_stats_in_db(login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, keywords, status, include_no_prio=False):
130 try: 151 try:
131 152
132 opener = connect_to_server(login_parmeters, baseurl) 153 opener = connect_to_server(login_parmeters, baseurl)
133 154
134 search_operators_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES)
135 order_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_ORDER) 155 order_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_ORDER)
136 156
137 if searchurl == False: 157 keywords_ids_url = get_keyword_ids(opener, baseurl, keywords)
138 formated_search_url = set_search_paramters_on_URL(SEARCH_ROUNDUP, search_operators_csv) 158
139 else: 159 status_ids_url = get_status_ids(opener, baseurl, status)
140 formated_search_url = searchurl 160 formated_search_url = SEARCH_ROUNDUP.format(search_values=status_ids_url, keyword_values=keywords_ids_url)
141 161
142 current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url) 162 current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url)
143 163
144 opener.close() 164 opener.close()
145 165
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)