-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_utils.py
More file actions
43 lines (37 loc) · 1.61 KB
/
export_utils.py
File metadata and controls
43 lines (37 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import csv
import json
from typing import Any
def write_json(path: str, payload: dict[str, Any]) -> None:
with open(path, "w", encoding="utf-8") as handle:
json.dump(payload, handle, indent=2)
def write_clicks_csv(click_rows: list[dict[str, Any]], path: str = "clicks_report.csv") -> int:
with open(path, "w", encoding="utf-8", newline="") as handle:
writer = csv.writer(handle)
writer.writerow(["id", "user_id", "ip", "endpoint", "click_x", "click_y", "trusted", "time"])
for row in click_rows:
writer.writerow([
row.get("id", ""),
row.get("user_id", ""),
row.get("ip", ""),
row.get("endpoint", ""),
row.get("click_x", ""),
row.get("click_y", ""),
row.get("trusted", ""),
row.get("time", ""),
])
return len(click_rows)
def write_logins_csv(login_rows: list[dict[str, Any]], path: str = "logins_report.csv") -> int:
with open(path, "w", encoding="utf-8", newline="") as handle:
writer = csv.writer(handle)
writer.writerow(["id", "user_id", "username_hash", "password_len", "ip", "trusted", "time"])
for row in login_rows:
writer.writerow([
row.get("id", ""),
row.get("user_id", ""),
row.get("username_hash", ""),
row.get("password_len", ""),
row.get("ip", ""),
row.get("trusted", ""),
row.get("time", ""),
])
return len(login_rows)