Mapping_ya_tracker/asana_users.py

44 lines
1.1 KiB
Python
Raw Normal View History

import json
import csv
asana_data = './data/data_asana.json'
def extract_unique_names_and_ids(data):
""" Получение из json-файла данных о пользователях """
unique_names = set()
unique_ids = set()
for item in data:
assignee = item.get("assignee")
followers = item.get("followers")
if assignee:
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
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"])
for name, id in zip(unique_names, unique_ids):
writer.writerow([name, id])
with open('asana_data', 'r') as file:
json_data = json.load(file)
unique_names, unique_ids = extract_unique_names_and_ids(json_data)
export_to_csv(unique_names, unique_ids)