def get_movie(movie): query = "SELECT * FROM movies WHERE movie_id = (?) OR movie_name = (?) OR release_date = (?) OR rating = " \ "(?) OR genre = (?)" params = (movie.movie_id, movie.movie_name, movie.release_date, movie.rating, movie.genre) get_database(query, params)
def get_random_lastname_upperclass (): """ Returns a random previously unused upperclass last name. Names get constructed out of a variety of syllables. **Examples**:: Adderley, Hartlethorpe, Islington, Thistleby, Windermere. """ first = db.get_database(DB_LAST_UPPER1).random_pop() second = db.get_database(DB_LAST_UPPER2).random_pop() third = db.get_database(DB_LAST_UPPER3).random() fourth = db.get_database(DB_LAST_UPPER4).random_pop() if not (first and second and third and fourth): return get_random_lastname_middleclass() return "%s%s%s%s" % (first, second, third, fourth)
def get_room_from_database (try_strict, type = "utility"): """ Pulls a random room matching some kind of criterion from the database. If none can be found, try again without the additional requirements. :``try_strict``: If true, apply a function to check for some requirement. If the results is None, print a message and return False. If false, just get a random room. *Required*. """ dbr = db.get_database("rooms") if try_strict: if type == "utility": new_room = dbr.random_pop(check_for_utility) elif type == "passage": new_room = dbr.random_pop(check_is_passage) elif type == "no_windows": new_room = dbr.random_pop(check_no_windows) else: new_room = dbr.random_pop(alphabetic_check) if new_room == None: print "None found -> relax the requirements:", get_room_from_database(False) return False else: new_room = dbr.random_pop() print new_room.name return try_strict
def db_get_entry (db_name): """ Helper method returning a random database entry for a given database. :``db_name``: The database's name. *Required* """ return db.get_database(db_name).random()
def get_random_lastname_combo (): """ Returns a random previously unused last name built up of adjective + noun, or noun + noun. **Examples**:: Blackstone, Goodfellow, Gladwell, Longbourne. """ first = db.get_database(DB_LAST_COMBO1).random_pop() if not first: return get_random_lastname_simple() second = db.get_database(DB_LAST_COMBO2).random_pop() if not second: return get_random_lastname_simple() if second[0] == 'w' and first.endswith('w'): second = second[1:] return "%s%s" % (first, second)
def get_random_lastname_irish (): """ Returns a random previously unused last name beginning with "O'". **Examples**:: O'Connor, O'Halloran, O'Neill. """ name = db.get_database(DB_LAST_GAELIC1).random_pop() if not name: return get_random_lastname_simple() return "O'%s" % name
def get_random_lastname_scottish (): """ Returns a random previously unused last name beginning with "Mc" or "Mac". **Examples**:: MacCormack, McDonald, MacLeod. """ name = db.get_database(DB_LAST_GAELIC2).random_pop() if not name: return get_random_lastname_simple() return "%s%s" % (random.choice(('Mc', 'Mac')), name)
def get_random_lastname_upperclass (): """ Returns a random previously unused upperclass last name. Names get constructed out of a variety of syllables. **Examples**:: Adderley, Hartlethorpe, Islington, Thistleby, Windermere. """ first = db.get_database(DB_LAST_UPPER1).random_pop() if not first: return get_random_lastname_middleclass() if not one_chance_in(4): second = random.choice(('er', 'le', 'lings')) third = db.get_database(DB_LAST_UPPER2).random_pop() if not third: return get_random_lastname_middleclass() return "%s%s%s" % (first, second, third) second = random.choice(('lington', 'erly', 'erley')) return "%s%s" % (first, second)
def get_random_lastname_nameson (): """ Returns a random previously unused last name ending in "s" or "son". **Examples**:: Adams, Jackson, Stevenson, Williams. """ name = db.get_database(DB_LAST_NAMESON).random_pop() if not name: return get_random_lastname_simple() if name.endswith('s'): if coinflip(): return name else: return "%son" % name return "%sson" % name
def db_random_pop_default (db_name, value = None): """ Removes a random element from the database and returns it. If such an element does not exist, returns another value instead. :``db_value``: Database name. :``value``: Default return value. *Default None* """ name = db.get_database(db_name).random_pop() if not name: if not value: return get_random_lastname_simple () else: return value return name
def get_rooms (num = 10): """ Pull a random list of room names from the database. :``num``: The number of suspects. *Default 10*. """ # Note: Instead of pulling up random room names from the database, # this should eventually draw on the manor's room list. rooms = [] dbr = db.get_database("rooms") for i in xrange(num): new_room = dbr.random_pop() if (new_room): new_room = "the %s" % new_room.name else: new_room = "nowhere" rooms.append(new_room) return rooms
def pick_room (self): """ Pick a room type from the database that matches the requirements. If no applicable room can be found, loosen the requirements one after another. """ dbr = db.get_database("rooms") new_room = dbr.random_pop(self.check_room) if new_room == None: # Loosen restrictions in order of importance. if self.windows != None: if self.debug: print "loosen windows restriction" self.windows = None elif self.size != None: if self.debug: print "loosen size restriction" self.size = None elif self.passage: if self.debug: print "loosen passage restriction" self.passage = False # Section checks override all other checks. elif self.utility != None: if self.debug: print "loosen utility restriction" self.utility = None else: if self.debug: print "get random room" return dbr.random_pop() return self.pick_room() if self.debug: print "found room: %s" % new_room return new_room
def get_box_office(): query = "SELECT * FROM box_office" get_database(query)
def get_movie_genre(): query = "SELECT * FROM movies_genre" get_database(query)
def get_genre(genre): query = "SELECT * FROM genres WHERE genre_id = (?) OR name = (?)" params = (genre.genre_id, genre.name) get_database(query, params)
def get_director(director): query = "SELECT * FROM directors WHERE director_id = (?) OR name = (?)" params = (director.director_id, director.name) get_database(query, params)
def get_actor_movie(): query = "SELECT * FROM actor_movie" get_database(query)
def get_actor(actor): query = "SELECT * FROM actors WHERE actor_id = (?) OR actor_name = (?)" params = (actor.actor_id, actor.actor_name) get_database(query, params)
def get_box_office(): query = "SELECT * FROM box_offices WHERE box_office_id = (?) OR box_office_gross = (?)" params = (box_office.box_office_id, box_office.box_office_gross) get_database(query, params)
def get_studio(studio): query = "SELECT * FROM studios WHERE studio_id = (?) OR studio_name = (?)" params = (studio.studio_id, studio.studio_name) get_database(query, params)
def get_director_movie_table(): query = "SELECT * FROM directors_movies" get_database(query)