Mapping_ya_tracker/asana_users.py
2023-11-27 21:22:57 +05:00

48 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import csv
import json
import os
import sys
base_dir = os.path.dirname(os.path.realpath(__file__))
asana_data_json = os.path.join(base_dir, './data/data_asana.json')
sys.stdout.reconfigure(encoding='utf-8')
def extract_unique_names_and_ids(data):
""" Получение из json-файла данных о пользователях """
unique_names = set()
unique_ids = set()
for item in data["data"]:
assignee = item["assignee"]
followers = item["followers"]
if assignee:
unique_names.add(assignee["name"])
unique_ids.add(assignee["gid"])
if followers:
for follower in followers:
unique_names.add(follower["name"])
unique_ids.add(follower["gid"])
return unique_names, unique_ids
def export_to_csv(unique_names, unique_ids):
with open("users.mapping.asana2ya.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])
file = open(asana_data_json, "r", encoding="utf8")
json_data = json.loads(file.read())
unique_names, unique_ids = extract_unique_names_and_ids(json_data)
export_to_csv(unique_names, unique_ids)