Exemplo n.º 1
0
def sentiment(site='Amazon.com'):
    table = table_name(str(site))
    print table

    # For Fabmart.com (old)
    if not table.__contains__('('):
        c, conn = connection()

        count_row = """SELECT COUNT(total_senti) FROM %s""" % table
        c.execute(count_row)
        row = c.fetchone()[0]

        senti_sum = """SELECT SUM(total_senti) FROM %s""" % table
        c.execute(senti_sum)
        senti = c.fetchone()[0]

        try:
            avg = senti / row
        except TypeError:
            avg = 0

        c.close()
        conn.close()
        gc.collect()

        return (row, avg)
Exemplo n.º 2
0
def update_user_tracking():
    try:
        completed = str(
            request.agrs['completed']
        )  # this arg of ['completed'] is generated in HTML template
        if completed in str(
                TOPIC_DICT.values()
        ):  # url string passed from agr of completed is in TOPIC_DICT url values
            client_name, settings, tracking, rank = user_info()
            if tracking == None:
                tracking = completed
            else:
                if completed not in tracking:
                    tracking = tracking + "," + completed
            c, conn = connection()
            c.execute(
                "SELECT * FROM users SET tracking = (%s) WHERE username = (%s)",
                (
                    thwart(tracking),
                    thwart(client_name),
                ))
            conn.commit()
            c.close()
            conn.close()
            gc.collect()
            client_name, settings, tracking, rank = user_info()
        else:
            pass
    except Exception as e:
        pass
Exemplo n.º 3
0
def register():	
	try:
		form = RegisterForm(request.form)
		if request.method == "POST" and form.validate():

			username = form.username.data
			email = form.email.data
			password = sha256_crypt.encrypt((str(form.username.data)))
			c,conn = connection()
			x = c.execute("SELECT * FROM users WHERE username = (%s)", (thwart(username),))
			if int(x)>0:
				flash("that username is already taken, please try another!")
				return render_template("register.html", form = form)
			else:
				c.execute("INSERT INTO users (username, password, email, tracking) VALUES (%s, %s, %s, %s)", (thwart(username), thwart(password), thwart(email), thwart("/introductions/"),))
				#c.execute("INSERT INTO users (username, password, email, tracking) VALUES {0},{1},{2},{3}".format(thwart(username), thwart(password), thwart(email), thwart("/introductions/")))

				conn.commit()
				flash("thanks for registering!")
				c.close()
				conn.close()
				gc.collect()

				session['logged_in'] = True #session is a dictionary to track user action
				session['username'] = username
				
				return redirect(url_for('dashboard'))

		return render_template("register.html", form = form)
	except Exception as e:
		return (str(e))
Exemplo n.º 4
0
def dashboard():
   try:
     c, conn = connection()
     return("okay")
   except Exception as e:
     return(str(e))
   query = "SELECT * from tbl_User"
   c.execute(query)
   data = c.fetchall()
   conn.close()

   return render_template("dashboard.html",data=data)
Exemplo n.º 5
0
def user_info():
	try:
		client_name=(session['username'])
		guest=False
	except:
		guest=True
		client_name="Guest"
	if not guest:
		try:
			c,conn = connection()
			c.execute("SELECT * FROM users WHERE username = (%s)", (thwart(client_name),))
			data = c.fetchone()
			settings, tracking, rank = data[4], data[5], data[6]
		except Exception as e:
			pass
	else:
		settings, tracking, rank = [0,0], [0,0], [0,0]
	return client_name, settings, tracking, rank
Exemplo n.º 6
0
def review_sentiment_update(
        review):  #review[table_name,website_name,review_head,review_data]

    review_head = TextBlob(review[2].decode('utf-8'))
    review_data = TextBlob(review[3].decode('utf-8'))

    review_head_senti = review_head.sentiment.polarity * 100
    review_data_senti = review_data.sentiment.polarity * 100

    total_senti = review_head_senti + review_data_senti

    c, conn = connection()

    c.execute(
        "INSERT INTO %s" % review[0] +
        " (webname,review_head,review_data,review_head_senti,review_data_senti,total_senti) VALUES (%s,%s,%s,%s,%s,%s)",
        (str(review[1]), str(review[2]), str(
            review[3]), review_head_senti, review_data_senti, total_senti))
    conn.commit()

    c.close()
    conn.close()
    gc.collect()
Exemplo n.º 7
0
def login():
	error = ''
	try:
		c, conn = connection()
		if request.method == "POST":
			data = c.execute("SELECT * FROM users WHERE username = (%s)", (thwart(request.form['username']),))
			data = c.fetchone()[2]


			if sha256_crypt.verify(request.form['password'],data):
				session['logged_in'] = True
				session['username'] = request.form['username']
				flash("You are logged in!")
				return redirect(url_for("dashboard"))
				
			else:
				error = "Invalid credentials. Try again."
		gc.collect()
		return render_template("login.html",error=error) ##if login failed, it'll goto here!
	except Exception as e:
		error = "Invalid credentials. Try again."
		#flash(e)
		return render_template("login.html",error = error)
Exemplo n.º 8
0
from csv import writer
from csv import reader
import requests
import lxml
import gc

with open('webrate.csv', 'rb') as f:
    reader = reader(f)
    links = list(reader)

for website in links:
    link = website[1] + '-sort-MsDate-order-d'
    table = table_name(website[0])
    review_data_list = []

    c, conn = connection()

    review_r = """SELECT * FROM %s""" % table
    c.execute(review_r)
    review = c.fetchall()
    for single_review in review:
        review_data_list.append(single_review[2])

    c.close()
    conn.close()
    gc.collect()

    with requests.session() as s:
        page = s.get(link)
        tree = html.fromstring(page.content)