Exemple #1
0
def main_loop():
    current_search = BsScrape(url)
    no_pages_to_search = current_search.calculate_no_pages()
    total_cars_found = 0
    car_list = []
    # Debugging
    # print(no_pages_to_search)

    for i in range(no_pages_to_search):
        # 12 cars per page.
        for j in range(12):
            # Try and except block due to the last page throwing index
            # IndexError if there are less than 12 cars.
            try:
                searched_car = IndividualCar(current_search.car_list_data)
                searched_car.pull_data(j)
                convert_data_to_excel_readable(car_list, searched_car)
                total_cars_found += 1
                # searched_car.print_stats()
                # print(car_list)
                # print(total_cars_found)
            except IndexError:
                # print('IndexError')
                pass
        # Stops the function from searching for the next page when it is on the last page to be searched.
        if i < no_pages_to_search - 1:
            current_search = BsScrape(current_search.next_page())
        else:
            pass
    write_data('car.name', car_list)
    print('Total number of cars found: ' + str(total_cars_found))
# -*- coding: utf-8 -*-
# Created by http://www.reddit.com/user/toshitalk
# Released under GPL.

# import standard libraries
import os
import sys

from conn import download_data
from excel import write_data
from excel import select_excel
from calculations import get_data
from calculations import get_values


if __name__ == "__main__":
    data = download_data()

    try:
        tool_file = sys.argv[1]
    except IndexError:
        tool_file = select_excel()

    tool_path = os.path.join(os.getcwd(), tool_file)

    # currently only using stats.
    # actives and passives to be implemented later.
    stats, actives, passives = get_data(data)
    data = get_values(stats)
    write_data(tool_path, data)
if __name__ == "__main__":
    # initialize storage
    workbook = select_excel()

    # download content
    content = download_content()
    owe = get_owe(content)

    # grab each item
    for slot, item in get_data(content):
        attributes = parse_item(item, owe)

        # if offhand is shield, set accordingly
        if slot == "offhand":
            if is_shield(item):
                slot = "shield"

        if slot == "pants":
            pprint.pprint(item)

        # for each item, grab each attribute
        for attribute, value in attributes.items():
            cellname = "{}-{}".format(slot, attribute)
            try:
                cells[cellname] = Stat(cells[cellname].cell, value)
            except KeyError as e:
                # no cell is set up to take this value
                pass

    write_data(workbook, "Gear", cells)