コード例 #1
0
ファイル: ogi.py プロジェクト: adi2004/pyogame
    def login(self, universe, user, password):
        pc.yellow("Logging in with %s" % user, end=" ")

        try:
            self.ogame = OGame(universe, user, password)
        except Exception as e:
            pp.red("Failed to login %s. Exception: " % user + str(e))
        else:
            if self.ogame.is_logged():
                pc.green("Success!")
                for p in self.planets:
                    p.ogame = self.ogame
コード例 #2
0
ファイル: ogi.py プロジェクト: adi2004/pyogame
 def load(self, file_name=None):
     """Reads the data from a json file"""
     if file_name is not None and self.file != file_name:
         print("Setting file to %s" % file_name)
         self.file = file_name
     file_name = self.file
     pc.bold("Loading %s" % file_name, end=" ")
     try:
         f = open(file_name, "r")
         data = f.read()
         f.close()
         # data = '{"planet": {"mines": "none"}, "moon": {"produciton": "tbd"}}'
         self.data = json.loads(data)
     except Exception as e:
         pp.red("JSON format error: " + str(e))
     else:
         self.init_planets()
         pc.green("Done.")
コード例 #3
0
ファイル: ogi.py プロジェクト: adi2004/pyogame
    def save(self, file_name=None):
        if file_name is not None and self.file != file_name:
            pp("Setting file to %s", file_name)
        file_name = self.file
        pc.bold("Saving to %s" % file_name, end=" ")

        # updated data
        for p in self.planets:
            if p.name() not in self.data["planets"]:
                self.data["planets"][p.name()] = {}
            self.data["planets"][p.name()].update(p.data)

        # write to file
        try:
            f = open(file_name, "w")
            f.write(json.dumps(self.data, indent=4))
            f.close()
        except Exception as e:
            pp.red("Something went wrong: " + str(e))
        else:
            pc.green("Done.")
コード例 #4
0
ファイル: ogi.py プロジェクト: adi2004/pyogame
    def fetch_planets(self):
        if self.ogame is None:
            pp.red("Not logged in")
            return

        # read from the server
        pc.yellow("Updating all planet ids...")
        planets = self.ogame.get_planet_ids() + self.ogame.get_moon_ids()

        # convert to dict and save in data
        planets_dict = {}
        for p in planets:
            pc.yellow("Reading " + p, end="")
            planet_overview = self.ogame.get_planet_infos(p)
            planets_dict[planet_overview["planet_name"]] = planet_overview
            pc.green(" OK for " + planet_overview["planet_name"])

        # update the class member
        if "planets" not in self.data:
            self.data["planets"] = {}

        self.data["planets"].update(planets_dict)
コード例 #5
0
ファイル: ogi.py プロジェクト: adi2004/pyogame
 def fetch_account(self):
     #TODO: implement this
     if self.ogame is None:
         pp.red("Not logged in")
         return