Advertisement
Guest User

Untitled

a guest
May 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import httplib, re, base64, urllib
  4.  
  5. # Twitter user and password
  6. username = 'santisaez'
  7. password = ''
  8.  
  9. # HTTP request to get weather forecast from canalmeteo.elcorreo.com
  10. h = httplib.HTTPConnection('canalmeteo.elcorreo.com')
  11. h.request('GET', '/ciudad.php?id_ciudad=79')
  12. response = h.getresponse()
  13. data = response.read()
  14.  
  15. # Parse HTML response and extract data
  16. regex = re.compile('<td colspan="4">(.*)</td>')
  17. result = regex.findall(data)
  18.  
  19. # Update Twitter status with weather forecast
  20. authentication = { "Authorization": "Basic %s" % base64.encodestring("%s:%s" % (username, password)).strip() }
  21. h = httplib.HTTPConnection('twitter.com')
  22. h.request('POST', '/statuses/update.xml', urllib.urlencode({ 'status': result[1] }), authentication)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement