Mercurial > roundup-cc
comparison collect_issues.py @ 32:80bbd06fe8ec
Add Comments
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Fri, 23 Nov 2018 16:13:24 +0100 |
parents | 9aca070c86bd |
children | 946b9f458fcc |
comparison
equal
deleted
inserted
replaced
31:9aca070c86bd | 32:80bbd06fe8ec |
---|---|
2 """ Fetch issues from a roundup-tracker and save them in a databse. | 2 """ Fetch issues from a roundup-tracker and save them in a databse. |
3 | 3 |
4 author: Sascha L. Teichmann <sascha.teichmann@intevation.de> | 4 author: Sascha L. Teichmann <sascha.teichmann@intevation.de> |
5 author: Bernhard Reiter <bernhard@intevation.de> | 5 author: Bernhard Reiter <bernhard@intevation.de> |
6 author: Sean Engelhardt <sean.engelhardt@intevation.de> | 6 author: Sean Engelhardt <sean.engelhardt@intevation.de> |
7 | 7 author: Magnus Schieder <magnus.schieder@intevation.de> |
8 (c) 2010, 2015, 2018 by Intevation GmbH | 8 (c) 2010, 2015, 2018 by Intevation GmbH |
9 | 9 |
10 This is Free Software unter the terms of the | 10 This is Free Software unter the terms of the |
11 GNU GENERAL PUBLIC LICENSE Version 3 or later. | 11 GNU GENERAL PUBLIC LICENSE Version 3 or later. |
12 See http://www.gnu.org/licenses/gpl-3.0.txt for details | 12 See http://www.gnu.org/licenses/gpl-3.0.txt for details |
26 | 26 |
27 # Getting keywords and their ids. | 27 # Getting keywords and their ids. |
28 CHECK_KEYWORD_VALUES = "keyword?@action=export_csv&@columns=id,name" | 28 CHECK_KEYWORD_VALUES = "keyword?@action=export_csv&@columns=id,name" |
29 # Getting states and their ids. | 29 # Getting states and their ids. |
30 CHECK_STATUS_VALUES = "status?@action=export_csv&@columns=id,name" | 30 CHECK_STATUS_VALUES = "status?@action=export_csv&@columns=id,name" |
31 # Getting priority and their ids. | 31 # Getting priorities and their ids. |
32 CHECK_PRIO_VALUES = "priority?@action=export_csv&@columns=id,name" | 32 CHECK_PRIO_VALUES = "priority?@action=export_csv&@columns=id,name" |
33 | 33 |
34 # Getting the priority of each issue with the filter status ,keywords ,priority | 34 # Getting the priority of each issue with the filter status, keyword ,priority |
35 SEARCH_ROUNDUP_PRIO = "issue?@action=export_csv&@columns=priority&@filter=status,keyword,priority&@pagesize=500&@startwith=0&status={status_values}&keyword={keyword_values}&priority={priority_values}" | 35 SEARCH_ROUNDUP_PRIO = "issue?@action=export_csv&@columns=priority&@filter=status,keyword,priority&@pagesize=500&@startwith=0&status={status_values}&keyword={keyword_values}&priority={priority_values}" |
36 # Getting the status of each issue with the filter keywords, status | 36 # Getting the status of each issue with the filter keyword, priority, status |
37 SEARCH_ROUNDUP_STATUS = "issue?@action=export_csv&@columns=status&@filter=priority,keyword,status&@pagesize=500&@startwith=0&priority={priority_values}&keyword={keyword_values}&status={status_values}" | 37 SEARCH_ROUNDUP_STATUS = "issue?@action=export_csv&@columns=status&@filter=priority,keyword,status&@pagesize=500&@startwith=0&priority={priority_values}&keyword={keyword_values}&status={status_values}" |
38 | 38 |
39 | 39 |
40 def connect_to_server(params, baseurl): | 40 def connect_to_server(params, baseurl): |
41 enc_data = urllib.parse.urlencode(params).encode() | 41 enc_data = urllib.parse.urlencode(params).encode() |
72 cur.close() | 72 cur.close() |
73 if con: | 73 if con: |
74 con.close() | 74 con.close() |
75 | 75 |
76 def get_ids(opener, baseurl, parameter, url, include_no_prio=False): | 76 def get_ids(opener, baseurl, parameter, url, include_no_prio=False): |
77 """Returns the IDs of the respective search parameters as string and list. | |
78 """ | |
79 | |
77 if parameter == [""]: | 80 if parameter == [""]: |
78 return ("", []) | 81 return ("", []) |
79 | 82 |
80 parameter_csv = get_csv_from_server(opener, baseurl, url) | 83 parameter_csv = get_csv_from_server(opener, baseurl, url) |
81 parameter_dict = {} | 84 parameter_dict = {} |
97 | 100 |
98 | 101 |
99 def issues_to_quantities(issue_csv, columns_ids): | 102 def issues_to_quantities(issue_csv, columns_ids): |
100 """Count issues per priority. | 103 """Count issues per priority. |
101 | 104 |
102 Returns: a list of ints, containing how often a prio occurred [:-1] | 105 Returns: a list of ints, containing how often a prio/status occurred |
103 in order of the priorities, with the last being the "None" prio | 106 in the order in which they are specified in the config. |
104 """ | 107 """ |
105 | 108 |
106 order_dict = {} | 109 order_dict = {} |
107 z = 0 | 110 z = 0 |
108 for x in columns_ids: | 111 for x in columns_ids: |
115 priority = issue[issue_csv.fieldnames[0]] | 118 priority = issue[issue_csv.fieldnames[0]] |
116 | 119 |
117 if priority in order_dict: | 120 if priority in order_dict: |
118 if priority.isdigit() == True : | 121 if priority.isdigit() == True : |
119 quantities[order_dict[priority]] += 1 | 122 quantities[order_dict[priority]] += 1 |
120 else: | 123 else: # no priority set |
121 quantities[-1] += 1 | 124 quantities[-1] += 1 |
122 #print("quantities : " + str(quantities)) | 125 #print("quantities : " + str(quantities)) |
123 | 126 |
124 return quantities | 127 return quantities |
125 | 128 |
153 | 156 |
154 keywords_ids_url, _ = get_ids(opener, baseurl, keywords, | 157 keywords_ids_url, _ = get_ids(opener, baseurl, keywords, |
155 CHECK_KEYWORD_VALUES) | 158 CHECK_KEYWORD_VALUES) |
156 | 159 |
157 if search == "prio": | 160 if search == "prio": |
158 # search_parameters are statuses. | 161 # search_parameters are states. |
159 status_ids_url, _ = get_ids(opener, baseurl,search_parameters , | 162 status_ids_url, _ = get_ids(opener, baseurl,search_parameters , |
160 CHECK_STATUS_VALUES, include_no_prio) | 163 CHECK_STATUS_VALUES, include_no_prio) |
161 prio_ids_url, columns_ids = get_ids(opener, baseurl, columns, | 164 prio_ids_url, columns_ids = get_ids(opener, baseurl, columns, |
162 CHECK_PRIO_VALUES, include_no_prio) | 165 CHECK_PRIO_VALUES, include_no_prio) |
163 formated_search_url = SEARCH_ROUNDUP_PRIO.format( | 166 formated_search_url = SEARCH_ROUNDUP_PRIO.format( |
178 | 181 |
179 current_issues_csv = get_csv_from_server(opener, baseurl, | 182 current_issues_csv = get_csv_from_server(opener, baseurl, |
180 formated_search_url) | 183 formated_search_url) |
181 | 184 |
182 opener.close() | 185 opener.close() |
183 print(baseurl + formated_search_url) | 186 #print(baseurl + formated_search_url) |
184 | 187 |
185 quantities = issues_to_quantities(current_issues_csv, columns_ids) | 188 quantities = issues_to_quantities(current_issues_csv, columns_ids) |
186 | 189 |
187 save_issues_to_db(quantities, db_file, sql_create_db, sql_insert_in_db) | 190 save_issues_to_db(quantities, db_file, sql_create_db, sql_insert_in_db) |
188 | 191 |