def _format_response(json_response: json) -> dict: """ A helper method that formats the text message response to the user. Args: json_response: the movie metadata information from OMDB Returns: response: a dictionary that contains a essential movie information along with the summary of the movie. """ response_template = Template("$movie_title ($rating)\n" + "Directed By: $director\n" + "Cast: $cast\n\n" + "$plot\n\n" + "IMDB: $imdb\n" + "Rotton Tomatoes: $rt") movie_title, rating, directors, cast_members, plot, imdb, rt = ("", "", "", "", "", "", "") keys = json_response.keys() if 'Title' in keys: movie_title = json_response['Title'] if 'Rated' in keys: rating = json_response['Rated'] if 'Director' in keys: directors = json_response['Director'] if 'Plot' in keys: plot = json_response['Plot'] if 'Ratings' in keys: imdb_index = _check_for_ratings_keys(json_response['Ratings'], 'Internet Movie Database') rt_index = _check_for_ratings_keys(json_response['Ratings'], 'Rotten Tomatoes') imdb = json_response['Ratings'][imdb_index][ 'Value'] if imdb_index != None else "" rt = json_response['Ratings'][rt_index][ 'Value'] if rt_index != None else "" # get the cast if 'imdbID' in keys: imdb_id = json_response['imdbID'] cast_members = ct.cast(imdb_id) movie_info = response_template.substitute(movie_title=movie_title, rating=rating, director=directors, cast=cast_members, plot=plot, imdb=imdb, rt=rt) review = reviews.reviews(movie_title) response = {"movie_information": movie_info, "review_nyt": str(review)} return response
def cmd_cast(bot: Bot, update: Update): try: spell: str = update.message.text.split(" ", 1)[1] except IndexError: bot.send_message( update.message.chat.id, "⚠️ Non hai specificato nessun incantesimo!\n" "Sintassi corretta: `/cast <nome_incantesimo>`") return # Open a new db session session = db.Session() # Find a target for the spell target = random.sample(session.query(db.Telegram).all(), 1)[0] # Close the session session.close() bot.send_message(update.message.chat.id, cast.cast(spell_name=spell, target_name=target.username if target.username is not None else target.first_name, platform="telegram"), parse_mode="HTML")
def __init__(self, headers=[], values=[]): for header, value in zip(headers, values): setattr(self, header, cast.cast(value)) pass
import random import cast from relationships import relType as rType from cast import ConnectionStrategy from characters import character # Create graph c = cast.cast() # Add characters totalCharacters = random.randint(4, 15) #totalCharacters = 4 print("TOTAL CHARACTERS: " + str(totalCharacters)) for n in range(totalCharacters): c.addCharacter(character()) # GENERATE FAMILIAL RELATIONSHIP NETWORK numFamilies = (int(totalCharacters / 6), int(totalCharacters / 3)) numFamilyMembers = (max(2, int(totalCharacters / 6)), int(totalCharacters / 3)) if (numFamilies[1] * numFamilyMembers[1] > totalCharacters): print( "WARNING: May have too few characters for max possible families and members" ) print("Family parameters: number" + str(numFamilies) + ", size" + str(numFamilyMembers)) # GENERATE ROMANTIC RELATIONSHIP NETWORK numRomances = int(0.5 * totalCharacters) # GENERATE PROFESSIONAL RELATIONSHIP NETWORK numEmployers = (int(totalCharacters / 6), int(totalCharacters / 3))
import random import cast from relationships import relType as rType from cast import ConnectionStrategy from characters import character from characters import gender # Create graph c = cast.cast() # Add characters totalCharacters = random.randint(4, 15) characterGenders = [gender.getRandomGender() for x in range(totalCharacters)] print("TOTAL CHARACTERS: " + str(totalCharacters)) for charGender in characterGenders: c.addCharacter(character(charGender)) # GENERATE FAMILIAL RELATIONSHIP NETWORK numFamilies = (int(totalCharacters/6), int(totalCharacters/3)) numFamilyMembers = (max(2, int(totalCharacters/6)), int(totalCharacters/3)) if (numFamilies[1] * numFamilyMembers[1] > totalCharacters): print("WARNING: May have too few characters for max possible families and members") print("Family parameters: number" + str(numFamilies) + ", size" + str(numFamilyMembers)) # GENERATE ROMANTIC RELATIONSHIP NETWORK numRomances = int(0.5 * totalCharacters) # GENERATE PROFESSIONAL RELATIONSHIP NETWORK numEmployers = (int(totalCharacters/6), int(totalCharacters/3)) numEmployees = (max(2, int(totalCharacters/6)), int(totalCharacters/3))
def get_actors(self): c = cast(self.pagenum, self.cache) self.actors = c.get_actors()