Пример #1
0
def main():

    # verification process
    api = simple_twit.create_api()

    simple_twit.version()

    ranomuserid = "@CoinDesk"
    #ranomuserid="@gem_detecter"
    #ranomuserid="@jonathanbosh"
    #ranomuserid="@binance"

    timeline = simple_twit.get_user_timeline(api, ranomuserid, 15)
    textonly_tweets = [[tweet.full_text] for tweet in timeline]
    print("Tweets From another user Timeline", *textonly_tweets, sep="\n")
    print("Total tweets From another user timeline", len(textonly_tweets))

    print(type(textonly_tweets))
    file = open('data.csv', 'w+', newline='')
    with file:
        write = csv.writer(file)
        write.writerow(["Tweets"])
        print(
            "type=================================================================>",
            type(textonly_tweets))
        for x in textonly_tweets:
            try:
                write.writerows([x])
            except:
                pass
Пример #2
0
def main():
    api = simple_twit.create_api()
    simple_twit.version()
    tweets = simple_twit.get_home_timeline(api, 20)
    key_word = "the"
    morning = "Good morning"
    afternoon = "Good afternoon"
    while True:
        for tweet in tweets:
            word_arr = tweet.full_text.split(" ")
            if len(word_arr) > 25:
                words = word_arr
                random.shuffle(words)
                new_sentence = ' '.join(words)
                username = "******" + tweet.user.name + " "
                simple_twit.send_reply_tweet(api, username + new_sentence,
                                             tweet.id)
                time.sleep(15)
        time.sleep(300)
        # Sleep 5 minutes
        for tweet in tweets:
            if key_word in tweet.full_text.split(" "):
                datetime_object = datetime.datetime.now()
                username = "******" + tweet.user.name + " "
                if int(datetime_object.hour) > 12:
                    simple_twit.send_reply_tweet(api, username + afternoon,
                                                 tweet.id)
                else:
                    simple_twit.send_reply_tweet(api, username + morning,
                                                 tweet.id)
                break
        time.sleep(3600)
Пример #3
0
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    # Do not remove or change this function call.
    # Pass the variable "api" holding this Tweepy API object as the first
    # argument to simple_twit functions.
    api = simple_twit.create_api()]

    simple_twit.version()
    
    # Project 04 Exercises

   
    # Exercise 1 - Get and print 10 tweets from your home timeline
    tweet10 = simple_twit.get_home_timeline(api=api, count=20)
    for t in tweet10:
        print(t.full_text)
    
    # Exercise 2 - Get and print 10 tweets from another user's timeline
    Spy10 = simple_twit.get_user_timeline(api = api, user= "******", count = 20)
    for st in Spy10:
        print(st.full_text)
    # Exercise 3 - Post 1 tweet to your timeline.
    simple_twit.send_tweet(api=api, text="I tweeted my first tweet, Hold my head")
    
    # Exercise 4 - Post 1 media tweet to your timeline.
    simple_twit.send_media_tweet(api=api, text="This is a picture from my archives", filename= "C:/Users/Glen F/OneDrive/Desktop/test.png")
    
    simple_twit.send_tweet(api=api, text="test #2 I think, media isn't working")
Пример #4
0
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    # Do not remove or change this function call.
    # Pass the variable "api" holding this Tweepy API object as the first
    # argument to simple_twit functions.
    api = simple_twit.create_api()
    # YOUR CODE BEGINS HERE

    name = "tmia_IAE101"

    user = simple_twit.get_user(api, name)

    time_line = simple_twit.get_user_timeline(api, name, count=5)
    home_time_line = simple_twit.get_home_timeline(api, count=5)

    #weather bot
    key = "440cb9d576a4f8df23fb00a4e3a2dde2"
    latitude = "40.916168"
    longitude = "-73.118309"
    url = f"https://api.darksky.net/forecast/{key}/{latitude},{longitude}"
    data = requests.get(url).json()

    currently = data['currently']["summary"]
    current_temp = data['currently']['temperature']
    try:
        precipitation = data["currently"]["precipType"]
    except KeyError:
        pass
    precipitation_probability = str(data["currently"]["precipProbability"] *
                                    100)

    if float(precipitation_probability) in [100, 100.0]:
        try:
            message = f"Currently in Stony Brook: {currently} with a temperature of {current_temp}°F\nPrecipitation probability: {precipitation_probability}%\nAnd now a word from Ollie: "
        except KeyError:
            pass
        tweet = simple_twit.send_media_tweet(api, message,
                                             "ollie_raining_sideways.jpg")
        thanks = simple_twit.send_tweet(api, "Thanks Ollie.")

    elif float(precipitation_probability) in range(50, 100):
        try:
            message = f"Curreently: {currently} with a temperature of {current_temp}°F\nPrecipitation probability: {precipitation_probability}%"
        except KeyError:
            pass
        tweet = simple_twit.send_media_tweet(api, message, "ollie.jpg")

        thanks = simple_twit.send_tweet(api, "Thanks Ollie.")

    else:
        message = f"Currently in Stony Brook: {currently} with a temperature of {current_temp}°F\nPrecipitation probability: {precipitation_probability}%"
        tweet = simple_twit.send_tweet(api, message)

    simple_twit.version()
