def __init__(self, collector=None): if (collector == None): collector = part_collector.PartCollector() HTMLParser.__init__(self) self._collector = collector self._state = 1 self._current_part_dict = {}
def FetchStoreInfo(): sys.stdout.write('Fetching inventory...' + "\n") # get information for all lists that matched collector = part_collector.PartCollector() parser = ResultHtmlParser() # regular parts first url_params = { 'store_id': FLAGS.store_id, } try: conn = urllib.urlopen(SHOP_LIST_URL % url_params) except: print "Could not connect to BrickLink. Check your connection and try again." sys.exit(1) html = conn.read() parser.feed(html) # get results parts = parser.Result() sys.stdout.write(' ... %d parts in %d lots\n' % (sum(parts.values()), len(parts))) for part_id in parts: collector.AddPartbyKey(part_id, parts[part_id]) sys.stdout.flush() sys.stdout.write('\n') return collector.Parts()
def ReadParts(filenames): collector = part_collector.PartCollector() for filename in filenames: if filename.endswith('.xml'): wanted_list.CollectBricklinkParts(filename, collector) elif filename.endswith('.lxf'): lfxml.CollectBricklinkParts(filename, collector) elif (filename != ''): print 'Unknown file type for file %s' % filename return collector.Parts()
def FetchListParts(): sys.stdout.write('Fetching lists...' + "\n") # First login opener = login_bl.BricklinkLogin() if (not opener): print 'Could not login to Bricklink.' sys.exit(1) # Get all wanted lists, in particular their IDs, to be used in queries (lists, listsbyName) = FetchListInfo(opener) # Match existing lists with command line argument (which allows for a regex) matched_lists = MatchWantedLists(lists, FLAGS.wanted_list) # print some information which lists will be considered print "Found %d lists on bricklink, of which %d matched:" % \ (len(lists), len(matched_lists)) for list in sorted(listsbyName.keys()): if (list in matched_lists.values()): print "* ", list else: print " ", list # get information for all lists that matched collector = part_collector.PartCollector() for list_id in sorted(matched_lists, key=matched_lists.get): list_name = lists[list_id]["name"] sys.stdout.write(' processing ' + list_name + ' (' + list_id + ')') parser = ResultHtmlParser() # regular parts first FetchListPartsbyType(opener, list_id, 'P', parser) # now instructions (have to be done separately apparently) FetchListPartsbyType(opener, list_id, 'I', parser) # In theory we should be able to do the following for boxes, but this # is untested, thus commented: #FetchListPartsbyType(opener, list_id, 'B', parser) # get results back from parser lists[list_id]["parts"] = parser.Result() sys.stdout.write(' ... %d parts in %d lots\n' % (sum( lists[list_id]["parts"].values()), len(lists[list_id]["parts"]))) for part_id in lists[list_id]["parts"]: collector.AddPartbyKey(part_id, lists[list_id]["parts"][part_id]) sys.stdout.flush() sys.stdout.write('\n') return collector.Parts()
def OptimizeCommand(argv): if len(argv) >= 3: if argv[2] == 'wlist': parts = fetch_wanted_list.FetchListParts() # This arguably isn't the most useful option, but it works and in theory it # gives you what your own inventory would be worth if bought now on BL elif argv[2] == 'store': parts = fetch_inventory.FetchStoreInfo() else: parts = ReadParts(argv[2:]) try: os.makedirs(FLAGS.cachedir) except OSError: pass # reduce wanted parts by parts indicated to be already present if (FLAGS.inventory): iparts = ReadParts(FLAGS.inventory) collector = part_collector.PartCollector() collector.InitParts(parts) parts = collector.Subtract(iparts) shop_data = fetch_shops.FetchShopInfo(parts) try: opt = optimizer.CreateOptimizer() except NameError, e: ReportError(e) allow_used = AllowedUsedBricks(parts) opt.Load(parts, argv[2], shop_data, allow_used) output.PrintShopsText(opt) opt.Run() output.PrintOrdersText(opt, FLAGS.shop_fix_cost) if FLAGS.output_html: output.PrintAllHtml(opt, shop_data, FLAGS.shop_fix_cost, argv[2], FLAGS.output_html)
def __init__(self, collector=part_collector.PartCollector()): self._collector = collector self._current_part_dict = {} self._current_elem_name = '' self._current_content = ''
def __init__(self, collector = part_collector.PartCollector()): self._collector = collector self._custom_dict = self._ParseCustomDict()