def sentiment_analysis(username): """ We create a query to obtain the sentiment analysis of a tweet published by a given username. """ query = {"name": f"{username}"} text = list(collection.find(query, {"_id": 0, "name": 1, "text": 1})) sia = SentimentIntensityAnalyzer() sentence = list(collection.find(query, {"_id": 0, "text": 1})) extract = [tweet['text'] for tweet in sentence] polarity = sia.polarity_scores(extract[0]) return f'Text input and name: {text} The sentiment analysis shows: {polarity}'
def mensajes(): """ Función que devuelve todas las frases de Dumbledore :) """ query = {"character_name": "Albus Dumbledore"} frases = list(collection.find(query,{"_id": 0})) return frases
def mensajepersonaje(nombre): """ Hago una query a la base de datos para sacar las frases de una persona """ query = {"speaker": f"{nombre}"} frases = list(collection.find(query, {"_id": 0, "date": 0})) return frases
def person_sentence(nombre): """ Una query a la base de datos para obtener las frases de un personaje de Juego de Tronos """ query = {"Name": f"{nombre}"} frases = list(collection.find(query, {"_id": 0, "Release Date": 0})) return frases
def mensajespersonaje(personaje): """ Función que devuelve todas las frases un personaje """ query = {"character_name": f"{personaje}"} frases = list(collection.find(query,{"_id": 0})) return frases
def mensaje_personaje(nombre): """ Hacemos una query a la base de datos para sacar las frases de un personaje """ query = {"character_name": f"{nombre}"} frases = list(collection.find(query, {"_id": 0})) return frases
def quotes_episode(episode_title): """ Function that returns all the quotes of a certain episode (name of the episode must be given). """ proj = {"_id": 0, "index": 0} query = {"episode_title": f"{episode_title}"} quotes = list(collection.find(query, proj)) return quotes
def quotes_character(character): """ Function that returns all the quotes that a certain character says. """ proj = {"_id": 0, "index": 0} query = {"author": f"{character}"} quotes = list(collection.find(query, proj)) return quotes
def insertamensaje(name_episode,name,frase): dict_insert = { "episode name": f"{name_episode}", "name": f"{name}", "line": f"{frase}", } while dict_insert not in list(collection.find({}, {'name': 1,'episode name':1, 'line': 1, '_id': 0})): collection.insert_one(dict_insert)
def text_by_user(username): """ We create a query to obtain the tweets written by a certain user. """ query = {"name": f"{username}"} text = list(collection.find(query, {"_id": 0, "name": 1, "text": 1})) return text
def airline_by_user(username): """ We create a query to obtain the airline. """ query = {"name": f"{username}"} lines = list(collection.find(query, {"_id": 0, "name": 1, "airline": 1})) return lines
def mayoresretweets(numero): """ Función que devuelve los tweets con x numero de retweets """ query_one = {'rt': {"$gt": numero}} print(query_one) tweets = list(collection.find(query_one, {"tweet": 1, "rt": 1, "_id": 0})) return tweets
def title_sentiment_over(number): """ Devuelve los post con un title sentiment arriba de numero eligido, de -1 a 1. """ query = {'title_sentiment': {'$gte': float(number)}} t_sent = list(collection.find(query, {'_id': 0})) return t_sent
def ticker_posts(ticker): ''' Funcion que devuelve todos los posts que incluyen cierto ticker en el titulo. ''' query = {'tickers': f"{ticker}"} ticker_posts = list(collection.find(query, {'_id': 0, 'Unnamed: 0': 0})) return ticker_posts
def mensajepersonaje(Name): """ Hacemos una query a la base de datos para sacar las frases de un personaje """ query = {'Name': f'{Name}'} #id set to 0 so that id from mongo is not shown frases = list(collection.find(query, {"_id": 0, 'Season': 0})) return frases
def quotes_season(season): """ Function that returns all the quotes of a certain season. """ proj = {"_id": 0, "index": 0} query = {"season": f"{season}"} quotes = list(collection.find(query, proj)) return quotes
def serum_skincare_routine_url(routine_skin_option_for_query, routine_money_option_for_query): ''' Query that returns the brand, category, name, skin type and rating according to the skin type input = user's input output = dictionary ''' seventeen = list(collection.find({"$and":[{'Skin_Type':routine_skin_option_for_query},{'Price':{"$lte":routine_money_option_for_query}}, {'Category':'Face Serum'}]}, {'_id':0, 'Brand':0, 'Category':0, 'Skin_Type':0, 'Ingredients':0, 'Price':0, 'Rating':0}).limit(3).sort('Rating', -1)) return seventeen
def cleanser_skincare_routine(routine_skin_option_for_query, routine_money_option_for_query): ''' Query that returns the brand, category, name, skin type and rating according to the skin type input = user's input output = dictionary ''' eight = list(collection.find({"$and":[{'Skin_Type':routine_skin_option_for_query},{'Price':{"$lte":routine_money_option_for_query}}, {'Category':'Cleanser'}]}, {'_id':0, 'Ingredients':0, 'URL':0}).limit(3).sort('Rating', -1)) return eight
def number_quotes(character): """ Function that returns the number of quotes that a certain character says. """ proj = {"_id": 0, "index": 0} query = {"author": f"{character}"} nr = len(list(collection.find(query, proj))) return f"{character} says {nr} quotes"
def money(money_option): ''' Query that returns the brand, category, name, skin type and rating according to the price input = user's input output = dictionary ''' six = list(collection.find({'Price':{"$lte":money_option}}, {'_id':0, 'Ingredients':0, 'URL':0}).limit(5)) return six
def rating(rating_option): ''' Query that returns the brand, category, name, skin type and rating according to the rating input = user's input output = dictionary ''' seven = list(collection.find({'Rating':rating_option}, {'_id':0, 'Ingredients':0, 'URL':0}).limit(5)) return seven
def multi_category(multi_category_option): ''' Query that returns the brand, category, name, skin type and rating according to the product's categories input = user's input output = dictionary ''' four = list(collection.find({'Category':{"$in":multi_category_option}}, {'_id':0, 'Ingredients':0, 'URL':0, 'Price':0}).limit(5).sort('Rating', -1)) return four
def skin_type(skin_option): ''' Query that returns the brand, category, name, skin type and rating according to the skin type input = user's input output = dictionary ''' five = list(collection.find({'Skin_Type':skin_option}, {'_id':0, 'Ingredients':0, 'URL':0, 'Price':0}).limit(5).sort('Rating', -1)) return five
def sentiment(character): """ Function that returns the main sentiment of a certain character. """ proj = {"_id": 0, "word": 0} query = {"character": f"{character}"} sent = list(collection.find(query, proj)) return sent
def brand(brand_option): ''' Query that returns the brand, category, name, skin type and rating according to the brand input = user's input output = dictionary ''' one = list(collection.find({'Brand':brand_option}, {'_id':0, 'Ingredients':0, 'URL':0, 'Price':0}).limit(6).sort('Rating', -1)) return one
def word(character): """ Function that returns the most repeated word of a certain character """ proj = {"_id": 0, "sentiment": 0} query = {"character": f"{character}"} wrd = list(collection.find(query, proj)) return wrd
def quotes_word(word): """ Function that returns all the quotes that contains a certain word or sentence. """ proj = {"_id": 0, "index": 0} query = {"quote": {'$regex': f"{word}"}} quotes = list(collection.find(query, proj)) return quotes
def quotes_season_episode(season, episode): """ Function that returns all the quotes of a certain episode (number of the episode and must be given). """ proj = {"_id": 0, "index": 0} query = {"season": f"{season}", "episode_number": f"{episode}"} quotes = list(collection.find(query, proj)) return quotes
def textoxclave(clave): """ Función que devuelve todas los textos que tengan esa keyword """ query = {"Keywords": f"{clave}"} textos = list(collection.find(query, {"_id": 0})) if len(textos) == 0: return ("su búsqueda no ha dado ningún resultado") else: return textos
def textoxpartido(partido): """ Función que devuelve todas los textos de un partido """ query = {"Partido": f"{partido}"} textos = list(collection.find(query, {"_id": 0})) if len(textos) == 0: return ("su búsqueda no ha dado ningún resultado") else: return textos