Пример #1
0
def getTweets():
    global user
    global startDate
    global endDate

    num_tweets_label.place(x=100, y=350)
    num_tweets_box.place(x=250, y=350)
    tweets_box.place(x=90, y=400)
    newSearchBtn.place(x=230, y=550)

    #prevent user from pressing search button
    runSearchBtn.config(state="disabled")

    user = usernameBox.get()
    start = startDateBox.get()
    end = endDateBox.get()

    tweets = get_tweets(user, start, end)

    num_tweets_box.insert(0, len(tweets))

    for tweet in tweets:
        char_list = [
            tweet[j] for j in range(len(tweet))
            if ord(tweet[j]) in range(65536)
        ]
        tweet = ''
        for j in char_list:
            tweet = tweet + j
        tweets_box.insert(
            END, "-----------------------------------------\n" + tweet +
            "\n-----------------------------------------\n\n")
Пример #2
0
def send_message(type):
    msg = ""
    if type == 1:
        msg = "Hello Buddy hope you doing well :) I m here to help you before your flight\nSo which airport we are going today?"
    elif type == 20:
        msg = "Sorry Buddy but I currently do not support this airport, see you soon bye!"
    elif type == 21:
        msg = "Have a nice trip to Dubai Internatinal Airport, What is your concern just simply type, I can help you with following: \nMy flight\ntime\nweather\ntraffic"
    elif type == 31:
        data = airport_api.getRequest("time")
        msg = airport_api.parseRequest(data, "time")
        msg1 = "\nThank you for talking with me :) if you want anything else simply type"
        msg = msg + msg1
    elif type == 41:
        data = airport_api.getRequest("weather")
        msg = airport_api.parseRequest(data, "weather")
        msg1 = "\nThank you for talking with me :) if you want anything else simply type"
        msg = msg + msg1
    elif type == 51:
        msg = twitter_api.get_tweets("dubai traffic jam @waze")
        msg1 = "\nThank you for talking with me :) if you want anything else simply type"
        msg = msg + msg1
    elif type == 91:
        msg = "See you soon Buddy, bye!"
    elif type == 61:
        msg = "Sorry Buddy but I currently do not support flight info :( but I'm learning now that skills!"

    else:
        msg = "Wait wait, I am not so smart I coudn't understand you but I am learning ;)"

    return msg
Пример #3
0
def display_tweets(userName):
    if userName == "anku94":
        tweets = []
        tweets.append("RT @User1: #Abc #def tweet first");
        tweets.append("RT @User2: #NewHashTag #coolShitBrah tweet first");
        tweets.append("RT @User3: #NewHashTag #coolShitBrah tweet first");
        tweets.append("RT @User4: @hiianubhav @kansal.k #NewHashTag #coolShitBrah tweet first");
        return jsonify({'tweets': tweets})

    resp = twitter_api.get_tweets(userName)

    if resp['data']:
        return jsonify({'tweets': resp['data']})
    else:
        return jsonify({'tweets': None, 'error': resp['error']}), 404
Пример #4
0
def index():
    if request.method == "GET":
        return render_template("index.html", button_name="Go!")

    else:
        # get data from page
        user_input = html.escape(request.form['handle'])
        handle = "@" + user_input
        saved_dict = eval(request.form['lastUserDict'])

        if request.form['lastUser'] != user_input or user_input == "" or saved_dict == {}:
            # user entered new handle
            try:
                tweet_list = get_tweets(handle)
                saved_dict = get_dict(tweet_list)
                fake_tweet = gen_markov_tweet(saved_dict)

            except TweepError as err:
                # invalid or private handle

                if str(err) == "User is protected":
                    fake_tweet = "Error! User is private."
                else:
                    fake_tweet = "User not found! Please try another handle."

                saved_dict = {}

            except ValueError:
                # empty handle
                fake_tweet = "Please enter a handle."
                saved_dict = {}
        else:
            # user re-entered handle - use saved dict
            fake_tweet = gen_markov_tweet(saved_dict)

        return json.dumps({"handle": user_input, "tweet": fake_tweet, "saved_dict": str(saved_dict)})
Пример #5
0
    "SpaceX",
    "NatGeo",
    "NASA",
]

if __name__ == "__main__":
    logger = get_logger(home, "retweeter")
    logger.info("Setting up api connection...")
    api = setup_api(home)
    user = api.me()
    logger.info(
        "Name: {0}\nLocation: {1}\nFriends: {2}\nFollowers: {3}\n".format(
            user.name, user.location, user.friends_count,
            user.followers_count))
    while 1:
        now = arrow.now()
        new_tweets = get_tweets(api, relevant_accounts, logger)
        for tweet in new_tweets:
            try:
                logger.info("Retweeting: " + tweet.text)
                tweet_message = tweet.retweet()
                break
            except:
                continue
        else:
            logger.warning("No relevant tweets to retweet")
        if now.time().hour > 23 or now.time().hour < 7:
            logger.warning("Time to go to sleep")
            break
        sleep(14400)
#!/usr/bin/env python

import json
import os
import google_api
import twitter_api

# enter username
username = input('Please enter the username: '******'@BU_Tweets'

# grab tweets
twitter_api.get_tweets(username)

# read file
rfile = open('tweet.json', 'r')
data = json.load(rfile)
rfile.close()

# use google api and store sentiment score
allscore = []
allmag = []
text = data[0]
date = data[1]
for string in text:
    score, mag = google_api.google_sentiment(string)
    print('')
    allscore.append(score)
    allmag.append(mag)

# anaylze sentiment
Пример #7
0
from hmm_sol import *
from twitter_api import get_tweets

m = MarkovModel()
d = get_tweets('SarcasticRover')
train(m, d)
m.run(endOnString)
Пример #8
0
    # limit number of tags
    max_tag = 5

    # Boston, USA woeid
    tag_list = twitter_api.top_hashtags(2367105)

    # check the list of tags in main.json
    with open('main.json', 'w') as outfile:
        json.dump(tag_list, outfile)

    for index, tag in enumerate(tag_list):
        if (index == max_tag):
            break

        print("\n", index + 1, ". tag:", tag, flush=True)
        tweets = twitter_api.get_tweets(tag)

        score_list = []
        for tweet in tweets:
            text = remove_url(tweet.text)
            # print("text: ", text, flush = True)
            try:
                score = google_api.analyze_text_sentiment(text)
            except Exception as e:
                print("google api: error processing text")
                print("\"" + text + "\"", flush=True)
            score_list.append(score)

        # plot the sentiment score in histrogram
        fig, ax = plt.subplots()