Пример #1
0
def export(data):
    def elapsed(game_time):
        return '%3d:%02d:%02d' % ((game_time // 3600) % 3600,
                                  (game_time // 60) % 60, game_time % 60)

    querytime = config.getint('querytime') or int(time.time())

    openlog()

    commodities = defaultdict(int)
    for item in data['ship'].get('cargo', {}).get('items', []):
        if item['commodity'] != 'drones':
            commodities[commodity_map.get(item['commodity'],
                                          item['commodity'])] += item['qty']

    logfile.write(
        '%s,%s,%s,%s,%s,%s\r\n' %
        (time.strftime('%Y-%m-%d', time.localtime(querytime)),
         time.strftime('%H:%M:%S',
                       time.localtime(querytime)), data['lastSystem']['name'],
         data['commander']['docked'] and data['lastStarport']['name'] or '',
         ship_map.get(data['ship']['name'], data['ship']['name']), ','.join(
             [('%d %s' % (commodities[k], k)) for k in sorted(commodities)])))

    logfile.flush()
Пример #2
0
def export(data):

    querytime = config.getint('querytime') or int(time.time())

    commodities = defaultdict(int)
    for item in data['ship'].get('cargo', {}).get('items', []):
        if item['commodity'] != 'drones':
            commodities[commodity_map.get(item['commodity'],
                                          item['commodity'])] += item['qty']

    writelog(querytime, data['lastSystem']['name'], data['commander']['docked']
             and data['lastStarport']['name'],
             ship_map.get(data['ship']['name'].lower(),
                          data['ship']['name']), commodities)
Пример #3
0
def addcommodities(data):

    if not data['lastStarport'].get('commodities'): return

    commodityfile = 'commodity.csv'
    commodities = {}

    # slurp existing
    if isfile(commodityfile):
        with open(commodityfile) as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                key = row.pop('name')
                commodities[key] = row
    size_pre = len(commodities)

    for commodity in data['lastStarport'].get('commodities'):
        key = commodity_map.get(commodity['name']) or commodity['name']
        new = {
            'id'       : commodity['id'],
            'category' : category_map.get(commodity['categoryname']) or commodity['categoryname'],
            'average'  : commodity['cost_mean'].split('.')[0]
        }
        old = commodities.get(key)
        if old:
            if new['id'] != old['id'] or new['category'] != old['category']:
                raise AssertionError('%s: "%s"!="%s"' % (key, new, old))
            elif new['average'] != old['average']:
                commodities[key] = new
        else:
            commodities[key] = new

    if len(commodities) > size_pre:

        if isfile(commodityfile):
            if isfile(commodityfile+'.bak'):
                os.unlink(commodityfile+'.bak')
            os.rename(commodityfile, commodityfile+'.bak')

        with open(commodityfile, 'wb') as csvfile:
            writer = csv.DictWriter(csvfile, ['id','category', 'name', 'average'])
            writer.writeheader()
            for key in commodities:
                commodities[key]['name'] = key
            for row in sorted(commodities.values(), key = lambda x: (x['category'], x['name'])):
                writer.writerow(row)

        print 'Added %d new commodities' % (len(commodities) - size_pre)
Пример #4
0
def export(data):

    querytime = config.getint("querytime") or int(time.time())

    commodities = defaultdict(int)
    for item in data["ship"].get("cargo", {}).get("items", []):
        if item["commodity"] != "drones":
            commodities[commodity_map.get(item["commodity"], item["commodity"])] += item["qty"]

    writelog(
        querytime,
        data["lastSystem"]["name"],
        data["commander"]["docked"] and data["lastStarport"]["name"],
        ship_map.get(data["ship"]["name"].lower(), data["ship"]["name"]),
        commodities,
    )
Пример #5
0
def addcommodities(data):

    if not data['lastStarport'].get('commodities'): return

    commodityfile = 'commodity.csv'
    commodities = {}

    # slurp existing
    if isfile(commodityfile):
        with open(commodityfile) as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                key = row.pop('name')
                commodities[key] = row
    size_pre = len(commodities)

    for commodity in data['lastStarport'].get('commodities'):
        key = commodity_map.get(commodity['name']) or commodity['name']
        new = {
            'id'       : commodity['id'],
            'category' : category_map.get(commodity['categoryname']) or commodity['categoryname'],
            'average'  : commodity['cost_mean'].split('.')[0]
        }
        old = commodities.get(key)
        if old:
            if new != old:
                raise AssertionError('%s: "%s"!="%s"' % (key, new, old))
        else:
            commodities[key] = new

    if len(commodities) > size_pre:

        if isfile(commodityfile):
            if isfile(commodityfile+'.bak'):
                os.unlink(commodityfile+'.bak')
            os.rename(commodityfile, commodityfile+'.bak')

        with open(commodityfile, 'wb') as csvfile:
            writer = csv.DictWriter(csvfile, ['id','category', 'name', 'average'])
            writer.writeheader()
            for key in commodities:
                commodities[key]['name'] = key
            for row in sorted(commodities.values(), key = lambda x: (x['category'], x['name'])):
                writer.writerow(row)

        print 'Added %d new commodities' % (len(commodities) - size_pre)
Пример #6
0
def export(data):

    def elapsed(game_time):
        return '%3d:%02d:%02d' % ((game_time // 3600) % 3600, (game_time // 60) % 60, game_time % 60)

    querytime = config.getint('querytime') or int(time.time())

    openlog()

    logfile.write('%s,%s,%s,%s,%s,%s\r\n' % (
        time.strftime('%Y-%m-%d', time.localtime(querytime)),
        time.strftime('%H:%M:%S', time.localtime(querytime)),
        data['lastSystem']['name'],
        data['commander']['docked'] and data['lastStarport']['name'] or '',
        ship_map.get(data['ship']['name'], data['ship']['name']),
        ','.join([('%d %s' % (x['qty'], commodity_map.get(x['commodity'],x['commodity']))) for x in data['ship']['cargo']['items'] if x['commodity']!='drones'])))
    logfile.flush()
Пример #7
0
def export(data):

    def elapsed(game_time):
        return '%3d:%02d:%02d' % ((game_time // 3600) % 3600, (game_time // 60) % 60, game_time % 60)

    querytime = config.getint('querytime') or int(time.time())

    openlog()

    commodities = defaultdict(int)
    for item in data['ship'].get('cargo',{}).get('items',[]):
        if item['commodity'] != 'drones':
            commodities[commodity_map.get(item['commodity'], item['commodity'])] += item['qty']

    logfile.write('%s,%s,%s,%s,%s,%s\r\n' % (
        time.strftime('%Y-%m-%d', time.localtime(querytime)),
        time.strftime('%H:%M:%S', time.localtime(querytime)),
        data['lastSystem']['name'],
        data['commander']['docked'] and data['lastStarport']['name'] or '',
        ship_map.get(data['ship']['name'], data['ship']['name']),
        ','.join([('%d %s' % (commodities[k], k)) for k in sorted(commodities)])))

    logfile.flush()