def facebook_authorized(resp): if resp is None: return 'Access denied: reason=%s error=%s' % ( request.args['error_reason'], request.args['error_description']) session['oauth_token'] = (resp['access_token'], '') me = facebook.get('/me/television') # Flask.jsonify(me.data) #pprint(me.data['data'], depth=100) #pprint(me.data, depth=100) result = [] for strx in me.data['data']: result.append(str(strx['name'])) pprint(result, depth=100) recommender.main()
def output(): tutor_url = str(request.args.get('tutor_url')) print tutor_url # BEGIN Normalize url if tutor_url.startswith("www"): tutor_url = "http://" + tutor_url elif tutor_url.startswith("wyzant"): tutor_url = "http://www." + tutor_url if "#" in tutor_url: tutor_url = tutor_url.split("#")[0] # END Normalize url try: tutor_data = scrape_tutor.main(tutor_url) example, hourly_rate = cleanup_tutor_features.clean_tutor(tutor_data) try: nn, max_tut, min_tut, img_io = recommender.main( example, df, possible_subjects) except: error_message = 'Looks like you\'re a special snowflake! There\'s not too many other similar tutors, so charge what you want.' return render_template("error.html", error_message=error_message) tutor_name = example['name'] tut_list = [] tut_list.append(dict(rel='Most similar tutor', \ name=nn['name'], \ rate=nn['hourly_rate'], \ url=nn['url'])) tut_list.append(dict(rel='Maximum priced tutor', \ name=max_tut['name'], \ rate=max_tut['hourly_rate'], \ url=max_tut['url'])) tut_list.append(dict(rel='Minimum priced tutor', \ name=min_tut['name'], \ rate=min_tut['hourly_rate'], \ url=min_tut['url'])) example_tutor = dict(name=tutor_name, rate=hourly_rate, url=tutor_data['url']) html = """ <img src="data:image/png;base64,{}"> """ img_io = img_io.getvalue().encode('base64') img_io = html.format(img_io) return render_template("output.html", \ tutors=tut_list, \ example_tutor=example_tutor, \ sim_plot=img_io) except: error_message = 'Whoops! Cannot find WyzAnt profile. Did you enter the correct url?' return render_template("error.html", error_message=error_message)
def example_output(): example_tutor_url = str(request.args.get('example_tutor_url')) if example_tutor_url == 'None': return render_template("error_example.html") examples = {} examples[ 'Elliott L.'] = "http://www.wyzant.com/Tutors/NY/New_York/7875805/?z=10116&d=20&sl=80075877&sort=27" # examples['Erica S.'] = "http://www.wyzant.com/Tutors/NY/New_York/8671128/?z=10116&d=20&sl=80075877&sort=27" # $40/hr -> $49 examples[ 'Jared A.'] = "http://www.wyzant.com/Tutors/NY/New_York/8565916/?z=10116&d=20&sl=80075877&sort=27" examples[ 'Jennifer T.'] = "http://www.wyzant.com/Tutors/NY/New_York/8462587/?z=10116&d=20&sl=80075877&sort=27" examples[ 'Linda W.'] = "http://www.wyzant.com/Tutors/NY/New_York/8587257/?z=10116&d=20&sl=80075877&sort=27" tutor_url = examples[example_tutor_url] tutor_name = example_tutor_url tutor_data = scrape_tutor.main(tutor_url) example, hourly_rate = cleanup_tutor_features.clean_tutor(tutor_data) nn, max_tut, min_tut, img_io = recommender.main(example, df, possible_subjects) tut_list = [] tut_list.append(dict(rel='Most similar tutor', \ name=nn['name'], \ rate=nn['hourly_rate'], \ url=nn['url'])) tut_list.append(dict(rel='Maximum priced tutor', \ name=max_tut['name'], \ rate=max_tut['hourly_rate'], \ url=max_tut['url'])) tut_list.append(dict(rel='Minimum priced tutor', \ name=min_tut['name'], \ rate=min_tut['hourly_rate'], \ url=min_tut['url'])) example_tutor = dict(name=tutor_name, rate=hourly_rate, url=tutor_data['url']) html = """ <img src="data:image/png;base64,{}"> """ img_io = img_io.getvalue().encode('base64') img_io = html.format(img_io) return render_template("example_output.html", \ tutors=tut_list, \ example_tutor=example_tutor, \ sim_plot=img_io)
def main(): bol = False while True: print("^^^^^^^^^^^^^^^^^^^ ANIME RECOMMENDER ^^^^^^^^^^^^^^^^^^^\n") if bol: string = "Vuoi che ti suggerisca un altro anime ? - Premi 1\n" \ + "Vuoi sapere il genere di un altro anime? - Premi 2\n" \ + "Vuoi uscire? - Premi 3\n" else: string = "Konichiwa, cosa vuoi fare?\n" + "Vuoi che ti suggerisca un anime ? - Premi 1\n" \ + "Vuoi sapere il genere di un anime? - Premi 2\n" \ + "Vuoi uscire? - Premi 3\n" response = input(string) if response == '1': # RECOMMENDER ****************************************************************** name = '' score = '' genre = '' type_ = '' duration = '' episodes = '' source = '' print("Ti faro' delle domande per poterti suggerire un anime.") name = input( "Suggeriscimi il nome di un anime che hai apprezzato\n").lower( ) score = input( "Se dovessi valutarlo che voto gli daresti da 1 a 10?\n" ).lower() genre = input("Qual è il genere di questo anime?\n").lower() string = input( "Sai dirmi il tipo di questo anime? (Si o No)(se non sai cos'è il tipo digita 1)\n" ).lower() while string == '1': print( "Quando parliamo di tipo intendiamo se l'anime appartiene a una di queste categorie:\n" + "- TV : l'anime viene trasmesso ad episodi\n" + "- Movie : l'anime è un film\n" + "- ONA/OVA : l'anime è una puntata speciale di un anime o originale\n" ) string = input( "Ora sai dirmi qual è il tipo? (Si o No)(se non sai cos'è il tipo digita 1)\n" ).lower() if string == "si": type_ = input("Qual è il tipo?\n").lower() if type_ == 'tv' or type_.lower() == 'ona' or type_.lower( ) == 'ova': string = input( "Sai dirmi da quanti episodi è formato? (Si o No)\n" ).lower() if string == "si": episodes = input("Da quanti?\n").lower() string = input( "Sai dirmi quanto dura mediamente un episodio?\n").lower() if string == "si": duration = input("Quanto dura mediamente?\n").lower() elif type_ == 'movie': episodes = 1 string = input( "Sai dirmi anche quanto dura il film? (si o no)\n").lower( ) if string == "si": duration = input( "quanto dura mediamente? (esprimi la durata in minuti)\n" ).lower() string = input( "Sai dirmi l'origine di questo anime? (Si o No)(se non sai cos'è l'origine digita 1)\n" ).lower() while string == '1': print( "Quando parliamo di origine intendiamo se l'anime appartiene a una di queste categorie:\n" + "- Manga\n- Novel\n- Book \n- Radio\n- Picture book\n- Web Manga\n- Digital Manga\n- Original\n" ) string = input( "Ora sai dirmi qual è l'origine? (Si o No)(se non sai cos'è l'origine digita 1)\n" ).lower() if string == "si": source = input("Qual è?\n").lower() recommender.main(episodes, genre, type_, source, duration, name, score) print("\n") os.system("pause") bol = True print("\n") elif response == '2': print("Ti chiedero' un po' di cose. Inziamo...") name = input( "Qual è il nome dell'anime che vuoi classificare?\n ").lower() score = input( "Qual è lo score dell'anime che vuoi classificare?\n").lower() type_ = input( "Qual è il type dell'anime che vuoi classificare?(se non sai cos'è il tipo digita 1)\n" ).lower() while type_ == '1': print( "Quando parliamo di tipo intendiamo se l'anime appartiene a una di queste categorie:\n" + "- TV : l'anime viene trasmesso ad episodi\n" + "- Movie : l'anime è un film\n" + "- ONA/OVA : l'anime è una puntata speciale di un anime o originale\n" ) type_ = input( "Quindi, qual è il type dell'anime che vuoi classificare?(se non sai cos'è il tipo digita 1)\n" ).lower() episodes = input( "Quanti episodi ha l'anime che vuoi classificare?\n").lower() duration = input( "Quanto dura mediamente un episodio dell'anime che vuoi classificare?\n" ).lower() producers = input( "Qual è il produttore dell'anime che vuoi classificare?\n" ).lower() studios = input( "Qual è lo studio dell'anime che vuoi classificare?\n").lower( ) source = input( "Qual è l'origine dell'anime che vuoi classificare?" + " (se non sai cos'è l'origine di un anime tipo digita 1)\n" ).lower() while source == '1': print( "Quando parliamo di origine intendiamo se l'anime appartiene a una di queste categorie:\n" + "- Manga\n- Novel\n- Book \n- Radio\n- Picture book\n- Web Manga\n- Digital Manga\n- Original\n" ) source = input( "Quindi, qual è l'origine dell'anime che vuoi classificare?(se non sai cos'è l'origine " "digita 1)\n").lower() prediction_genre.predict_genre(name, score, type_, episodes, duration, producers, studios, source) print("\n") os.system("pause") bol = True print("\n\n") else: print("Sayonara") break
def main2(text): # converting to lowercase lower_case = text.lower() cleaned_text = re.sub("[?,.!" "']", " ", lower_case) # splitting text into words tokenized_words = cleaned_text.split() """"stop_words = ["i", "me", "my", "myself", "we", "our", "ours", "ourselves", "you", "your", "yours", "yourself", "yourselves", "he", "him", "his", "himself", "she", "her", "hers", "herself", "it", "its", "itself", "they", "them", "their", "theirs", "themselves", "what", "which", "who", "whom", "this", "that", "these", "those", "am", "is", "are", "was", "were", "be", "been", "being", "have", "has", "had", "having", "do", "does", "did", "doing", "a", "an", "the", "and", "but", "if", "or", "because", "as", "until", "while", "of", "at", "by", "for", "with", "about", "against", "between", "into", "through", "during", "before", "after", "above", "below", "to", "from", "up", "down", "in", "out", "on", "off", "over", "under", "again", "further", "then", "once", "here", "there", "when", "where", "why", "how", "all", "any", "both", "each", "few", "more", "most", "other", "some", "such", "no", "nor", "not", "only", "own", "same", "so", "than", "too", "very", "s", "t", "can", "will", "just", "don", "should", "now"]""" final_words = [] for word in tokenized_words: if word not in sw.words('english'): final_words.append(word) def listToString(s): # initialize an empty string str1 = " " return str1.join(s) def find_ngrams(n, a): # Split sentence into tokens. input_sequence = listToString(a) tokens = input_sequence.split() ngrams = [] for i in range(len(tokens) - n + 1): # Take n consecutive tokens in array. ngram = tokens[i:i + n] # Concatenate array items into string. ngram = ' '.join(ngram) ngrams.append(ngram) return ngrams ngrams = find_ngrams(3, final_words) analysis = {} for ngram in ngrams: blob = TextBlob(ngram) print('Ngram: {}'.format(ngram)) print('Polarity: {}'.format(blob.sentiment.polarity)) emotion_list = [] from os.path import dirname, join f = open(join(dirname(__file__), 'emotions.txt')) for line in f: if line: clear_line = line.replace("\n", '').replace(",", '').replace("'", '').strip() word, emotion = clear_line.split(':') if word in final_words: emotion_list.append(emotion) print(emotion_list) w = Counter(emotion_list) print(w) score = vl().polarity_scores(cleaned_text) a = score['neg'] b = score['pos'] print(score) bar = 1 am = 1 if (a > b): print("Negative Sentiment") if a > 0 and a <= 0.25: bar = 1 print("Level 1") am = r1.main(1) if a > 0.25 and a <= 0.5: bar = 2 print("Level 2") am = r1.main(2) if a > 0.5 and a <= 0.75: bar = 3 print("Level 3") am = r1.main(3) if a > 0.75 and a <= 1: bar = 4 print("Level 4") am = r1.main(4) elif a < b: print("Positive Sentiment") bar = 5 am = r1.main(5) else: print("Neutral Sentiment") bar = 5 am = r1.main(5) count = 0 lst = [] demo = [] if bar == 1 or bar == 2 or bar == 3 or bar == 4: print("\nWant to watch some movies\n") for i in am: # Splitting each line of the # IMDb data to scrape movies tmp = str(i).split('>') if len(tmp) == 3: lst.append(tmp[1][:-3]) if (count > 13): break count += 1 else: print("\nWant to watch some movies\n") for i in am: tmp = str(i).split('>') if len(tmp) == 3: lst.append(tmp[1][:-3]) if (count > 11): break count += 1 return lst
def main(text, listToReturn): # converting to lowercase lower_case = text.lower() # Removing punctuations # cleaned_text = lower_case.translate(str.maketrans('', '', string.punctuation)) cleaned_text = re.sub("[?,.!" "']", " ", lower_case) # splitting text into words tokenized_words = cleaned_text.split() """"stop_words = ["i", "me", "my", "myself", "we", "our", "ours", "ourselves", "you", "your", "yours", "yourself", "yourselves", "he", "him", "his", "himself", "she", "her", "hers", "herself", "it", "its", "itself", "they", "them", "their", "theirs", "themselves", "what", "which", "who", "whom", "this", "that", "these", "those", "am", "is", "are", "was", "were", "be", "been", "being", "have", "has", "had", "having", "do", "does", "did", "doing", "a", "an", "the", "and", "but", "if", "or", "because", "as", "until", "while", "of", "at", "by", "for", "with", "about", "against", "between", "into", "through", "during", "before", "after", "above", "below", "to", "from", "up", "down", "in", "out", "on", "off", "over", "under", "again", "further", "then", "once", "here", "there", "when", "where", "why", "how", "all", "any", "both", "each", "few", "more", "most", "other", "some", "such", "no", "nor", "not", "only", "own", "same", "so", "than", "too", "very", "s", "t", "can", "will", "just", "don", "should", "now"]""" # Removing stop words from the tokenized words list final_words = [] for word in tokenized_words: if word not in sw.words('english'): final_words.append(word) # NLP Emotion Algorithm # 1) Check if the word in the final word list is also present in emotion.txt # - open the emotion file # - Loop through each line and clear it # - Extract the word and emotion using split # 2) If word is present -> Add the emotion to emotion_list # 3) Finally count each emotion in the emotion list def listToString(s): # initialize an empty string str1 = " " return str1.join(s) def find_ngrams(n, a): # Split sentence into tokens. input_sequence = listToString(a) tokens = input_sequence.split() ngrams = [] for i in range(len(tokens) - n + 1): # Take n consecutive tokens in array. ngram = tokens[i:i + n] # Concatenate array items into string. ngram = ' '.join(ngram) ngrams.append(ngram) return ngrams ngrams = find_ngrams(3, final_words) analysis = {} for ngram in ngrams: blob = TextBlob(ngram) print('Ngram: {}'.format(ngram)) print('Polarity: {}'.format(blob.sentiment.polarity)) emotion_list = [] from os.path import dirname, join f = open(join(dirname(__file__), 'emotions.txt')) #f= open("emotions.txt","r").read() #with open('C:/Users/KIIT/Downloads/New folder/BrainRelief/app/src/main/python/emotions.txt', 'r') as file: for line in f: if line: clear_line = line.replace("\n", '').replace(",", '').replace("'", '').strip() word, emotion = clear_line.split(':') if word in final_words: emotion_list.append(emotion) print(emotion_list) w = Counter(emotion_list) print(w) score = vl().polarity_scores(cleaned_text) a = score['neg'] b = score['pos'] print(score) bar = 1 am = 1 if (a > b): print("Negative Sentiment") if a > 0 and a <= 0.25: bar = 1 print("Level 1") am = r1.main(1) if a > 0.25 and a <= 0.5: bar = 2 print("Level 2") am = r1.main(2) if a > 0.5 and a <= 0.75: bar = 3 print("Level 3") am = r1.main(3) if a > 0.75 and a <= 1: bar = 4 print("Level 4") am = r1.main(4) elif a < b: print("Positive Sentiment") bar = 5 am = r1.main(5) else: print("Neutral Sentiment") bar = 6 am = r1.main(5) count = 0 lst = [] demo = [] if bar == 1 or bar == 2 or bar == 3 or bar == 4: print("\nWant to watch some movies\n") for i in am: # Splitting each line of the # IMDb data to scrape movies tmp = str(i).split('>') if len(tmp) == 3: lst.append(tmp[1][:-3]) if (count > 13): break count += 1 else: print("\nWant to watch some movies\n") for i in am: tmp = str(i).split('>') if len(tmp) == 3: lst.append(tmp[1][:-3]) if (count > 11): break count += 1 if bar == 1: demo = l1.lev1(listToReturn) elif bar == 2: demo = l2.lev2(listToReturn) elif bar == 3: demo = l3.lev3(listToReturn) elif bar == 4: demo = l4.lev4(listToReturn) elif bar == 5: demo = l5.lev5(listToReturn) elif bar == 6: demo = l6.lev6(listToReturn) return lst, demo
def setUp(self): from recommender import main app = main({}) from webtest import TestApp self.testapp = TestApp(app)