Skip to content

Commit

Permalink
add answer insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
vanita5 committed Nov 16, 2014
1 parent 7b0c282 commit a8418df
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
39 changes: 33 additions & 6 deletions webForm/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from contextlib import closing
from flask import Flask, render_template, request, redirect, g


# #################
# INITIALIZATION #
##################

# init tweepy
try:
auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret)
Expand All @@ -20,6 +25,10 @@
app = Flask(__name__)


###############
# FLASK BLOCK #
###############

@app.before_request
def before_request():
g.db = connect_db()
Expand Down Expand Up @@ -110,9 +119,14 @@ def insert_question(tweet_id, question, timestamp):
g.db.commit()


###############
# CLASS BLOCK #
###############
def insert_answer(q_id, answer, tweet_id, timestamp):
with app.app_context():
g.db = connect_db()
g.db.execute('INSERT INTO answers(q_id, answer, tweet_id, timestamp)\
VALUES (?, ?, ?, ?)',
[q_id, answer, tweet_id, timestamp])
g.db.commit()


def get_since_id():
try:
Expand All @@ -127,8 +141,11 @@ def save_since_id(since_id):
f.write(str(since_id))


class AnswerDownloader(threading.Thread):
###############
# CLASS BLOCK #
###############

class AnswerDownloader(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.daemon = True
Expand All @@ -142,9 +159,19 @@ def run(self):
mentions = twitter.mentions_timeline()

for i in range(len(mentions) - 1, -1, -1):
print mentions[0].text
print mentions[i].text

tweet_id = mentions[i].id
timestamp_utc = calendar.timegm(mentions[i].created_at.utctimetuple())
q_id = mentions[i].in_reply_to_status_id

answer = mentions[i].text
my_screen_name = twitter.me().screen_name
answer = answer.replace('@' + my_screen_name + ' ', '')

insert_answer(q_id, answer, tweet_id, timestamp_utc)
if i == 0:
save_since_id(mentions[0].id)
save_since_id(mentions[i].id)

except Exception as e:
print e
Expand Down
5 changes: 4 additions & 1 deletion webForm/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
font-size:1rem;
line-height:2rem;
position:relative;
transition:0.5s;
-webkit-transition: all 1s ease-out; /* Firefox */
-moz-transition: all 1s ease-out; /* WebKit */
-o-transition: all 1s ease-out; /* Opera */
transition: all 1s ease-out; /* Standard */
}

#forkongithub a:hover {
Expand Down

0 comments on commit a8418df

Please sign in to comment.