2023-11-07 16:57:58 -05:00
|
|
|
import pprint
|
2024-01-05 17:07:59 -05:00
|
|
|
import csv
|
2023-05-17 12:30:27 -04:00
|
|
|
import requests
|
|
|
|
|
import Apikeys
|
2024-02-21 18:55:26 -05:00
|
|
|
import json
|
|
|
|
|
|
2023-05-17 12:30:27 -04:00
|
|
|
|
2024-05-30 17:26:35 -04:00
|
|
|
APIKEY = Apikeys.ANTHOLOGY
|
2023-05-17 12:30:27 -04:00
|
|
|
groups_dict = {}
|
2023-11-07 16:57:58 -05:00
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
2023-05-17 12:30:27 -04:00
|
|
|
|
|
|
|
|
|
2023-11-07 16:57:58 -05:00
|
|
|
def get_groups(APIKEY):
|
2023-05-17 12:30:27 -04:00
|
|
|
count = 0
|
|
|
|
|
groups = []
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
count += 1
|
|
|
|
|
url = f"https://api.northpass.com/v2/groups?page={count}"
|
2023-11-07 16:57:58 -05:00
|
|
|
headers = {"accept": "application/json", "X-Api-Key": APIKEY}
|
2023-05-17 12:30:27 -04:00
|
|
|
response = requests.get(url, headers=headers)
|
|
|
|
|
data = response.json()
|
|
|
|
|
nextlink = data["links"]
|
|
|
|
|
|
|
|
|
|
for response in data["data"]:
|
2024-01-04 16:51:28 -05:00
|
|
|
# created_at = response["attributes"]["created_at"]
|
|
|
|
|
# if created_at.startswith("2023"):
|
|
|
|
|
group_id = response["id"]
|
|
|
|
|
group_name = response["attributes"]["name"]
|
|
|
|
|
# print(group_name)
|
2024-01-05 17:07:59 -05:00
|
|
|
groups_dict = {group_name: group_id}
|
2024-01-04 16:51:28 -05:00
|
|
|
groups.append(groups_dict)
|
2023-05-17 12:30:27 -04:00
|
|
|
|
|
|
|
|
if "next" not in nextlink:
|
|
|
|
|
break
|
2024-04-18 18:57:55 -04:00
|
|
|
print(groups)
|
2023-05-17 12:30:27 -04:00
|
|
|
|
2024-01-05 17:07:59 -05:00
|
|
|
with open(
|
2024-05-30 17:26:35 -04:00
|
|
|
"/Users/normrasmussen/Downloads/Anthology-Groups.csv", "a+", newline="\n"
|
2024-01-05 17:07:59 -05:00
|
|
|
) as csvfile:
|
|
|
|
|
for group in groups:
|
|
|
|
|
for key, value in group.items():
|
|
|
|
|
csvwriter = csv.writer(csvfile)
|
|
|
|
|
csvwriter.writerow([key, value])
|
2023-05-17 12:30:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-11-07 16:57:58 -05:00
|
|
|
get_groups(APIKEY)
|