Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import httplib, re, base64, urllib
- # Twitter user and password
- username = 'santisaez'
- password = ''
- # HTTP request to get weather forecast from canalmeteo.elcorreo.com
- h = httplib.HTTPConnection('canalmeteo.elcorreo.com')
- h.request('GET', '/ciudad.php?id_ciudad=79')
- response = h.getresponse()
- data = response.read()
- # Parse HTML response and extract data
- regex = re.compile('<td colspan="4">(.*)</td>')
- result = regex.findall(data)
- # Update Twitter status with weather forecast
- authentication = { "Authorization": "Basic %s" % base64.encodestring("%s:%s" % (username, password)).strip() }
- h = httplib.HTTPConnection('twitter.com')
- h.request('POST', '/statuses/update.xml', urllib.urlencode({ 'status': result[1] }), authentication)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement