sábado, 5 de junio de 2021

Twitter bot

 https://www.youtube.com/watch?v=0FOUFF4q14A

Installation https://stackoverflow.com/questions/31431002/unable-to-import-tweepy-module

https://dototot.com/write-twitter-bot-python-tweepy-tweet-list-users/

https://gist.github.com/szolotykh/e4924159d79ddbaa12c6


https://pypi.org/project/tweepy/

https://www.geeksforgeeks.org/tweet-using-python/

# importing the module
import tweepy
  
# personal details
consumer_key ="xxxxxxxxxxxxxxxx"
consumer_secret ="xxxxxxxxxxxxxxxx"
access_token ="xxxxxxxxxxxxxxxx"
access_token_secret ="xxxxxxxxxxxxxxxx"
  
# authentication of consumer key and secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# authentication of access token and secret
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
  
# update the status
api.update_status(status ="Hello Everyone !")

domingo, 14 de marzo de 2021

try except

 

The General Solution: try except

As with any exception, you can always use the try except block to isolate the potential exception-raising code and provide a backup solution.

You can use the try except block in a similar example as before, but this time providing a default message to be printed should a KeyError be raised in the normal case:

 1# ages.py
 2
 3ages = {'Jim': 30, 'Pam': 28, 'Kevin': 33}
 4person = input('Get age for: ')
 5
 6try:
 7    print(f'{person} is {ages[person]} years old.')
 8except KeyError:
 9    print(f"{person}'s age is unknown.")

https://realpython.com/python-keyerror/