Пример #1
0
    def test_simple_invoice(self):
        invoice = Invoice("invoices/test.yaml")
        invoice.add_item(Item('dummy item', 2.54, 3, 20))
        data = invoice.get_document_data()
        assert data['from']['name'] == 'John Doe'
        assert data['from']['street'] == 'Random Street'
        assert data['from']['city'] == 'Random Town'
        assert data['from']['postcode'] == 4711

        assert data['to']['name'] == 'Jane Doe'
        assert data['to']['street'] == 'Random Other Street'
        assert data['to']['city'] == 'Random Other Town'
        assert data['to']['postcode'] == 4711815

        items = invoice.get_items()
        assert items[0].get_description() == 'dummy item'
        assert items[0].get_price() == 2.54
        assert items[0].get_tax() == 20
        assert items[0].total_price == 9.144
        assert items[0].get_total_price() == 9.14 # rounded value
        assert items[0].total_price_net == 7.62
        assert items[0].get_total_price_net() == 7.62
        assert items[0].get_total_tax() == 1.524

        invoice.output_pdf('test.pdf')
        assert os.path.exists('test.pdf')
Пример #2
0
def read_item_csv(path, version):
    csv_path = F"{path}\\{version}\\exd\\Item.csv"
    read_items = []
    with open(csv_path, 'r', encoding="utf-8") as csvfile:
        reader = csv.reader(csvfile)
        _index_row = next(reader)
        header_row = next(reader)
        index = parse_indices_from_header_row(header_row)
        _data_type_row = next(reader)
        for row in reader:
            this_item = Item()
            this_item.key = int(row[index["key"]])
            this_item.name = row[index["name"]].strip()
            this_item.level_item = int(row[index["level_item"]])
            this_item.item_search_category = row[index["item_search_category"]].strip()
            this_item.stack_size = int(row[index["stack_size"]])
            this_item.is_unique = parse_boolean_string(row[index["is_unique"]])
            this_item.is_untradable = parse_boolean_string(row[index["is_untradable"]])
            this_item.is_indisposable = parse_boolean_string(row[index["is_indisposable"]])
            this_item.can_be_hq = parse_boolean_string(row[index["can_be_hq"]])
            this_item.is_collectable = parse_boolean_string(row[index["is_collectable"]])
            this_item.always_collectable = parse_boolean_string(row[index["always_collectable"]])
            this_item.level_equip = int(row[index["level_equip"]])
            this_item.equip_restriction = bool(row[index["equip_restriction"]])
            this_item.class_job_category = row[index["class_job_category"]]
            read_items.append(this_item)
    return read_items
Пример #3
0
 def show_list(self, data) :
     for i in range(len(data)) :
         item = QListWidgetItem(self.listWidget)
         row = Item(data[i])
         item.setWhatsThis(str(i))
         item.setSizeHint(row.sizeHint())
         self.listWidget.setItemWidget(item, row)
         self.listWidget.addItem(item)
         self.itemList.append(item)
         self.rowList.append(row)
Пример #4
0
def create_local_csvs(game_version, item_list, recipe_list):
    output_path = F"./debug_csvs/{game_version}"
    if not os.path.exists(output_path):
        os.makedirs(output_path)

    header_row = Item().__dict__.keys()
    item_file = F"{output_path}/filtered_items.csv"
    ingredients_file = F"{output_path}/filtered_recipe_ingredients.csv"
    recipe_meta_file = F"{output_path}/recipe_meta_information.csv"
    with open(item_file, "w", newline='', encoding="utf-8") as outfile:
        writer = csv.DictWriter(outfile, fieldnames=header_row)
        writer.writeheader()
        writer.writerows([item.__dict__ for item in item_list])

    data = []
    header = ["recipe_name", "material", "amount"]
    for recipe in recipe_list:
        for ingredient, amount in recipe.ingredients:
            row = {"recipe_name": recipe.item_result.strip(), "material": ingredient.strip(), "amount": amount.strip()}
            data.append(row)

    with open(ingredients_file, "w", newline='') as outfile:
        writer = csv.DictWriter(outfile, fieldnames=header)
        writer.writeheader()
        writer.writerows(data)

    data = []
    header = ["recipe_name",
              "craft_type",
              "yield_per_craft",
              "material_quality_factor",
              "difficulty_factor",
              "quality_factor",
              "durability_factor",
              "recipe_level_table_entry",
              "needs_specialist"]

    for recipe in recipe_list:
        row = {
            "recipe_name": recipe.item_result,
            "craft_type": recipe.craft_type,
            "yield_per_craft": recipe.amount_result,
            "material_quality_factor": recipe.material_quality_factor,
            "difficulty_factor": recipe.difficulty_factor,
            "quality_factor": recipe.quality_factor,
            "durability_factor": recipe.durability_factor,
            "recipe_level_table_entry": recipe.recipe_level_table,
            "needs_specialist": recipe.is_specialization_required
        }
        data.append(row)

    with open(recipe_meta_file, "w", newline='') as outfile:
        writer = csv.DictWriter(outfile, fieldnames=header)
        writer.writeheader()
        writer.writerows(data)