Пример #5
0
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    # Do not remove or change this function call.
    # Pass the variable "api" holding this Tweepy API object as the first
    # argument to simple_twit functions.
    api = simple_twit.create_api()
    simple_twit.version()

    # Project 04 Exercises

    # Exercise 1 - Get and print 10 tweets from your home timeline

    # Exercise 2 - Get and print 10 tweets from another user's timeline

    # Exercise 3 - Post 1 tweet to your timeline.

    # Exercise 4 - Post 1 media tweet to your timeline.

    # YOUR BOT CODE BEGINS HERE
    # mytweets = simple_twit.get_home_timeline(api,10)
    # print("-------------10 Tweets from my timeline-------------")
    # print()
    #
    #
    #
    #
    # for tweet in mytweets:
    #     print(tweet.full_text)
    # #
    # print()
    # elsetweets = simple_twit.get_user_timeline(api, "nice_tips_bot", 10)
    # print("-------------10 Tweets from @nice_tips_bot-------------")
    # print()
    # for tweet in elsetweets:
    #     print(tweet.full_text)

    print("-------------Posting a tweet-------------")
    while True:
        event = get_event()
        image_status = download_image(api, get_image(event["url"]))
        message = "Today in year {y}, {e}".format(y=event["year"],
                                                  e=event["event"])
        print(message)
        if (image_status == 1):
            simple_twit.send_media_tweet(api, message, "temp.jpg")
            os.remove("temp.jpg")
        elif (image_status == 0):
            simple_twit.send_tweet(api, message)
        time.sleep(900)
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    api = simple_twit.create_api()
    simple_twit.version()
    CONFIG_FILE = "twitter_bot.config"
    consumer_key = "#################";
    consumer_secret = "################"
    f = open(CONFIG_FILE, "r")
    config = json.load(f)
    access_token = config["access_token"]
    access_token_secret = config["access_secret"]
    f.close()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    myListener = MyStreamListener()
    myStream = tweepy.Stream(auth, listener = myListener)
    keywords  = ['Yankees', 'Cole', 'Cashman']
    myStream.filter(track = keywords)
    tweets = myListener.tweets#tweets is a list of string objects now
    #print(tweets)
    #tweets.extend(simple_twit.get_home_timeline(api, 3))
    sid = SentimentIntensityAnalyzer()
    aggs=[0,0,0,0]#element 0 is total compound, element 1 is total negative, element 2 is total neutral, element 3 is total positive
    for tweet in tweets:
        #print(tweet)
        ss = sid.polarity_scores(tweet)
        x=0
        for k in sorted(ss):#k is key
            #print('{0}: {1}, '.format(k, ss[k]), end='')
            #print(ss[k])
            #print()
            aggs[x]+=ss[k]
            x+=1
    #print("AGGREGATE")
    #print(aggs[0])
    #print(aggs[1])
    #print(aggs[2])
    #print(aggs[3])
    aggtext = ("For the query using keywords " + str(keywords) + ", the average sentiment values are as follows. Compound "+str(aggs[0]/15.0)+", negative " + str(aggs[1]/15.0)+", neutral " + str(aggs[2]/15.0)+", positive " + str(aggs[3]/15.0))
    print(aggtext)
    #for tweet in tweets:
        #print("MY PRINT " + tweet)
        #simple_twit.send_tweet(api,tweet)
    simple_twit.send_tweet(api, aggtext)
Пример #7
0
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    api = simple_twit.create_api()
    simple_twit.version()
    top30 = [
        '@BarackObama', '@katyperry', '@justinbieber', '@rihanna',
        '@taylorswift13', '@Cristiano', '@ladygaga', '@TheEllenShow',
        '@YouTube', '@ArianaGrande', '@realDonaldTrump', '@jtimberlake',
        '@KimKardashian', '@selenagomez', '@twitter', '@britneyspears',
        '@cnnbrk', '@shakira', '@jimmyfallon', '@narendramodi', '@BillGates',
        '@neymarjr', '@MileyCyrus', '@nytimes', '@JLo', '@KingJames',
        '@BrunoMars', '@CNN', '@Oprah', '@BBCBreaking'
    ]
    me = api.get_user("joshmathew_iae")
    print(me.screen_name)
    public_tweets = api.home_timeline()

    cont = True
    while (cont):
        try:
            index = random.randrange(0, 30)
            randuser = api.user_timeline(top30[index])
            randtweet = randuser[0].text
            ident = randuser[0].id
            print(randtweet)
            print("\n\nReversed:")
            revd = reversal(randuser[0].text)
            print(revd)
            message = top30[index] + ' ' + revd
            api.update_status(message, ident)
            print(top30[index])
            cont = False
        except:
            #check for errors
            print("\nERROR occured, trying again...\n")
