def load_cards(self): self.load_card_info() path = os.path.join(self.base_path,'starting_cards.json') obj = PPjo(filename=path) card_ids = obj.get_strings('card_ids') for key,card_id in enumerate(card_ids): key += 1 self.db.update("insert into play_starting_cards values(%s,%s)"%(key,card_id))
def load_users(self): path = os.path.join(self.base_path,'users.json') obj = PPjo(filename=path) users = obj.get_objects('users') for user in users: username = user.get_string("username") password = user.get_string("password") email = user.get_string("email") User.objects.create_user(username,email,password) register_add_cards(username)
def load_card_info(self): pre_glob_path = os.path.join(self.base_path,'cards','*.json') card_files = glob.glob(pre_glob_path) for card_file in card_files: obj = PPjo(filename=card_file) card = obj.get_object('card') key = obj.get_string('index') name = card.get_string('name') effect = card.get_string('effect') self.db.update('insert into play_card_names values(%s,"%s","%s")'% (key,name,effect))
def update_game(self,resp): #with open("ASDF.json","w") as f: # f.write(str(resp)) obj = PPjo(resp) respType = obj.get_string("respType") if respType == "ok": command = obj.get_string("command") gameId = obj.get_int("gameId") message = obj.get_string("message") gameRepr = obj.get_object("gameRepr") self.games[gameId] = Game(gameRepr.get_object("game")) self.current_game_id = gameId return message else: return 'Received error message: %s'%respType