From 75048d23f49a248c1c46badd4deaeade52ce0f22 Mon Sep 17 00:00:00 2001 From: tonmona2 Date: Mon, 10 Apr 2017 21:14:19 -0400 Subject: [PATCH 1/4] add a testing route --- api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index fc963ee..0bd4e88 100644 --- a/api.py +++ b/api.py @@ -23,8 +23,11 @@ api = tweepy.API(auth) +@app.route('/test') +def test(): + return "Test" -@app.route('/twitter/') +@app.route('/twitter') def Go_bots(): args = request.args article_links_array = args.getlist('article_links') From a86da4649194b1959c672d7f56a8aa63e33d2750 Mon Sep 17 00:00:00 2001 From: tonmona2 Date: Mon, 10 Apr 2017 21:52:17 -0400 Subject: [PATCH 2/4] Deployment experimentation and add limit counter --- api.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/api.py b/api.py index 0bd4e88..f615bec 100644 --- a/api.py +++ b/api.py @@ -10,14 +10,14 @@ app = Flask(__name__, template_folder="mytemplate") -# Authentication +# Keys t_consumerkey= 'ONoYgdpRdkIj592dVQJi52Qsg' t_secretkey= 'hn9y9Y7SBK5tiHWMVUKn6PRbUBUANjUX1aXcD9vwrpoTBFp8FJ' access_tokenkey='846743565904564224-We0haZK8x9XomN18ITn9cSxqlYwouX5' access_tokensecret='ValzlTvpS0Gq2SJAksUvvfyxm9N3a5o8dhSLJJrZzS6Ex' - +#Authentication auth = tweepy.OAuthHandler(t_consumerkey, t_secretkey) auth.set_access_token(access_tokenkey, access_tokensecret) @@ -29,16 +29,21 @@ def test(): @app.route('/twitter') def Go_bots(): + ## take all arguments args = request.args article_links_array = args.getlist('article_links') hashtags_array = args.getlist('hashtags') macro_link = args['macro_link'] tweet_text = args['tweet_text'] + + #add counter for number of tweets + counter = 2 - + # create empty array search_result_article = [] search_result_hashtag = [] + # search through twitter by article name for article in article_links_array: try: @@ -47,29 +52,40 @@ def Go_bots(): except Exception as e: print e + return jsonify({"x": search_result_article}) + # search through twitter by hastag for hashtag in hashtags_array: search_result_hashtag.append(api.search('#'+hashtag)) all_tweets_text = [] + #takes the name of the users tha tweets the articles and contacts them for tweets_a in search_result_article: for t in tweets_a: + if counter ==0: + break handle = "@" + t.user.screen_name m_a = handle + " " + macro_link all_tweets_text.append(m_a) s = api.update_status(m_a) # nap = randint(1, 60) - time.sleep(50) - + time.sleep(5) + counter-=1 + # reset counter + counter = 2 + + #takes the name of the users tha tweets the hashtags and contacts them for tweets in search_result_hashtag: for tweet in tweets: + if counter ==0: + break handle = "@" + tweet.author.screen_name m = handle + " " + macro_link all_tweets_text.append(m) s = api.update_status(m) - nap = randint(1, 60) - time.sleep(50) - + # nap = randint(1, 60) + time.sleep(5) + counter-=1 return jsonify({"tweets": all_tweets_text}) From 48041b4936ad633e7c2d793d8602b13fc2c72516 Mon Sep 17 00:00:00 2001 From: tonmona2 Date: Mon, 10 Apr 2017 21:55:30 -0400 Subject: [PATCH 3/4] Update api.py --- api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api.py b/api.py index f615bec..4ea6600 100644 --- a/api.py +++ b/api.py @@ -52,13 +52,14 @@ def Go_bots(): except Exception as e: print e - return jsonify({"x": search_result_article}) - + # search through twitter by hastag for hashtag in hashtags_array: search_result_hashtag.append(api.search('#'+hashtag)) all_tweets_text = [] + return jsonify({"x": search_result_hashtag}) + #takes the name of the users tha tweets the articles and contacts them for tweets_a in search_result_article: for t in tweets_a: From 848c5f0157523f5dfa6ae8c891c9f0cbb19b9f5f Mon Sep 17 00:00:00 2001 From: tonmona2 Date: Mon, 10 Apr 2017 22:01:13 -0400 Subject: [PATCH 4/4] Add exception to hashtags append --- api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 4ea6600..37dcfa2 100644 --- a/api.py +++ b/api.py @@ -55,7 +55,11 @@ def Go_bots(): # search through twitter by hastag for hashtag in hashtags_array: - search_result_hashtag.append(api.search('#'+hashtag)) + try: + search_result_hashtag.append(api.search('#'+hashtag)) + except Exception as e: + print e + all_tweets_text = [] return jsonify({"x": search_result_hashtag})