コード例 #1
0
ファイル: categories.py プロジェクト: vudev/EbayCategoryTree
def render(cid):
    """
    Fetch the data for given category id from datastore.
    If available, render an html script with the data tree.
    If unavailable, print an error message.
    """

    # connect to database
    datastore = DataStore()
    datastore.connect()

    # fetch record from database with given id
    record = datastore.retrieve_by_cid(cid)

    # check if table doesn't exist
    if record == -1:
        return

    # if record doesn't exist in table, return
    if not record:
        print("No category with ID: {}".format(cid))
        return

    # if exists, fetch all children

    records = fetch_all_children(datastore, record)

    # connection close
    datastore.disconnect()

    # create an html file with name as cid
    create_html_page(cid, records)
コード例 #2
0
ファイル: categories.py プロジェクト: vudev/EbayCategoryTree
def rebuild():
    """
    Build the datastore/database by fetching the category data from ebay
    """

    # fetch data and extract from xml
    category_data_xml = fetch_categories_from_ebay()
    category_data = extract_category_data(category_data_xml)

    # connect to database
    datastore = DataStore()
    datastore.connect()

    # create a new table. drop first if exists
    datastore.drop_table()
    datastore.create_table()

    # insert data into datastore
    datastore.insert_all(category_data)

    # close connection
    datastore.disconnect()