Пример #8
0
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    # Do not remove or change this function call.
    # Pass the variable "api" holding this Tweepy API object as the first
    # argument to simple_twit functions.
    api = simple_twit.create_api()
    Images = ["pete.jpg", "petedebate.jpg", "pd1.jpg", "p4.jpg", "p5.jpg"]
    PeteQuotes = [
        "Greatness will come by looking forward - untethered from the politics of the past and anchored by our shared values - and by changing our nation's future.",
        "I think that policy matters. I'm a policy guy. #WinTheEra https://peteforamerica.com/issues/",
        "So much of politics is about people's relationships with themselves. You do better if you make people feel secure in who they are. https://peteforamerica.com/issues/"
    ]
    TopCandidates = [
        "@DonaldTrump", "@PeteButtigieg", "BernieSanders", "@ewarren",
        "@JoeBiden"
    ]
    Replies = [
        "#VoteBlue #VoteBlueNoMatterWho",
        "#NeverTrump #VoteDemocrat because the country needs to fix the messes of Trump",
        "Support Democrats. Check out https://democrats.org/"
    ]
    replyCounter = 0
    # YOUR CODE BEGINS HERE
    tweets = simple_twit.get_home_timeline(api, 10)
    topCandidate = False
    for tweet in tweets:
        #print("Tweet:", i)
        print("ID:", tweet.id)
        print("Author:", tweet.author.screen_name, ":", tweet.author.name)
        print(tweet.full_text)
        if replyCounter < 4:
            for c in TopCandidates:
                if c == tweet.author.screen_name:
                    topCandidate = True
            simple_twit.send_reply_tweet(
                api, tweet.author.screen_name +
                Replies[random.randint(0,
                                       len(Replies) - 1)], tweet.id)
            if topCandidate == True and tweet.author.screen_name == TopCandidates[
                    1]:
                simple_twit.send_reply_tweet(
                    api, tweet.author.screen_name +
                    "He will make a great President. Check out his policies at https://peteforamerica.com/issues/",
                    tweet.id)
            if topCandidate == True and tweet.author.screen_name == TopCandidates[
                    0]:
                simple_twit.send_reply_tweet(
                    api,
                    "@realDonaldTrump You disgraced our country with your behavior, not Democrats #VoteBlueNoMatterWho",
                    tweet.id)
            replyCounter += 1
        print("Verified Account:", tweet.author.verified)
        print()
        topCandidate = False
    Tweets = simple_twit.get_user_timeline(api, "@PeteButtigieg", 3)
    for tweet in Tweets:
        simple_twit.retweet(api, tweet.id)

    #sys.exit()

    #tweets = simple_twit.get_home_timeline(api, 10)
    me = simple_twit.get_user(api, "@gbellam_IAE101")
    print(me.followers_count)
    print(me.description)
    print(me.location)
    simple_twit.version()

    #follow back users and unfollow former candidates
    followers = simple_twit.get_my_followers(api, 4)
    for follower in followers:
        simple_twit.follow_user(api, follower.name)
    simple_twit.unfollow_user(api, "@kamalaharris")
    simple_twit.unfollow_user(api, "@GovernorBullock")
    #index = random.randint(0,len(Images)-1_
    simple_twit.send_media_tweet(
        api, PeteQuotes[random.randint(0,
                                       len(PeteQuotes) - 1)],
        Images[random.randint(0,
                              len(Images) - 1)])
Пример #9
0
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    # Do not remove or change this function call.
    # Pass the variable "api" holding this Tweepy API object as the first
    # argument to simple_twit functions.
    api = simple_twit.create_api()
    simple_twit.version()
    
    # Project 04 Exercises
    