Пример #5
0
 def __init__(self, game_map, screen):
     """
     Maze grid, from Grid class which import external file.
     """
     self.maze_grid = copy.deepcopy(game_map.grid)
     self.screen = screen
     self.guardian = Guardian(game_map)
     self.player = Player(game_map)
     self.needle = Item(game_map, self.guardian)
     self.tube = Item(game_map, self.guardian)
     self.ether = Item(game_map, self.guardian)
     self.bag = Bag()
     self.objects_list = [
         game_map, self.player, self.guardian, self.needle, self.tube,
         self.ether, self.bag
     ]
     self.item_1 = (6, 21)
     self.item_2 = (8, 21)
     self.item_3 = (10, 21)
     self.bag_items = [self.item_1, self.item_2, self.item_3]
     self.floor = None
     self.wall = None
     self.macgyver = None
     self.guard = None
     self.exit_tile = None
     self.exit_open = None
     self.needle_img = None
     self.tube_img = None
     self.ether_img = None
     self.empty_bag = None
     self.item_bag = None
     self.seringue_img = None
     self.splash1 = None
     self.splash2 = None
     self.splash3 = None
     self.rip = None
     self.bag_font = None
     self.text_full = None
     self._running = True
     self.list_guardian_animation = []
Пример #6
0
 def show_list(self, data):
     remainP = [
         '100개 이상', '30개 이상 100개 미만', '2개 이상 30개 미만', '1개 이하', '판매중지'
     ]
     for i in range(len(data)):
         item = QListWidgetItem(self.listWidget)
         row = Item(data[i])
         rs = data[i].get('remain_stat')
         if rs == None:
             row.remain_stat.setStyleSheet('color:red')
         elif remainP.index(rs) <= 1:
             row.remain_stat.setStyleSheet('color:green')
         elif remainP.index(rs) == 2:
             row.remain_stat.setStyleSheet('color:orange')
         else:
             row.remain_stat.setStyleSheet('color:red')
         item.setWhatsThis(str(i))
         item.setSizeHint(row.sizeHint())
         self.listWidget.setItemWidget(item, row)
         self.listWidget.addItem(item)
         self.itemList.append(item)
         self.rowList.append(row)
Пример #7
0
def fetch_and_insert(conn, driver, mobile, url, title, link, username):
    """
        Fetch content from url and and insert results into the db.

        This fetch the content from a specified url with a predefined web driver.
        The method does not parse any item, the title or link are already given as
        parameters. A user is also associated with each item inserted into the db.

        :param conn: A mongo connection
        :param driver: A web driver
        :param mobile: The mobile flag
        :param url: The url of the rss feed
        :param title: The title of the item
        :param link: The link ref of the item
        :param username: The username associated with the item
        :type conn: MongoClient
        :type driver: WebDriver
        :type mobile: bool
        :type url: str
        :type title: str
        :type link: str
        :type username: str
        :return: Nothing
        :rtype: None
    """
    if not link:
        return 'continue'
    link = format_link(link)
    if item_exists_in_db(conn, link, mobile):
        return 'continue'
    start_time = time.time()
    print 'Get content for {}'.format(link)
    content = get_content(driver, link)
    final_link = clean_link(driver.current_url)
    print 'Content is parsed for {}, took {} s'.format(link, (time.time() - start_time))
    item = Item(title, final_link, url, username, content)
    insert_item(conn, item.link, str(item.content), item.get_metadata(), mobile)
def write_items_to_external_spreadsheet(item_list, service, config):
    spreadsheet_id = config["spreadsheet_id"]
    item_range = config["item_range"]
    """
    Write relevant items to external spreadsheet.
    """
    header_row = Item().__dict__.keys()

    data = [list(header_row)] + [item.to_sheet_row() for item in item_list]
    # First, clear out data from sheet
    clear_sheet(service, item_range, spreadsheet_id)

    value_input_option = 'RAW'
    insert_data_option = 'OVERWRITE'
    value_range_body = {'majorDimension': 'ROWS', 'values': data}

    spreadsheet_values = service.spreadsheets().values()
    request = spreadsheet_values.append(spreadsheetId=spreadsheet_id,
                                        range=item_range,
                                        valueInputOption=value_input_option,
                                        insertDataOption=insert_data_option,
                                        body=value_range_body)
    response = request.execute()

    if response["spreadsheetId"] != spreadsheet_id:
        print("Didn't get correct spreadsheet, see following response")
        print(response)
        sys.exit(1)

    num_rows_updated = response["updates"]["updatedRows"]

    if num_rows_updated != len(data):
        print(
            F"Error with writing data, expected to write {len(data)} rows but only wrote {num_rows_updated} rows."
        )
        print(response)
        sys.exit(2)
