Пример #1
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")
Пример #2
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()
Пример #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

    # 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)
Пример #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()
    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)])
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)