示例#1
0
def main(url=Config.get("URL", "ships"), debug=False):
    stats = urllib2.urlopen(url).read()
    session.execute(Ship.__table__.delete())
    session.execute(
        text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))

    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in (
                    '-',
                    '',
            ):
                setattr(ship, key, line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug:
            print "%12s%12s%12s%12s" % (
                ship.name,
                ship.class_,
                ship.race,
                ship.type,
            )

        session.add(ship)

    session.commit()
    session.close()
示例#2
0
def main(url = Config.get("URL", "ships"), debug=False):
    req = urllib2.Request(url)
    req.add_header('User-Agent', useragent)
    stats = urllib2.urlopen(req).read()
    session.execute(Ship.__table__.delete())
    if Config.get("DB", "dbms") == "mysql":
        session.execute(text("ALTER TABLE ships AUTO_INCREMENT=1;", bindparams=[false]))
    else:
        session.execute(text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))
    
    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in ('-', '',):
                setattr(ship,key,line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug: print "%12s%12s%12s%12s" % (ship.name, ship.class_, ship.race, ship.type,)
        
        session.add(ship)
    
    session.commit()
    session.close()
示例#3
0
文件: shipstats.py 项目: JDD/DLR
def main(url = Config.get("URL", "ships"), debug=False):
    stats = urllib2.urlopen(url).read()
    session.execute(Ship.__table__.delete())
    session.execute(text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))
    
    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in ('-', '',):
                setattr(ship,key,line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug: print "%12s%12s%12s%12s" % (ship.name, ship.class_, ship.race, ship.type,)
        
        session.add(ship)
    
    session.commit()
    session.close()
示例#4
0
def main(url=Config.get("URL", "ships"), debug=False):
    req = urllib2.Request(url)
    req.add_header('User-Agent', useragent)
    stats = urllib2.urlopen(req).read()
    session.execute(Ship.__table__.delete())
    if Config.get("DB", "dbms") == "mysql":
        session.execute(
            text("ALTER TABLE ships AUTO_INCREMENT=1;", bindparams=[false]))
    else:
        session.execute(
            text("SELECT setval('ships_id_seq', 1, :false);",
                 bindparams=[false]))

    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in (
                    '-',
                    '',
            ):
                setattr(ship, key, line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug:
            print "%12s%12s%12s%12s" % (
                ship.name,
                ship.class_,
                ship.race,
                ship.type,
            )

        session.add(ship)

    session.commit()
    session.close()
示例#5
0
def add_ship(dct):
    ship = Ship()
    for key in dct.keys():
        if dct[key] != "-":
            if key == "class":
                k = key + "_"
            elif key[:4] == "init":
                k = "init"
            elif key[:6] == "target":
                k = "t" + key[-1]
            else:
                k = key
            setattr(ship, k, dct[key])
    ship.total_cost = int(ship.metal) + int(ship.crystal) + int(ship.eonium)
    session.add(ship)
    if __name__ == '__main__':
        print "%12s%12s%12s%12s" % (
            ship.name,
            ship.class_,
            ship.race,
            ship.type,
        )