def settings(): if "user" in session: #checks to see if logged in if request.method == 'POST': topicso = [] #getting and storing new topics for top in topics.getTopics(): idnum = top["idNum"] topicVal = 'topic' + str(idnum) topic = request.form.get(topicVal) if topic is not None: topicso.append(idnum) accountInfo.setTopics(session["user"], topicso) return render_template('settings.html', signedIn=isloggedIn(), topicsInput=topics.getTopics(), saved=True, currTopics=accountInfo.getTopics( session["user"])) else: return render_template('settings.html', signedIn=isloggedIn(), topicsInput=topics.getTopics(), currTopics=accountInfo.getTopics( session["user"])) else: return render_template('signin.html', signedIn=isloggedIn())
def validateInterestedTopics(objectCollection): topics = Tpc.getTopics() if len(objectCollection) == 0: returnErrorMessage("You did not select any interested topic.") for topic in objectCollection: if topic not in topics: returnErrorMessage("Your topic is invalid.")
def rally(): if "user" in session: #checks to see if logged in if request.method == 'POST': name = request.form["name"] description = request.form["description"] address = {} address["street"] = request.form["street"] address["city"] = request.form["city"] address["state"] = request.form["state"] address["zip"] = request.form["zip"] imageAddress = request.form["imageAddress"] link = request.form["link"] eventDate = request.form["eventDate"] topic = request.form["topics"] creator = session["user"] idIn = rallydb.getRallyCount() #add rally to list in topics # topics.addRally(topic, idIn) #add rally to rally db rallydb.setupRally(idIn, name, description, address, imageAddress, link, eventDate, topic, creator) #send rally stuff to all participants #checks if rally is close enough addressOfRally = address["street"] + ', ' + address[ "city"] + ", " + address["state"] + " " + address["zip"] accts = accountInfo.getAccounts() for act in accts: for t in act["topics"]: tStr = str(t) if tStr == topic: distanceStr = calc_distances.get_distance( accountInfo.getAddress(act["username"]), addressOfRally) distanceFloat = float(distanceStr[:-2]) if (distanceFloat < 30): #only texts if within 30 miles msg = "\nRelevent Rally Added!\n" + "Event: " + name + "\n" + "Address: " + addressOfRally + "\nDate: " + eventDate + "For more info check RALLY!\n" texting.send_message(msg, act["phone"]) return redirect(url_for("rallySuccess")) else: return render_template('rally.html', signedIn=isloggedIn(), topics=topics.getTopics()) else: return render_template('signin.html', signedIn=isloggedIn())
def buildTopics(): import topics as Tpc topics = Tpc.getTopics() print(topics) conn = cx_Oracle.connect('TW/TWBooX@localhost:1521', encoding="UTF-8") cursor = conn.cursor() querystring = '''delete from topics''' cursor.execute(querystring) for i in range(0, len(topics)): querystring = '''insert into topics values({id},'{topic}')'''.format( id=i + 1, topic=topics[i].replace("'", "''")) print(querystring) cursor.execute(querystring) conn.commit()
def storeQueryForUser(): search_query = request.args.get('query') search_query = spellchecker(search_query) if search_query == "": return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' } email = request.args.get('email') print(email) print("sq", search_query, request.args) if isQ.predict_question(search_query): answer = textinput.getAnswer(search_query) if answer is not None: query_topics = topics.getTopics(search_query, answer) print("sending", search_query, answer, query_topics) db.search_query(email, search_query, answer, query_topics) else: print("no assistant response:", search_query) else: print("not a question:", search_query) return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def signup(): if request.method == 'POST': username = request.form['username'] username = username.lower() password = request.form['password'] repeatPass = request.form['repeatPassword'] fname = request.form['fname'] lname = request.form['lname'] phone = request.form['phone'] email = request.form['email'] address = {} address["street"] = request.form["street"] address["state"] = request.form["state"] address["city"] = request.form["city"] address["zip"] = request.form["zip"] #get info for default topics topicso = [] for top in topics.getTopics(): idnum = top["idNum"] topicVal = 'topic' + str(idnum) topic = request.form.get(topicVal) if topic is not None: topicso.append(idnum) if (password != repeatPass): #check for repeat password try: return render_template('signup.html', ERROR=True, ERROR_MSG="Passwords must be the same", signedIn=isloggedIn()) except: return "Error in repeat password" elif (accounts.checkDuplicateUsername(username) ): #check for username alreadu in db try: return render_template( 'signup.html', ERROR=True, ERROR_MSG="Duplicate: Choose a new username", signedIn=isloggedIn()) except: return "Error in duplicate username" else: #add account to db accounts.addAccount(username, password) accountInfo.setupAccount(username, phone, email, topicso, fname, lname, address) try: return signupSuccess() except: return 'There was an error searching your task' else: #page refreshed/ reloaded so will output the template. return render_template('signup.html', ERROR=False, ERROR_MSG="No Error", signedIn=isloggedIn(), topicsInput=topics.getTopics())
def topicsPage(): return render_template('topicsPage.html', signedIn=isloggedIn(), topicList=topics.getTopics())