Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documented 2 functions #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions streamtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,24 @@

app = Flask(__name__)

"""
hello()

returns: json file with 'hello' and 'world' in it

"""
@app.route('/',methods=['GET'])
def hello():
return jsonify({'hello':'world'})

#-------------TRIGGER------------------------

@app.route('/triggertweets',methods=['GET'])
"""
triggertweets()

returns: json file with 'triiger' and 'started' in it
"""
def triggertweets():
key = request.args['keyword']
if key==None:
Expand All @@ -64,17 +74,17 @@ def get_tweets_from_db():
key = request.args['keyword']
offset = int(request.args.get('offset',0))
limit = int(request.args.get('limit',10))

name = request.args.get('name',None)
screenname = request.args.get('screen_name',None)
retweet_count = int(request.args.get('retweet_count',-1))
reply_count = int(request.args.get('reply_count',-1))
favorite_count = int(request.args.get('favorite_count',-1))
language = request.args.get('lang',None)








filters = {'keyword':key}
Expand Down Expand Up @@ -107,7 +117,7 @@ def get_tweets_from_db():
filters['lang'] = language
next_url += '&lang=' + language
prev_url += '&lang=' + language

sort_by = request.args.get('sort_by',None)
order_by = request.args.get('order','ASC');
if sort_by==None:
Expand All @@ -117,7 +127,7 @@ def get_tweets_from_db():
else:
next_url += '&sort_by=' + sort_by
prev_url += '&sort_by=' + sort_by

order = 0
if(order_by=='ASC'):
order = 0
Expand Down Expand Up @@ -163,7 +173,7 @@ def get_tweets_from_db():
else:
query = tweets.find(filters).sort(sort_by,pymongo.DESCENDING)


starting_id = query
try:
last_id = starting_id[offset]['_id']
Expand All @@ -175,9 +185,9 @@ def get_tweets_from_db():
filters['_id'] = {'$gte':last_id}
else:
filters['_id'] = {'$lte':last_id}

s = []

try:
count = 0;
full_find = query
Expand Down Expand Up @@ -243,15 +253,15 @@ def downloadtweets():
output.headers["Content-type"] = "text/csv"
return output
#return jsonify(ans)




#----------------TWEEPY STREAM LISTENER----------------------------


class StdOutListener(StreamListener):

count = 0
keyword = ""
max_tweets = 0
Expand All @@ -264,7 +274,7 @@ def __init__(self,key, max_tweets):
def on_data(self,data):

obj = json.loads(data)

tweet = {}
tweet['keyword'] = self.keyword

Expand All @@ -276,7 +286,7 @@ def on_data(self,data):
tweet['reply_count'] = obj['reply_count']
tweet['favorite_count'] = obj['favorite_count']



#print(tweet['created_at'])

Expand Down