def home(): if (EMAIL == ""): return redirect("/login") if request.method == 'POST': if request.form['posOrNeg'] == 'Positive': is_descending = True else: is_descending = False client = dbClient(config) client.set_handle(HANDLE) twitter_account_data = twitterAccountData(client) top_five_tweets = client.get_top_five_tweets(descending=is_descending) top_five_bad_words = client.get_top_five_bad_words() client.close_connection() return render_template("home.html", Overview=twitter_account_data, tweets=top_five_tweets, phrasesToAvoid=top_five_bad_words, tweetWindows=tweetWindows) else: client = dbClient(config) client.set_handle(HANDLE) twitter_account_data = twitterAccountData(client) top_five_tweets = client.get_top_five_tweets(descending=True) top_five_bad_words = client.get_top_five_bad_words() client.close_connection() return render_template("home.html", Overview=twitter_account_data, tweets=top_five_tweets, phrasesToAvoid=top_five_bad_words, tweetWindows=tweetWindows)
def history(): if request.method == 'POST': if request.form.get('ascending'): is_descending = False else: is_descending = True client = dbClient(config) client.set_handle(HANDLE) all_tweets = client.get_tweets_by_x(request.form['sortBy'], is_descending) client.close_connection() return render_template("history.html", tweets=all_tweets) else: client = dbClient(config) client.set_handle(HANDLE) all_tweets = client.get_all_tweets(descending=True) client.close_connection() return render_template("history.html", tweets=all_tweets)
def signIntoAccount(): if request.form['submitType'] == "Create Account": return redirect("/signup") elif request.form['submitType'] == "Log In": # hashing based on code from https://dev.to/brunooliveira/flask-series-part-10-allowing-users-to-register-and-login-1enb client = dbClient(config) email = request.form['email'] password = request.form['password'] checkPassword = client.run_query("select password from ogAccount where email = '" + email + "'") stored = checkPassword[0][0] salt = stored[:64] stored = stored[64:] pwdhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), salt.encode('ascii'), 100000) pwdhash = binascii.hexlify(pwdhash).decode('ascii') pwdhash = str(pwdhash) print(stored) print(pwdhash) print("HIT1") if (pwdhash == stored): print("HIT") global EMAIL global HANDLE EMAIL = email HANDLE = client.run_query("select defaultAccount from ogAccount where email = '" + EMAIL +"'") HANDLE = HANDLE[0][0] print(HANDLE) return redirect("/home") else: return redirect("/login?error=" + "Invalid%20Account")
def deleteAcctAndRedirectToLogin(): client = dbClient(config) client.set_handle(HANDLE) client.set_email(EMAIL) client.run_query("delete from ogAccount where email = '" + EMAIL +"'") return redirect("/login")
def updateSettings(): client = dbClient(config) client.set_handle(HANDLE) client.set_email(EMAIL) email = request.form['email'] password = request.form['password'] confirmPassword = request.form['confirmPassword'] salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii') pwdhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), salt, 100000) pwdhash = binascii.hexlify(pwdhash) hashed = (salt + pwdhash).decode('ascii') hashed = str(hashed) # Check Errors if (password != confirmPassword): return redirect("/settings?error=" + "Passwords%20Don%27t%20Match") if (not re.search("^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$", email)): return redirect("/settings?error=" + "Invalid%20Email") # Run Queries if (email != ""): query = "update ogAccount set email = '%s' where email = '%s'" % (email, EMAIL) if (password != "" & confirmPassword != ""): query = "update ogAccount set password = '******' where email = '%s'" % (hashed, EMAIL) if (email != "" & password != "" & confirmPassword != ""): query = "update ogAccount set email = '%s', password = '******' where email = '%s'" % (EMAIL, hashed, EMAIL) client.run_query(query) return redirect('/settings?res=' + 'Done!')
def updatepreferences(): client = dbClient(config) client.set_handle(HANDLE) client.set_email(EMAIL) query = "update ogAccount set defaultAccount = '%s', defaultWindow = '%s' where email = '%s'" % (request.form['account'], request.form['window'], EMAIL) client.run_query(query) return redirect('/preferences?res=' + 'Done!')
def preferences(): client = dbClient(config) client.set_handle(HANDLE) client.set_email(EMAIL) account = client.get_accounts() res = request.args.get('res', " ") # request.form['name'] return render_template("preferences.html", accounts=account, tweetWindows=tweetWindows, res=res)
def tweet(tweetID:str): if request.method == 'POST': temp_window = request.form['temp_window'] client = dbClient(config) client.set_handle(HANDLE) tweet = client.get_tweet(tweetID) client.add_follow_data_to_tweet_with_new_window(tweet, temp_window) return render_template("tweet.html", tweet=tweet, timeWindows=tweetWindows) else: client = dbClient(config) client.set_handle(HANDLE) tweet = client.get_tweet(tweetID) client.add_follow_data_to_tweet(tweet) return render_template("tweet.html", tweet=tweet, timeWindows=tweetWindows)
def history_search(): if request.method == 'POST': keyword_text = request.form['keywords'] keywords = [word.strip() for word in keyword_text.split(",")] client = dbClient(config) client.set_handle(HANDLE) all_tweets = client.get_tweets_with_keywords(keywords) client.close_connection() return render_template("history.html", tweets=all_tweets)
def fakeFunctionHandler(): client = dbClient(config) client.set_handle(HANDLE) client.set_email(EMAIL) if 'tweet' in request.form: def ran_num(): return random.randint(1,99) tweet = request.form['tweet'] currentTime = time.strftime('%Y-%m-%d %H:%M:%S') client.run_insert_query("insert into tweet (handle, content, datetime, retweet, favorites, replies) values ('%s', '%s', '%s', %d, %d, %d);" % (HANDLE, tweet, currentTime, ran_num(), ran_num(), ran_num())) if 'handle' in request.form: follower_handle = request.form['handle'] gain_or_loss = request.form['gainOrLoss'] client.handle_follow_event(follower_handle, gain_or_loss) return render_template("fakeFunction.html")
def signUpHandler(): client = dbClient(config) email = request.form['email'] password = request.form['password'] check_pass = request.form['confirmPassword'] handle = request.form['handle'] salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii') pwdhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), salt, 100000) pwdhash = binascii.hexlify(pwdhash) hashed= (salt + pwdhash).decode('ascii') hashed = str(hashed) if password == check_pass: client.create_twitter_account(handle, email, hashed, email) #TODO: Change with api integration query = '''insert into ogAccount values ("{0}", "{1}", "{2}", 'hour');'''.format(email, hashed, handle) client.run_insert_query(query) return redirect("/login") else: return redirect("/signup?error=" + "Passwords%20Don%27t%20Match")
from app import app from flask import render_template # from app.SpellCrawler.spellcrawler import findMisspellingsForTopPages from app.dbClient import dbClient from app.config import config import mysql.connector as conn client = dbClient(config) @app.route('/') @app.route('/home') def index(): query = "SELECT DISTINCT Website.link, Suggestions.word, Suggestions.suggestion from Suggestions inner join Website on Website.id = Suggestions.relatedSite;" misspelledWords = client.run_query(query) print(misspelledWords) return render_template("index.html", misspelled=misspelledWords)