2023-11-21 15:54:48 +05:00
|
|
|
|
import csv
|
2023-11-22 11:51:22 +05:00
|
|
|
|
import json
|
2023-11-23 00:11:49 +05:00
|
|
|
|
import os
|
|
|
|
|
import sys
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
2023-11-23 00:11:49 +05:00
|
|
|
|
|
|
|
|
|
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')
|
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
|
|
|
|
|
2023-11-23 00:11:49 +05:00
|
|
|
|
for item in data["data"]:
|
|
|
|
|
assignee = item["assignee"]
|
|
|
|
|
followers = item["followers"]
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
|
|
|
|
if assignee:
|
2023-11-23 00:11:49 +05:00
|
|
|
|
unique_names.add(assignee["name"])
|
|
|
|
|
unique_ids.add(assignee["gid"])
|
2023-11-22 00:23:37 +05:00
|
|
|
|
|
|
|
|
|
if followers:
|
|
|
|
|
for follower in followers:
|
2023-11-23 00:11:49 +05:00
|
|
|
|
unique_names.add(follower["name"])
|
|
|
|
|
unique_ids.add(follower["gid"])
|
2023-11-22 00:23:37 +05:00
|
|
|
|
|
|
|
|
|
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):
|
2023-11-23 21:44:55 +05:00
|
|
|
|
with open("users.mapping.asana2ya.csv", "w", newline="") as csvfile:
|
2023-11-22 00:23:37 +05:00
|
|
|
|
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-23 00:11:49 +05:00
|
|
|
|
file = open(asana_data_json, "r", encoding="utf8")
|
|
|
|
|
json_data = json.loads(file.read())
|
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)
|