Пример #9
0
	def test_createoneitemlocation( self ) :
		field = Field()
		item = Item()
		item.addRandomStartLocation(field)
		self.assertTrue( item.getStartLocation() != ( 0, 0, 0 ) )
Пример #10
0
#!/usr/bin/env python3

from lib.invoice import Invoice
from lib.item import Item
import argparse
import locale

parser = argparse.ArgumentParser(
    description='Convert HTML template to pdf with data from yaml')
parser.add_argument('--template',
                    help='The name of the template to use (e.g. invoice)',
                    default="invoice.html")
parser.add_argument(
    '--data',
    help='The name of the data template to use (e.g. invoices/customer.yaml)',
    default="invoices/test.yaml")
parser.add_argument('--output',
                    help='The output pdf file',
                    default="invoice.pdf",
                    type=argparse.FileType('w'))
parser.add_argument('--locale',
                    help='The locale to use',
                    default="de_DE.UTF-8")

args = parser.parse_args()
locale.setlocale(locale.LC_ALL, args.locale)

invoice = Invoice(args.data)
invoice.add_item(Item("Random Item", 25.00, 2, 0))
invoice.output_pdf(args.output.name)
Пример #11
0
 def test_invoice_arithmetics(self):
     item = Item('line item', 12, 2, 19)
     assert item.get_price() == 12.00
     assert item.get_total_price_net() == 24.00
     assert item.get_total_price() == 28.56
Пример #12
0
 def test_set_amount(self):
     item = Item('line item', 12.0283734821, 7, 19)
     amount = 12
     item.set_amount(amount)
     assert item.get_amount() == amount
Пример #13
0
 def test_item_with_floating_point_price(self):
     item = Item('line item', 12.0283734821, 7, 19)
     assert item.get_total_price_net() == 84.2
Пример #14
0
 def test_item_with_amount_lower_than_zero(self):
     with pytest.raises(Exception) as error:
         item = Item('line item', 10, -10, 0)
     assert "amount cannot be negative" in str(error.value)
Пример #15
0
 def test_item_with_no_tax(self):
     item = Item('line item', 12, 2, 0)
     assert item.get_total_price_net() == 24.00
     assert item.get_total_price() == 24.00
Пример #16
0
def add(db, args, config):
    '''Create, fill, save, and display a new jot Item.'''
    #
    # Arguments:
    #   [none]
    #           opens the default editor with a temp file.
    #
    #   -m "string"
    #   --manual "string"
    #           uses the supplied string as the item content.
    #
    #   -q
    #   --quiet
    #           suppress output, would really only make sense to
    #           run with -m, but works either way.
    #   -h
    #   --high
    #           attaches a 'high' priority to the item. Priority
    #           defaults to normal when this and the -l option are
    #           omitted.
    #
    #   -l
    #   --low
    #           attaches a 'low' priority to the item.
    #
    #   -t "string, string, ... "
    #   --tags "string, string, ... "
    #           attaches one or more comma-separated strings as
    #           to the item as tags. These are optional and can
    #           always be added later with the tag command.

    manual = False
    quiet = False
    content = None
    batchMode = False
    priority = 'Normal'
    tags = None
    for tup in args:
        arg1 = tup[0]
        arg2 = tup[1]
        if (arg1 == 'm' or arg1 == '-manual') and arg2 is not None:
            manual = True
            content = arg2
        if arg1 == '-high' or arg1 == 'h':
            priority = 'High'
        if arg1 == '-low' or arg1 == 'l':
            priority = 'Low'
        if arg1 == '-quiet' or arg1 == 'q':
            quiet = True
        if arg1 == '-batch' or arg1 == 'b':
            batchMode = True
        if (arg1 == '-tags' or arg1 == 't') and arg2 is not None:
            tags = arg2.split(',')

    if manual:
        item = Item(db, content=content, priority=priority, tags=tags)
    else:
        item = Item(db, priority=priority, tags=tags)
        item.fill()
    item.save()
    if not quiet:
        print util.decorate('OKGREEN', 'New item addition was successful.\n')
        item.display()
    return True