Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.

vendormanage.py

Jordan Banasik edited this page Nov 19, 2019 · 3 revisions

load_vendors

Returns a list of dictionaries representing vendors

def load_vendors():
    with open('config/vendors.json', 'r') as f:
        return json.load(f)

save_vendors

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)

add_vendor

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)

Clone this wiki locally