from pyapimaker import PyApi from connector import server, s_login, s_storage from game import game import logic from random import randint import json game_api = PyApi() def get_clean_storage(): return {"win": 0, "lost": 0, "draw": 0, "surrender": 0, "played": 0} def get_from_storage(key): resp = s_storage.get_from(game.usertoken, game.storage, key) if resp.had_errors: return None return json.loads(str(resp.content)) def storage_increment(key): if server.is_online(): s = get_from_storage(key) put_to_storage(key, s + 1) def put_to_storage(key, value): resp = s_storage.put_to(game.usertoken, game.storage, key, value) if resp.had_errors: return False
from pyapimaker import PyApi from pyapimaker import PyRpcServer, PyRpcBlueprint from ast import literal_eval myapi = PyApi() @myapi.add() def foo_a(): print("foo_a is doing thing on serverside") return ("things done") @myapi.add() def foo_b(li, num): print("foo_b is doing something on serverside") li = literal_eval(li) return [s + str(num) for s in li] if __name__ == "__main__": s = PyRpcServer(port=17887) bp = PyRpcBlueprint(name="web", prefix="/rpc") bp.add(myapi.find_functions(), only_names=True) s.add(bp) s.run()
import shelve from pyapimaker import PyApi from config import config storage = PyApi() db_dir = config.get("db_dir", ".") users = shelve.open(db_dir + "/users.db") with storage.context("users"): @storage.add() def get(name): return users.get(name, None) @storage.add() def put(name, user): users[name] = user users.sync() @storage.add() def rem(name): del users[name] users.sync() profiles = shelve.open(db_dir + "/profiles.db") with storage.context("profiles"): @storage.add()