Ver Mensaje Individual
  #6 (permalink)  
Antiguo 22/06/2011, 20:58
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: send to twitter

Algo mas o menos así.

Código Python:
Ver original
  1. import urllib.request
  2. import time
  3.  
  4. password="yourpass"
  5. username="yourUsername"
  6.  
  7. def send_to_twitter(msg):
  8.     password_manager = urllib.request.HTTPPasswordMgr()
  9.     password_manager.add_password("Twitter API",
  10.                    "http://twitter.com/statuses", username, password)
  11.     http_handler = urllib.request.HTTPBasicAuthHandler(password_manager)
  12.     page_opener = urllib.request.build_opener(http_handler)
  13.     urllib.request.install_opener(page_opener)
  14.     params = urllib.parse.urlencode( {'status': msg} )
  15.     params = params.encode()
  16.     resp = urllib.request.urlopen("http://twitter.com/statuses/update.json", params)
  17.     print("OK")
  18.     resp.read()
  19.  
  20. def get_price():
  21.     page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
  22.     text = page.read().decode("utf8")
  23.     where = text.find('>$')
  24.     start_of_price = where + 2
  25.     end_of_price = start_of_price + 4
  26.     return float(text[start_of_price:end_of_price])
  27.  
  28. price_now = input("Do you want to see the price now (Y/N)? ")
  29.  
  30. if price_now == "Y":
  31.     send_to_twitter(get_price())
  32. else:
  33.     price = 99.99
  34.     while price > 4.74:
  35.         time.sleep(900)
  36.         price = get_price()
  37.     send_to_twitter("Buy!")