This repository was archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
vendormanage.py
Jordan Banasik edited this page Nov 19, 2019
·
3 revisions
Returns a list of dictionaries representing vendors
def load_vendors():
with open('config/vendors.json', 'r') as f:
return json.load(f)Takes in a list of dictionaries representing vendors and writes them out to config/vendors.json
def save_vendors(vendors):
with open('config/vendors.json', 'w') as f:
json.dump(vendors, f)Appends a vendor to the config/vendors.json file based on input. No error checking yet.
url_pattern = re.compile(r"https://(.*)\.(.*)")
def add_vendor(name, url, cms, active, currency = False):
vendor = {}
vendor['name'] = name
vendor['url'] = url
dataname_data = re.match(url_pattern, url)
print(dataname_data)
vendor['dataname'] = f"{dataname_data.group(1)}_{dataname_data.group(2)}"
vendor['cms'] = cms
vendor['scrape'] = bool(active)
vendor['currency'] = False
vendor['uuid'] = str(uuid.uuid5(uuid.NAMESPACE_DNS, vendor['url']))
vendors = load_vendors()
vendors.append(vendor)
save_vendors(vendors)