2023-11-21 15:54:48 +05:00
|
|
|
|
import csv
|
2023-11-22 11:51:22 +05:00
|
|
|
|
import json
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
asana_data = './data/data_asana.json'
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
def extract_unique_names_and_ids(data):
|
2023-11-21 15:54:48 +05:00
|
|
|
|
""" Получение из json-файла данных о пользователях """
|
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
unique_names = set()
|
|
|
|
|
unique_ids = set()
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
|
|
|
|
for item in data:
|
2023-11-22 00:23:37 +05:00
|
|
|
|
assignee = item.get("assignee")
|
|
|
|
|
followers = item.get("followers")
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
|
|
|
|
if assignee:
|
2023-11-22 00:23:37 +05:00
|
|
|
|
unique_names.add(assignee.get("name"))
|
|
|
|
|
unique_ids.add(assignee.get("id"))
|
|
|
|
|
|
|
|
|
|
if followers:
|
|
|
|
|
for follower in followers:
|
|
|
|
|
unique_names.add(follower.get("name"))
|
|
|
|
|
unique_ids.add(follower.get("id"))
|
|
|
|
|
|
|
|
|
|
return unique_names, unique_ids
|
|
|
|
|
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
def export_to_csv(unique_names, unique_ids):
|
|
|
|
|
with open("output.csv", "w", newline="") as csvfile:
|
|
|
|
|
writer = csv.writer(csvfile, delimiter=",")
|
|
|
|
|
writer.writerow(["Name", "ID"])
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
for name, id in zip(unique_names, unique_ids):
|
|
|
|
|
writer.writerow([name, id])
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
with open('asana_data', 'r') as file:
|
|
|
|
|
json_data = json.load(file)
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
2023-11-22 00:23:37 +05:00
|
|
|
|
unique_names, unique_ids = extract_unique_names_and_ids(json_data)
|
|
|
|
|
export_to_csv(unique_names, unique_ids)
|