コード例 #1
0
def thank(api, tweet):
    """
    Crafts a reply using the screen name and id of a given tweet. Choses
    a random thank you message as the reply.
    """
    thank_you_messages = [
        "Thanks for sharing my article!", "Glad you liked the article!",
        "Thanks for the tweet of my article!",
        "Glad to hear you enjoyed my article!",
        "I'm happy you liked the article enough to tweet it!",
        "Thanks for the share! Glad you liked it!",
        "I appreciate the tweet -- glad you enjoyed my article!",
        "Glad you liked the article enough to share it!",
        "Appreciate you sharing my article!", "Thanks for tweeting my article!"
    ]
    message = choice(thank_you_messages)
    try:
        reply = "@" + tweet.user.screen_name + " " + message
        api.update_status(reply, tweet.id)
    except tweepy.TweepError as e:
        print(e)
コード例 #2
0
try:
    poster_url = requests.get(omdb_api_endpoint).json()['Poster']
    poster_response = requests.get(poster_url)
    with open('poster.jpg', 'bw') as poster_file:
        poster_file.write(poster_response.content)
        poster_file.close()
    no_poster = False
except KeyError:
    no_poster = True

tweet = 'La película elegida aleatoriamente del día es "%s", ganadora del premio Oscar a %s en el ' \
        'año %s. Visítanos en https://random.uchile.cl/apps/movie-bot para más información sobre nuestro servicio. ' % \
        (title, options[1], year) + hashtags

parser = argparse.ArgumentParser(
    description='Twitter Bot - Academy Winners Movies')
parser.add_argument("-t",
                    "--tweet",
                    action="store_true",
                    dest="tweet",
                    default=False)
options = parser.parse_args()

if options.tweet:
    if no_poster:
        api.update_status(tweet)
    else:
        api.update_with_media(filename='poster.jpg', status=tweet)
else:
    print(tweet)
コード例 #3
0
def send_tweet(tweet):
    try:
        api.update_status(tweet)
        logging.info('Tweet sent to Twitter')
    except Exception as e:
        logging.error('Error sending tweet to Twitter: ', e)
コード例 #4
0
def tweet_status(tweet):
    try:
        api.update_status(tweet)
        logging.info('Posted to Twitter')
    except Exception as exc:
        logging.error('Error posting to Twitter: {}'.format(exc))
コード例 #5
0
def tweet_progress(tweet):
    try:
        api.update_status(tweet)
        print('Posted to twitter account')
    except Exception as ex:
        print('Unable to post to twitter. {}'.format(ex))