01a05c045d
first iteration on data["data"]/Users/angelinatingaeva/HEADO_1/Mapping_ya_tracker/venv/bin/python /Users/angelinatingaeva/HEADO_1/Mapping_ya_tracker/mapping.py /- -.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
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)
|