Exports a single table query result into a csv file.
(self, query_result, output_fp=None, output_fn=None)
| 1213 | return output_dict |
| 1214 | |
| 1215 | def export_one_table_to_csv(self, query_result, output_fp=None, output_fn=None): |
| 1216 | |
| 1217 | """ Exports a single table query result into a csv file. """ |
| 1218 | |
| 1219 | table = query_result["table"] |
| 1220 | |
| 1221 | output = [] |
| 1222 | |
| 1223 | table_raw = table |
| 1224 | rows = table_raw.split("<tr>") |
| 1225 | cols_tracker = [] |
| 1226 | coords_master = [] |
| 1227 | |
| 1228 | for row in rows: |
| 1229 | |
| 1230 | new_row = [] |
| 1231 | if row.strip().endswith("</tr>"): |
| 1232 | row = row.strip()[:-5] |
| 1233 | |
| 1234 | cells = row.lstrip().split("<th>") |
| 1235 | cols_count = 0 |
| 1236 | coords = [] |
| 1237 | |
| 1238 | for c in cells: |
| 1239 | |
| 1240 | if c.strip().endswith("</th>"): |
| 1241 | c = c.strip()[:-5] |
| 1242 | |
| 1243 | clean_cell = "" |
| 1244 | bracket_on = 0 |
| 1245 | |
| 1246 | fields = c.split("<") |
| 1247 | |
| 1248 | if fields[0]: |
| 1249 | index = fields[1].rstrip()[0:-1] |
| 1250 | main_entry = fields[2].split(">") |
| 1251 | value = main_entry[-1] |
| 1252 | co = main_entry[0].split(" ") |
| 1253 | if len(co) > 2: |
| 1254 | x = co[1] |
| 1255 | y = co[2] |
| 1256 | coords.append((int(x), int(y))) |
| 1257 | |
| 1258 | for c1 in c: |
| 1259 | if bracket_on == 0 and c1 not in ("<", ">"): |
| 1260 | clean_cell += c1 |
| 1261 | if c1 == "<": |
| 1262 | bracket_on = 1 |
| 1263 | if c1 == ">": |
| 1264 | bracket_on = 0 |
| 1265 | |
| 1266 | if c: |
| 1267 | c_strip = c.split(">")[-1] |
| 1268 | new_row.append(c_strip.strip()) |
| 1269 | cols_count += 1 |
| 1270 | coords_master.append(coords) |
| 1271 | cols_tracker.append(cols_count) |
| 1272 | output.append(new_row) |
no test coverage detected