8
'as' is in the send_to_twitter function (msg)
import urllib.request
import time
def send_to_twitter(msg):
import twitter as t:
CONSUMER_KEY = '1wrnsF5lB8fEWVzRdvlIqdTle'
CONSUMER_SECRET = 'eTiylDUHLJgGnTCcxzzCtzHXG4OlHrbY6wLvuZUnAEhrokyNAF'
ACCESS_KEY = '2325915097-q2JYaZ3UGeL9Pr95BJC7643NMyETY6x7Bb8T1q1'
ACCESS_SECRET = '8GRq4e9ukVKcC8XjroM3iLKuZYOM2QtFEdCHXG3TXx0zo'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(msg)
print(msg)
def get_price():
page = urllib.request.urlopen("http://beans-r-us.appspot.com/prices-loyalty.html")
text = page.read().decode("utf8")
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
return(text[start_of_price : end_of_price])
escolha = input("Precisa do valor imediatamente? ")
if escolha == 'y':
send_to_twitter(get_price())
else:
if escolha == 'n':
price = 99.99
while price > 4.74:
price = float(get_price())
time.sleep(3)
send_to_twitter('BUY!')
else:
print("Voce nao escolheu nada")
Add-on: The most practical utility of this is that you can give more meaningful names to an imported class or function and use the new name in your code instead of the original name. I also use in cases where the name of an imported function is a bit large so I create the alias so I don’t have to type that function with a huge name every time I need to use it.
– Matheus Saraiva