##    # Exercise 1 - Get and print 10 tweets from your home timeline
##    myTimeline = simple_twit.get_home_timeline(api, 10)
##    for tweet in myTimeline:
##        print(tweet.id)
##        print(type(tweet.user))
##        print(tweet.author.name)
##        print(tweet.user.name)
##        print(tweet.full_text)
##        print()
##    
##    # Exercise 2 - Get and print 10 tweets from another user's timeline
##    careBotTimeline = simple_twit.get_user_timeline(api,"tinycarebot", 10)
##    for tweet in careBotTimeline:
##        print(tweet.id)
##        print(type(tweet.user))
##        print(tweet.author.name)
##        print(tweet.user.name)
##        print(tweet.full_text)
##        print()
##    
##    # Exercise 3 - Post 1 tweet to your timeline.
##    myPost = simple_twit.send_tweet(api, "Exercise #3 on mytwitterbot.py (third run)")
##    print(type(myPost))
##    
##    # Exercise 4 - Post 1 media tweet to your timeline.
##    myMediaPost = simple_twit.send_media_tweet(api, "Exercise #4 on mytwitterbot.py", "cat.jpg")
##    print(type(myMediaPost))
    
    
    # YOUR BOT CODE BEGINS HERE
    



    while True:
        
        year = datetime.now()
        currentYear = year.year

        today = date.today()
        d = today.strftime("%B %d, %Y")
    
        present = datetime.now()
        future = datetime(currentYear, 1, 1, 12, 0, 0)
        difference = present - future 
        newDifference = 366 - difference.days
        
        
        tweet = "Today is " + str(d) + "."
        tweet2 = "Days left till " + str(currentYear + 1) + ": " + str(newDifference)

        if newDifference == 0:
            finalTweet = "HAPPY NEW YEAR!"
        else:
            finalTweet = tweet+ "\n"+ tweet2

        print(finalTweet)

        myPost = simple_twit.send_tweet(api, finalTweet)
        print(type(myPost))
        time.sleep(86400)
def main():
    # This call to simple_twit.create_api will create the api object that
    # Tweepy needs in order to make authenticated requests to Twitter's API.
    # Do not remove or change this function call.
    # Pass the variable "api" holding this Tweepy API object as the first
    # argument to simple_twit functions.
    api = simple_twit.create_api()
    simple_twit.version()

    # Project 04 Exercises

    # # Exercise 1 - Get and print 10 tweets from your home timeline
    # print('Exercise 1:')
    # home_tweets = simple_twit.get_home_timeline(api, 10)
    # for tweet in home_tweets:
    #     print('Name: ' + str(tweet.author.name))
    #     print('ID: ' + str(tweet.id))
    #     print('Tweet: ' + str(tweet.full_text))
    #     print()
    #
    # # Exercise 2 - Get and print 10 tweets from another user's timeline
    # print('Exercise 2:')
    # elon_tweets = simple_twit.get_user_timeline(api, 'elonmusk', 10)
    # for tweet in elon_tweets:
    #     print('Name: ' + str(tweet.author.name))
    #     print('ID: ' + str(tweet.id))
    #     print('Tweet: ' + str(tweet.full_text))
    #     print()
    # # print(simple_twit.get_user(api, 'elonmusk'))
    # # Exercise 3 - Post 1 tweet to your timeline.
    # print('Exercise 3:')
    # post_tweet = 'This is a test tweet for exercise 3'
    # simple_twit.send_tweet(api, post_tweet)
    # print(post_tweet)
    # print()
    #
    # # Exercise 4 - Post 1 media tweet to your timeline.
    # print('Exercise 4:')
    # post_media_tweet_text = 'This is a test tweet text for exercise 4'
    # simple_twit.send_media_tweet(api, post_media_tweet_text, 'test31.png')
    # print(post_media_tweet_text)

    # YOUR BOT CODE BEGINS HERE
    marvel_lines = [
        'We\'re Fighting An Army Of Robots And I Have A Bow And Arrow. None Of This Makes Sense.',
        'Whatever It Takes...',
        'If You\'re Nothing Without The Suit, Then You Shouldn\'t Have It.',
        'I Have Nothing To Prove To You.',
        'She\'s Not Alone.',
        'I Can Do This All Day.',
        'That\'s My Secret Cap; I\'m Always Angry.',
        'Wakanda Forever!',
        'I Am Iron Man.',
        'We Have A Hulk.'
        'There Was An Idea...',
        'We Are Groot!',
        'If We Can\'t Protect The Earth, You Can Be Damn Well Sure We\'ll Avenge It!',
        'Dormammu, I\'ve Come To Bargain.',
        'Part of the journey is the end.',
        'No amount of money ever bought a second of time.',
        'SteveRogersSad.png',
        'captain-america-civil-war.png',
        'captain-marvel.png',
        'thor-horse.png',
        'thor-adopted.png',
        'tony-spaceship.png',
        'spiderman-fury.png',
        'captain-marvel-w-friend.png',
    ]

    while True:
        pick = random.choice(marvel_lines)
        print(pick)
        if pick.split('.')[-1] == 'png':
            simple_twit.send_media_tweet(api, 'An iconic marvel image', pick)
        else:
            simple_twit.send_tweet(api, pick)
        time.sleep(900)