def add_user(user_id): flag = False for user in User.select().where(User.user_id == user_id): flag = True if not flag: user = User.create(user_id=user_id, lis_film='') user.save()
def del_film(user_id, name, age): for user in User.select().where(User.user_id == user_id): film_lis = str(user.lis_film) film_lis = film_lis.split(',') nam = '' for film_id in film_lis: for film in Film.select().where(Film.film_id == int(film_id)): if ((name in film.name_film) and (film.year_release == age)): nam = name id = film_id film_lis = film_lis[:film_lis. index(id)] + film_lis[film_lis.index(id) + 1:] lis_film = '' for film in film_lis: lis_film += str(film) + ',' lis_film = lis_film[:-1] user.lis_film = lis_film if user.lis_film[0] == ',': user.lis_film = user.lis_film[1:] user.save() return nam
def change_position(user_id, name, age, pos): for user in User.select().where(User.user_id == user_id): film_lis = str(user.lis_film) film_lis = film_lis.split(',') for film_id in film_lis: for film in Film.select().where(Film.film_id == int(film_id)): if ((name in film.name_film) and (film.year_release == age)): id = film_id pos = int(pos) - 1 if pos >= len(film_lis): pos = len(film_lis) - 1 pos_id = film_lis.index(id) if pos_id > pos: film_lis = film_lis[:pos] + list( id) + film_lis[pos:pos_id] + film_lis[pos_id + 1:] if pos_id < pos: film_lis = film_lis[:pos_id] + film_lis[pos_id + 1:pos + 1] + list( id) + film_lis[pos + 1:] lis_film = '' for film in film_lis: lis_film += str(film) + ',' lis_film = lis_film[:-1] user.lis_film = lis_film if user.lis_film[0] == ',': user.lis_film = user.lis_film[1:] user.save()
def showUsers(): query = 'select * from user' rs = query_db(query, args=(), one=False) users = [] for row in rs: user = User.User(row[0], row[1]) users.append(user.__dict__) return json.dumps(users)
def show_users(): query = 'select * from user' rs = query_db(query, args=(), one=False) users = [] for user in rs: u = User.User(user[0], user[1], user[2]) users.append(u.__dict__) return json.dumps(users)
def return_up_age(user_id, age): film_list = [] for user in User.select().where(User.user_id == user_id): film_lis = str(user.lis_film).split(',') for film_id in film_lis: for film in Film.select().where(Film.film_id == film_id): if film.year_release > age: film_list.append( str(film.name_film + ' ' + film.year_release)) return film_list
def print_films(user_id): film_lis = [] for user in User.select().where(User.user_id == user_id): movie_lis = str(user.lis_film) movie_lis = movie_lis.split(',') film_lis = [] for film_id in movie_lis: for film in Film.select().where(Film.film_id == film_id): film_lis.append( str('%s. %s ' % (film.name_film, film.year_release))) return film_lis
def del_unusable_film(): set_id = set() for user in User.select(): film_lis = str(user.lis_film) film_lis = film_lis.split(',') for film_id in film_lis: set_id |= set(film_id) for film in Film.select(): if not (str(film.film_id) in list(set_id)): film.delete_instance() return list(set_id)
def add_film_user(name, age, user_id): for user in User.select().where(User.user_id == user_id): for film in Film.select().where(name == Film.name_film): if film.year_release == age: if not (str(film.film_id) in user.lis_film): if user.lis_film: user.lis_film += ',' + str(film.film_id) else: user.lis_film += str(film.film_id) if user.lis_film[0] == ',': user.lis_film = user.lis_film[1:] user.save()
def main_interface(): response = request.get_json() name = response["message"] print(name) split_words = User.User(name).splitter() words = Parser.Parser(split_words).parser() city = Parser.Parser(split_words).compare(words) coordinates, address = Maps.Maps(city).mapsextract() wikititle = Wikipedia.Wikipedia(city).title() title = Wikipedia.Wikipedia(city).wikipage() wikitext = Wikipedia.Wikipedia(city).wikiextract(title) link = Wikipedia.Wikipedia(city).wikilink() print(link) return make_response( jsonify({"myCity": city}, {"myList": coordinates}, {"myText": wikitext}, {"myTitle": link}), 200)
def main(): """define collect init, load ressources classes and struct the program""" collect = [0, 0, 0] maps = La.Labyrinth().open_map() space_list, wall_list, tina_position = La.Labyrinth().register_fixed(maps) item_list, maps = It.Items().items_position(space_list, maps) window, space = Ga.Pygame().unmovable(wall_list, space_list) Ga.Pygame().movable(window, item_list, tina_position) for line in maps: print(line) while 1: mcgyver_position, mcx, mcy = Ch.Character().mcgyver(maps) C.Collect().check_win(mcgyver_position, tina_position, window, collect) Ga.Pygame().display_mac(window, mcgyver_position, space) move = Us.User().entry_raw() collect = C.Collect().check_items(item_list, mcgyver_position, collect) Mo.Motion().check_direction(move, mcy, mcx, maps, collect)
def pop(user_id): for user in User.select().where(User.user_id == user_id): name = print_films(user_id)[0] try: films = user.lis_film.split(',') films = films[1:] lis_film = '' for film in films: lis_film += str(film) + ',' lis_film = lis_film[:-1] user.lis_film = lis_film except: user.lis_film = '' user.save() return name
def test_splitter(self): assert User.User("Où se trouve New York ?").splitter() == \ ["Où", "se", "trouve", "New", "York", "?"]