def post(self, request): if request.method == "POST": form = MoodForm(request.POST) if form.is_valid(): try: form.save() return redirect('show') except: pass else: form = MoodForm() return render(request, 'index.html', {'form': form})
def post(self,request): if request.method == "POST": form = MoodForm(request.POST) if form.is_valid(): try: form.save() print("From index\post\sucess") return redirect('/show') except: pass else: print("From index\post\fail") form = MoodForm() return render(request,'index.html',{'form':form})
def post(self, request): if request.method == "POST": form = MoodForm(request.POST) print("Hii") if form.is_valid(): try: form.save() print('form saved') print(form.data) print(type(form.data)) return redirect('/show') except: pass else: print('form did not saved') form = MoodForm() return render(request, 'index.html', {'form': form})
def post(self, request): if request.method == "POST": form = MoodForm(request.POST) if form.is_valid(): try: obj = form.save(commit=False) print(obj) TimeDate = datetime.datetime.now() obj.time = TimeDate return redirect('/show') except: pass else: form = MoodForm() return render(request, 'index.html', {'form': form})
def post(self, request): form = MoodForm(request.POST) print('Printing the form data...\n', form.data) if form.is_valid(): print("Form is valid") try: obj = form.save(commit=False) mood_dict = form.data print('Printing the value of mood_dict = form.data...\n', mood_dict) expression = mood_dict['message'] print('Printing the message...\n', expression) positive_keywords = [ "great", "happy", "amazing", "fantastic", "like", "love", "good", "awesome", "cool", "best", "exciting" ] negative_keywords = [ "disgusting", "boring", "sad", "depressing", "hate", "shit", "bad", "terrible", "horrible", "annoying", "worst" ] expression = ''.join(c for c in expression if c not in punctuation) words = expression.strip().lower().split() print('Printing the words in the text as a list...\n', words) positive_mood_counter = 0 negative_mood_counter = 0 mood = 'Good' for word in words: if word in positive_keywords: positive_mood_counter += 1 elif word in negative_keywords: negative_mood_counter += 1 else: continue if positive_mood_counter >= negative_mood_counter: mood = 'Good' print('The mood is "{}"'.format(mood)) elif negative_mood_counter > positive_mood_counter: mood = 'Bad' print('The mood is "{}"'.format(mood)) time = datetime.now() obj.user = request.user obj.result = mood obj.time = time obj.save() print("The mood was saved in the database") return redirect('/show') except: print("The mood did not save in the database") pass else: form = MoodForm() return render(request, 'index.html', {'form': form})
def post(self, request): if request.method == "POST": form = MoodForm(request.POST) if form.is_valid(): try: obj = form.save(commit=False) p = form.data print(p) print(obj) ##################################### MOVIE RATING BY REVIEWS ####################################################### positive_keywords = [ "best", "great", "owsome", "fantastic", "mindblowing", "amazing", "marvellous", "nice", "super", "good", "lovely", "love", "smashing", "cool", "marvellous", "smashing", "superb", "" ] negative_keywords = [ "bad", "wrost", "flop", "boaring", "not good", "disguasting", "bakwas", "faltu", "complicated", "notbad" ] review = [] print(p['name1'], p['name2'], p['name3'], p['name4'], p['name5']) a = p['name1'] b = p['name2'] c = p['name3'] d = p['name4'] e = p['name5'] user1 = a split = user1.split() review.append(split) user2 = b split = user2.split() review.append(split) user3 = c split = user3.split() review.append(split) user4 = d split = user4.split() review.append(split) user5 = e split = user5.split() review.append(split) Pos_counter = 0 Neg_counter = 0 for each in review: print(each) for word in each: if word in positive_keywords: Pos_counter += 1 elif word in negative_keywords: Neg_counter += 1 else: pass print("Positive counter is", Pos_counter) print("Negative counter is", Neg_counter) print( "--------------------------------------------------------------------------------------------------------------" ) if Pos_counter >= Neg_counter: print("Result:") total = Pos_counter per = float(total) * (100 / 5) print("Percentage is: ", per) print("Good movie go for it") print( "-----------------------------------------------------------------------------------------------------------" ) print("Rating for movie") for i in range(Pos_counter): print("✯ ", end="") obj.star = Pos_counter obj.opinion = 'Go for Movie' obj.result = per obj.save() else: total = Pos_counter per = float(total) * (100 / 5) print("Percentage is: ", per) print("Dont go for movie") print( "-----------------------------------------------------------------------------------------------------------" ) for i in range(Pos_counter): print("Rating for movie") print("✯ ", end="") print("\n") obj.result = per obj.star = Pos_counter obj.opinion = 'Dont go for Movie' obj.save() print("-------") return redirect('/show') except: pass else: form = MoodForm() return render(request, 'index.html', {'form': form})