def parse_view_contents(lines): """ Parse view contents :param string paste_string: String pasted from view contents window """ matches, bad_lines = regex_match_lines(VIEWCONT_LIST_RE, lines) matches2, bad_lines2 = regex_match_lines(STATION_CONTAINER_RE, bad_lines) items = defaultdict(int) for name, group, location, _, _, quantity in matches: items[(name, group, location)] += f_int(quantity) results = [{'name': name, 'group': group, 'location': location, 'quantity': quantity} for (name, group, location), quantity in sorted(items.items())] items2 = defaultdict(int) for name, group, quantity in matches2: items2[(name, group)] += f_int(quantity) results2 = [{'name': name, 'group': group, 'quantity': quantity} for (name, group), quantity in sorted(items2.items())] return results + results2, bad_lines2
def parse_listing(lines): """ Parse Listing and Cargo Scan Results :param string paste_string: A raw string pasted from Eve Online of a cargo scan result or a human listing """ matches, bad_lines = regex_match_lines(LISTING_RE, lines) matches2, bad_lines2 = regex_match_lines(LISTING_RE2, bad_lines) matches3, bad_lines3 = regex_match_lines(LISTING_RE3, bad_lines2) items = defaultdict(int) for count, name in matches: items[name.strip()] += f_int(count) or 1 for name, count in matches2: items[name.strip()] += f_int(count) or 1 for res in matches3: items[res[0].strip()] += 1 results = [] for name, quantity in sorted(items.items()): results.append({'name': name, 'quantity': quantity}) return results, bad_lines3
def parse_contract(lines): """ Parse contract format :param string paste_string: A contract result string """ matches, bad_lines = regex_match_lines(CONTRACT_RE, lines) matches2, bad_lines2 = regex_match_lines(CONTRACT_RE2, bad_lines) # Collect Items items = defaultdict(int) for name, quantity, _type, category, details in matches: items[(name, _type, category, details)] += f_int(quantity) or 1 result = [{ 'name': name, 'quantity': quantity, 'type': _type, 'category': category, 'details': details, 'fitted': details.startswith('Fitted') } for (name, _type, category, details), quantity in sorted(items.items())] # Collect Items2 items2 = defaultdict(int) for name, quantity, _type in matches2: items2[(name, _type)] += f_int(quantity) or 1 result2 = [{ 'name': name, 'quantity': quantity, 'type': _type } for (name, _type), quantity in items2.items()] return result + result2, bad_lines2
def parse_wallet(lines): """ Parse wallet :param string paste_string: A swallet result string """ matches, bad_lines = regex_match_lines(JOURNAL_RE, lines) matches2, bad_lines2 = regex_match_lines(TRANSACTION_RE, bad_lines) result = [{ 'time': time, 'transaction_type': transaction_type, 'amount': amount, 'balance': balance, 'description': desc } for (time, transaction_type, amount, _, balance, _, desc) in matches] result2 = [{ 'time': time, 'name': name, 'price': price, 'quantity': f_int(quantity), 'credit': credit, 'currency': currency, 'client': client, 'where': where } for (time, name, price, _, quantity, credit, _, currency, client, where) in matches2] return result + result2, bad_lines2
def parse_wallet(lines): """ Parse wallet :param string paste_string: A swallet result string """ matches, bad_lines = regex_match_lines(JOURNAL_RE, lines) matches2, bad_lines2 = regex_match_lines(TRANSACTION_RE, bad_lines) result = [ {"time": time, "transaction_type": transaction_type, "amount": amount, "balance": balance, "description": desc} for (time, transaction_type, amount, _, balance, _, desc) in matches ] result2 = [ { "time": time, "name": name, "price": price, "quantity": f_int(quantity), "credit": credit, "currency": currency, "client": client, "where": where, } for (time, name, price, _, quantity, credit, _, currency, client, where) in matches2 ] return result + result2, bad_lines2
def parse_view_contents(lines): """ Parse view contents :param string paste_string: String pasted from view contents window """ matches, bad_lines = regex_match_lines(VIEWCONT_LIST_RE, lines) matches2, bad_lines2 = regex_match_lines(STATION_CONTAINER_RE, bad_lines) items = defaultdict(int) for name, group, location, _, _, quantity in matches: items[(name, group, location)] += f_int(quantity) results = [{ 'name': name, 'group': group, 'location': location, 'quantity': quantity } for (name, group, location), quantity in sorted(items.items())] items2 = defaultdict(int) for name, group, quantity in matches2: items2[(name, group)] += f_int(quantity) results2 = [{ 'name': name, 'group': group, 'quantity': quantity } for (name, group), quantity in sorted(items2.items())] return results + results2, bad_lines2
def parse_contract(lines): """ Parse contract format :param string paste_string: A contract result string """ matches, bad_lines = regex_match_lines(CONTRACT_RE, lines) matches2, bad_lines2 = regex_match_lines(CONTRACT_RE2, bad_lines) # Collect Items items = defaultdict(int) for name, quantity, _type, category, details in matches: items[(name, _type, category, details)] += f_int(quantity) or 1 result = [{'name': name, 'quantity': quantity, 'type': _type, 'category': category, 'details': details, 'fitted': details.startswith('Fitted')} for (name, _type, category, details), quantity in sorted(items.items())] # Collect Items2 items2 = defaultdict(int) for name, quantity, _type in matches2: items2[(name, _type)] += f_int(quantity) or 1 result2 = [{'name': name, 'quantity': quantity, 'type': _type} for (name, _type), quantity in items2.items()] return result + result2, bad_lines2
def parse_pi(lines): """ Parse planetary interaction results :param string paste_string: A PI result string """ matches, bad_lines = regex_match_lines(PI_RE, lines) matches2, bad_lines2 = regex_match_lines(PI_RE2, bad_lines) matches3, bad_lines3 = regex_match_lines(PI_RE3, bad_lines2) result = [{ 'name': name, 'quantity': float(quantity), 'routed': routed == 'Routed' } for quantity, name, routed, _ in matches] result2 = [{ 'name': name, 'quantity': float(quantity), 'volume': float(volume) } for name, quantity, volume in matches2] result3 = [{ 'name': name, 'quantity': float(quantity) } for name, quantity in matches3] return result + result2 + result3, bad_lines3
def parse_cargo_scan(lines): """ Parse Cargo Scan Results :param string paste_string: A raw string pasted from Eve Online of a cargo scan result """ matches, bad_lines = regex_match_lines(CARGO_SCAN_RE, lines) items = defaultdict(int) for count, name in matches: items[name.strip()] += f_int(count) or 1 results = [] for name, quantity in sorted(items.items()): item = {'name': name, 'quantity': quantity} if item['name'].endswith(' (Copy)'): item['details'] = 'BLUEPRINT COPY' item['name'] = item['name'].replace(' (Copy)', '') if item['name'].endswith(' (Original)'): item['details'] = 'BLUEPRINT ORIGINAL' item['name'] = item['name'].replace(' (Original)', '') results.append(item) return results, bad_lines
def parse_assets(lines): """ Parse asset list :param string paste_string: An asset list string """ matches, bad_lines = regex_match_lines(ASSET_LIST_RE, lines) result = [{'name': name, 'quantity': f_int(quantity) or 1, 'group': group, 'category': category, 'size': size, 'slot': slot, 'volume': volume, 'meta_level': meta_level, 'tech_level': tech_level} for (name, quantity, _, group, _, category, _, size, _, slot, _, volume, _, meta_level, _, tech_level) in matches] return result, bad_lines
def parse_industry(lines): """ Parse Industry :param string paste_string: A raw string pasted from the industry """ matches, bad_lines = regex_match_lines(INDUSTRY_RE, lines) items = defaultdict(int) for name, count in matches: items[name.strip()] += f_int(count) results = [] for name, me, te, runs, group in sorted(items.items()): item = { 'name': name, 'me': me, 'te': te, 'runs': runs, 'group': group, } results.append(item) return results, bad_lines
def parse_dscan(lines): """ Parse D-Scan format :param string paste_string: A D-Scan result string """ matches, bad_lines = regex_match_lines(DSCAN_LIST_RE, lines) result = [{'item_name': item_name, 'name': name, 'distance': distance} for item_name, name, distance, _, _ in matches] return result, bad_lines
def parse_fleet_composition(lines): """ Parse fleet composition window format :param string paste_string: A fleet composition list """ matches, bad_lines = regex_match_lines(FLEET_COMP_RE, lines) result = [{'character_name': character_name, 'system_name': system_name, 'ship_type': ship_type, 'ship_class': ship_class, 'fleet_role': fleet_role, 'fleet_command_skill': fleet_command_skill, 'wing_command_skill': wing_command_skill, 'leadership_skill': leadership_skill, 'squad': squad } for character_name, system_name, ship_type, ship_class, fleet_role, fleet_command_skill, wing_command_skill, leadership_skill, squad, in matches] return result, bad_lines
def parse_loot_history(lines): """ Parse loot history format :param string paste_string: A loot history result string """ matches, bad_lines = regex_match_lines(LOOT_HIST_RE, lines) result = [{'time': time, 'player_name': player_name, 'quantity': f_int(quantity), 'name': name} for time, player_name, quantity, name in matches] return result, bad_lines
def parse_bill_of_materials(lines): """ Parse bill of materials :param string paste_string: A bill of material string """ matches, bad_lines = regex_match_lines(BOM_RE, lines) matches2, bad_lines2 = regex_match_lines(BOM_RE2, bad_lines) result = [{'name': name, 'you': f_int(you), 'perfect': f_int(perfect or you)} for name, you, _, perfect in matches] result2 = [{'name': name, 'quantity': f_int(quantity)} for name, quantity in matches2] results = result + result2 if results: for line in IGNORED_LINES: if line in bad_lines2: bad_lines2.remove(line) return results, bad_lines2
def parse_dscan(lines): """ Parse D-Scan format :param string paste_string: A D-Scan result string """ matches, bad_lines = regex_match_lines(DSCAN_LIST_RE, lines) result = [{ 'item_name': item_name, 'name': name, 'distance': distance } for item_name, name, distance, _, _ in matches] return result, bad_lines
def parse_pi(lines): """ Parse planetary interaction results :param string paste_string: A PI result string """ matches, bad_lines = regex_match_lines(PI_RE, lines) matches2, bad_lines2 = regex_match_lines(PI_RE2, bad_lines) matches3, bad_lines3 = regex_match_lines(PI_RE3, bad_lines2) result = [{'name': name, 'quantity': f_int(quantity), 'routed': routed == 'Routed'} for quantity, name, routed, _ in matches] result2 = [{'name': name, 'quantity': f_int(quantity), 'volume': volume} for name, quantity, volume in matches2] result3 = [{'name': name, 'quantity': f_int(quantity)} for name, quantity in matches3] return result + result2 + result3, bad_lines3
def parse_loot_history(lines): """ Parse loot history format :param string paste_string: A loot history result string """ matches, bad_lines = regex_match_lines(LOOT_HIST_RE, lines) result = [{ 'time': time, 'player_name': player_name, 'quantity': f_int(quantity), 'name': name } for time, player_name, quantity, name in matches] return result, bad_lines
def parse_survey_scanner(lines): """ Parse survey scanner :param string paste_string: A survey scanner result string """ matches, bad_lines = regex_match_lines(SURVEY_SCANNER_RE, lines) result = [{'name': name, 'quantity': f_int(quantity), 'distance': distance} for name, quantity, distance, _ in matches] # NOQA (F812) if matches: return result, [] else: return result, bad_lines
def parse_wallet(lines): """ Parse wallet :param string paste_string: A swallet result string """ matches, bad_lines = regex_match_lines(JOURNAL_RE, lines) matches2, bad_lines2 = regex_match_lines(TRANSACTION_RE, bad_lines) result = [{'time': time, 'transaction_type': transaction_type, 'amount': amount, 'balance': balance, 'description': desc} for (time, transaction_type, amount, _, balance, _, desc) in matches] result2 = [{'time': time, 'name': name, 'price': price, 'quantity': f_int(quantity), 'credit': credit, 'currency': currency, 'client': client, 'where': where} for (time, name, price, _, quantity, credit, _, currency, client, where) in matches2] return result + result2, bad_lines2
def parse_survey_scanner(lines): """ Parse survey scanner :param string paste_string: A survey scanner result string """ matches, bad_lines = regex_match_lines(SURVEY_SCANNER_RE, lines) result = [{ 'name': name, 'quantity': f_int(quantity), 'distance': distance } for name, quantity, distance, _ in matches] # NOQA (F812) if matches: return result, [] else: return result, bad_lines
def parse_industry(lines): """ Parse Industry :param string paste_string: A raw string pasted from the industry """ matches, bad_lines = regex_match_lines(INDUSTRY_RE, lines) items = defaultdict(int) for name, count in matches: items[name.strip()] += f_int(count) results = [] for name, quantity in sorted(items.items()): item = {'name': name, 'quantity': quantity} results.append(item) return results, bad_lines
def parse_eft(lines): """ Parse EFT format :param string paste_string: An EFT block string """ lines = [line for line in lines if line.lower() not in EFT_BLACKLIST] if not lines: raise Unparsable('No valid parsable lines') if '[' not in lines[0] or ']' not in lines[0]: raise Unparsable('Invalid EFT title line') title_parts = lines[0].strip('[]').split(',', 1) if len(title_parts) != 2: raise Unparsable('Invalid EFT title line') ship = title_parts[0].strip() eft_name = title_parts[1].strip() modules = [] # Match "Module, Ammo" matches, bad_lines = regex_match_lines(EFT_LIST_RE, lines[1:]) matches2, bad_lines2 = parse_listing(bad_lines) module_w_ammo = defaultdict(int) for module, ammo in matches: module_w_ammo[(module, ammo)] += 1 for (name, ammo), quantity in sorted(module_w_ammo.items()): modules.append({'name': name, 'ammo': ammo, 'quantity': quantity}) for item in matches2: modules.append(item) result = { 'ship': ship, 'name': eft_name, 'modules': [res for res in modules] } return result, bad_lines2
def parse_chat(lines): """ Parse Chat transcript :param string paste_string: Chat transcript string """ matches, bad_lines = regex_match_lines(CHAT_RE, lines) lines = [{'time': time, 'author': author, 'message': message} for _, time, author, message in matches] items = {} if lines: for line in lines: item_matches = CHAT_ITEM_RE.findall(line['message']) for item_id, name in item_matches: if item_id not in item_matches: items[item_id] = {'id': f_int(item_id), 'name': name} return {'lines': lines, 'items': sorted(items.values())}, bad_lines else: return None, bad_lines
def parse_eft(lines): """ Parse EFT format :param string paste_string: An EFT block string """ lines = [line for line in lines if line not in EFT_BLACKLIST] if not lines: raise Unparsable('No valid parsable lines') if '[' not in lines[0] or ']' not in lines[0]: raise Unparsable('Invalid EFT title line') title_parts = lines[0].strip('[]').split(',', 1) if len(title_parts) != 2: raise Unparsable('Invalid EFT title line') ship = title_parts[0].strip() eft_name = title_parts[1].strip() modules = [] # Match "Module, Ammo" matches, bad_lines = regex_match_lines(EFT_LIST_RE, lines[1:]) matches2, bad_lines2 = parse_listing(bad_lines) module_w_ammo = defaultdict(int) for module, ammo in matches: module_w_ammo[(module, ammo)] += 1 for (name, ammo), quantity in sorted(module_w_ammo.items()): modules.append({'name': name, 'ammo': ammo, 'quantity': quantity}) for item in matches2: modules.append(item) result = {'ship': ship, 'name': eft_name, 'modules': [res for res in modules]} return result, bad_lines2