def get(type_id, dbconnection:dbutils.DBConnection=None) -> GameType: if isinstance(type_id, str) and len(type_id.split(',')) > 0: type_id = splitstrlist(type_id) if len(type_id) == 1: type_id = type_id[0] if isinstance(type_id, list) and len(type_id) == 0: return list() if isinstance(type_id, int) and type_id != 0: dbconnection.execute("SELECT * FROM game_types WHERE type_id='{}'".format(type_id), dbutils.dbfields['game_types']) elif isinstance(type_id, list): dbconnection.execute( "SELECT * FROM game_types WHERE type_id IN (" + ','.join(map(str, type_id)) + ")", dbutils.dbfields['game_types']) elif type_id == 0: dbconnection.execute("SELECT * FROM game_types", dbutils.dbfields['game_types']) if len(dbconnection.last()) == 0: return list() game_types = dbconnection.last() game_types = list(map(lambda x: GameType(x, dbconnection=dbconnection), game_types)) if isinstance(type_id, int) and type_id != 0: return game_types[0] elif isinstance(type_id, list) or type_id == 0: return game_types
def get(city_id, dbconnection: dbutils.DBConnection = None) -> City: if isinstance(city_id, str) and len(city_id.split(',')) > 0: city_id = splitstrlist(city_id) if len(city_id) == 1: city_id = city_id[0] if isinstance(city_id, list) and len(city_id) == 0: return list() if isinstance(city_id, int) and city_id != 0: dbconnection.execute( "SELECT * FROM cities WHERE city_id='{}'".format(city_id), dbutils.dbfields['cities']) elif isinstance(city_id, list): dbconnection.execute( "SELECT * FROM cities WHERE city_id IN (" + ','.join(map(str, city_id)) + ")", dbutils.dbfields['cities']) elif city_id == 0: dbconnection.execute("SELECT * FROM cities", dbutils.dbfields['cities']) if len(dbconnection.last()) == 0: return list() cities = dbconnection.last() cities = list(map(lambda x: City(x), cities)) if isinstance(city_id, int) and city_id != 0: return cities[0] elif isinstance(city_id, list) or city_id == 0: return cities
def get(court_id, city_id: int = 1, dbconnection: dbutils.DBConnection = None) -> Court: if isinstance(court_id, str) and len(court_id.split(',')) > 0: court_id = splitstrlist(court_id) if len(court_id) == 1: court_id = court_id[0] if isinstance(court_id, list) and len(court_id) == 0: return list() if isinstance(court_id, int) and court_id != 0: dbconnection.execute( "SELECT * FROM courts WHERE court_id={} AND city_id={}".format( court_id, city_id), dbutils.dbfields['courts']) elif isinstance(court_id, list): dbconnection.execute( "SELECT * FROM courts WHERE court_id IN (" + ','.join(map(str, court_id)) + ") AND city_id={}".format(city_id), dbutils.dbfields['courts']) elif court_id == 0: dbconnection.execute( "SELECT * FROM courts WHERE city_id={}".format(city_id), dbutils.dbfields['courts']) if len(dbconnection.last()) == 0: return list() courts = dbconnection.last() courts = list(map(lambda x: Court(x, dbconnection=dbconnection), courts)) if isinstance(court_id, int) and court_id != 0: return courts[0] elif isinstance(court_id, list) or court_id == 0: return courts
def get(city_id, dbconnection:dbutils.DBConnection=None) -> City: if isinstance(city_id, str) and len(city_id.split(',')) > 0: city_id = splitstrlist(city_id) if len(city_id) == 1: city_id = city_id[0] if isinstance(city_id, list) and len(city_id) == 0: return list() if isinstance(city_id, int) and city_id != 0: dbconnection.execute("SELECT * FROM cities WHERE city_id='{}'".format(city_id), dbutils.dbfields['cities']) elif isinstance(city_id, list): dbconnection.execute("SELECT * FROM cities WHERE city_id IN (" + ','.join(map(str, city_id)) + ")", dbutils.dbfields['cities']) elif city_id == 0: dbconnection.execute("SELECT * FROM cities", dbutils.dbfields['cities']) if len(dbconnection.last()) == 0: return list() cities = dbconnection.last() cities = list(map(lambda x: City(x), cities)) if isinstance(city_id, int) and city_id != 0: return cities[0] elif isinstance(city_id, list) or city_id == 0: return cities
def get_by_id(game_id, dbconnection: dbutils.DBConnection = None) -> Game: if isinstance(game_id, str) and len(game_id.split(',')) > 0: game_id = splitstrlist(game_id) if len(game_id) == 1: game_id = game_id[0] if isinstance(game_id, list) and len(game_id) == 0: return list() if isinstance(game_id, int): dbconnection.execute( "SELECT * FROM games WHERE game_id={}".format(game_id), dbutils.dbfields['games']) elif isinstance(game_id, list): dbconnection.execute( "SELECT * FROM games WHERE game_id IN (" + ','.join(map(str, game_id)) + ")", dbutils.dbfields['games']) if len(dbconnection.last()) == 0: return list() games = dbconnection.last() games = list(map(lambda x: Game(x, dbconnection=dbconnection), games)) if isinstance(game_id, int): return games[0] elif isinstance(game_id, list): return games
def get(sport_id, dbconnection:dbutils.DBConnection=None) -> list: if isinstance(sport_id, str) and len(sport_id.split(',')) > 0: sport_id = splitstrlist(sport_id) if len(sport_id) == 1: sport_id = sport_id[0] if isinstance(sport_id, list) and len(sport_id) == 0: return list() if isinstance(sport_id, int) and sport_id != 0: dbconnection.execute("SELECT * FROM sport_types WHERE sport_id='{}'".format(sport_id), dbutils.dbfields['sport_types']) elif isinstance(sport_id, list): dbconnection.execute( "SELECT * FROM sport_types WHERE sport_id IN (" + ','.join(map(str, sport_id)) + ")", dbutils.dbfields['sport_types']) elif sport_id == 0: dbconnection.execute("SELECT * FROM sport_types", dbutils.dbfields['sport_types']) if len(dbconnection.last()) == 0: return list() sport_types = dbconnection.last() sport_types = list(map(lambda x: SportType(x), sport_types)) if isinstance(sport_id, int) and sport_id != 0: return sport_types[0] elif isinstance(sport_id, list) or sport_id == 0: return sport_types
def get(user_id, userlevel: int = -1, count: slice = slice(0, 20), dbconnection: dbutils.DBConnection = None) -> User: if isinstance(user_id, str) and len(user_id.split(',')) > 0: user_id = splitstrlist(user_id) if len(user_id) == 1: user_id = user_id[0] if isinstance(user_id, list) and len(user_id) == 0: return list() sql = "SELECT * FROM users WHERE user_id='{}'".format(user_id) if isinstance(user_id, int) and user_id != 0: sql = "SELECT * FROM users WHERE user_id='{}'".format(user_id) elif isinstance(user_id, list): sql = "SELECT * FROM users WHERE user_id IN (" + ','.join( map(str, user_id)) + ")" elif user_id == 0: sql = "SELECT * FROM users" if userlevel >= 0 or isinstance(userlevel, set): if user_id == 0: sql += ' WHERE ' else: sql += ' AND ' if isinstance(userlevel, int): sql += " LOCATE('|{}|', userlevel) ".format(userlevel) else: ' AND '.join( map(lambda x: "LOCATE('|{}|', userlevel)".format(x), userlevel)) sql += " ORDER BY played_games DESC" if user_id == 0: sql += " LIMIT {}, {}".format(count.start if count.start else 0, count.stop) dbconnection.execute(sql, dbutils.dbfields['users']) if len(dbconnection.last()) == 0: return list() users = dbconnection.last() users = list(map(lambda x: User(x, dbconnection=dbconnection), users)) if isinstance(user_id, int) and user_id != 0: return users[0] elif isinstance(user_id, list) or user_id == 0: return users
def delete(notification_id): with dbutils.dbopen() as db: if isinstance(notification_id, str) and len(notification_id.split(',')) > 0: notification_id = splitstrlist(notification_id) if len(notification_id) == 1: notification_id = notification_id[0] if isinstance(notification_id, list) and len(notification_id) == 0: return if isinstance(notification_id, int) and notification_id > 0: db.execute( "DELETE FROM notifications WHERE notification_id={}".format(notification_id)) elif isinstance(notification_id, list): db.execute("DELETE FROM notifications WHERE notification_id IN (" + ','.join( map(str, notification_id)) + ")") elif notification_id < 0: user_id = abs(notification_id) db.execute("DELETE FROM notifications WHERE `read`=1 AND user_id={}".format(user_id))
def get(user_id, userlevel:int=-1, count:slice=slice(0, 20), dbconnection:dbutils.DBConnection=None) -> User: if isinstance(user_id, str) and len(user_id.split(',')) > 0: user_id = splitstrlist(user_id) if len(user_id) == 1: user_id = user_id[0] if isinstance(user_id, list) and len(user_id) == 0: return list() sql = "SELECT * FROM users WHERE user_id='{}'".format(user_id) if isinstance(user_id, int) and user_id != 0: sql = "SELECT * FROM users WHERE user_id='{}'".format(user_id) elif isinstance(user_id, list): sql = "SELECT * FROM users WHERE user_id IN (" + ','.join(map(str, user_id)) + ")" elif user_id == 0: sql = "SELECT * FROM users" if userlevel >= 0 or isinstance(userlevel, set): if user_id==0: sql += ' WHERE ' else: sql += ' AND ' if isinstance(userlevel, int): sql += " LOCATE('|{}|', userlevel) ".format(userlevel) else: ' AND '.join(map(lambda x: "LOCATE('|{}|', userlevel)".format(x), userlevel)) sql += " ORDER BY played_games DESC" if user_id == 0: sql += " LIMIT {}, {}".format(count.start if count.start else 0, count.stop) dbconnection.execute(sql, dbutils.dbfields['users']) if len(dbconnection.last()) == 0: return list() users = dbconnection.last() users = list(map(lambda x: User(x, dbconnection=dbconnection), users)) if isinstance(user_id, int) and user_id != 0: return users[0] elif isinstance(user_id, list) or user_id == 0: return users
def delete(notification_id): with dbutils.dbopen() as db: if isinstance(notification_id, str) and len(notification_id.split(',')) > 0: notification_id = splitstrlist(notification_id) if len(notification_id) == 1: notification_id = notification_id[0] if isinstance(notification_id, list) and len(notification_id) == 0: return if isinstance(notification_id, int) and notification_id > 0: db.execute( "DELETE FROM notifications WHERE notification_id={}".format( notification_id)) elif isinstance(notification_id, list): db.execute("DELETE FROM notifications WHERE notification_id IN (" + ','.join(map(str, notification_id)) + ")") elif notification_id < 0: user_id = abs(notification_id) db.execute( "DELETE FROM notifications WHERE `read`=1 AND user_id={}". format(user_id))