Backed up BuilderTrend's templates.
This commit is contained in:
@ -3,8 +3,8 @@ import os
|
||||
import Apikeys
|
||||
import requests
|
||||
|
||||
apikey = Apikeys.WALMARTPROD
|
||||
cmd = "touch ~/Downloads/Spark_Categories.csv"
|
||||
apikey = Apikeys.SUPPLIERPROD
|
||||
cmd = "touch ~/Downloads/Supplier_Categories.csv"
|
||||
|
||||
os.system(cmd)
|
||||
url = "https://api2.northpass.com/v2/categories?limit=100"
|
||||
@ -18,12 +18,12 @@ response = response.json()
|
||||
for item in response['data']:
|
||||
id = item['id']
|
||||
name = item['attributes']['name']
|
||||
with open('/Users/normrasmussen/Downloads/Spark_Categories.csv', 'a', newline='') as csvfile:
|
||||
with open('/Users/normrasmussen/Downloads/Supplier_Categories.csv', 'a', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
writer.writerow([name, id,])
|
||||
# print(f"Category: {name} and ID: {id}")
|
||||
|
||||
with open('/Users/normrasmussen/Downloads/Spark_Categories.csv', 'r') as readfile:
|
||||
with open('/Users/normrasmussen/Downloads/Supplier_Categories.csv', 'r') as readfile:
|
||||
reader = csv.reader(readfile)
|
||||
for row in reader:
|
||||
print(row)
|
||||
|
||||
@ -21,22 +21,25 @@ def get_course():
|
||||
|
||||
for response in data["data"]:
|
||||
status = response["attributes"]["status"]
|
||||
uuid = response["id"]
|
||||
name = response["attributes"]["name"]
|
||||
course_dict = {
|
||||
"id": uuid,
|
||||
"name": name,
|
||||
"status": status,
|
||||
# "build_url": build_url
|
||||
# "url": f"https://walmart.northpass.com/app/courses/{uuid}",
|
||||
}
|
||||
courses.append(course_dict)
|
||||
if status == "live":
|
||||
uuid = response["id"]
|
||||
name = response["attributes"]["name"]
|
||||
course_dict = {
|
||||
"id": uuid,
|
||||
"name": name,
|
||||
"status": status,
|
||||
# "build_url": build_url
|
||||
# "url": f"https://walmart.northpass.com/app/courses/{uuid}",
|
||||
}
|
||||
courses.append(course_dict)
|
||||
|
||||
# FIX: Up until here, each course gets read to the terminal.
|
||||
# FIX: After this, something is being overwritten.
|
||||
# FIX: Up until here, each course gets read to the terminal.
|
||||
# FIX: After this, something is being overwritten.
|
||||
|
||||
cat_id = response["relationships"]["categories"]["data"]
|
||||
get_cat_name(cat_id, course_dict, courses)
|
||||
cat_id = response["relationships"]["categories"]["data"]
|
||||
print(name)
|
||||
print(cat_id)
|
||||
get_cat_name(cat_id, course_dict, courses)
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
@ -63,14 +66,16 @@ def get_cat_name(cat_id, course_dict, courses):
|
||||
for item in cat_id:
|
||||
categoryid = item["id"]
|
||||
url = f"https://api2.northpass.com/v2/categories/{categoryid}"
|
||||
# print(url)
|
||||
cat_resp = requests.get(url, headers=headers)
|
||||
cat_data = cat_resp.json()
|
||||
# print(cat_data)
|
||||
cat_name = cat_data["data"]["attributes"]["name"]
|
||||
cats.append(cat_name)
|
||||
course_dict.update({"categories": cats})
|
||||
print(course_dict)
|
||||
|
||||
write_to_csv(courses)
|
||||
# write_to_csv(courses)
|
||||
|
||||
|
||||
def write_to_csv(courses):
|
||||
|
||||
Reference in New Issue
Block a user