Pushing a message to Twitter using Jabber

The following code connects to the NOAA using pyMETAR to retrieve a weather report and then connects to the Twitter Jabber bot and sends a message as me. Believe it or not the hard part was figuring out that the Twitter IM bot was ignoring normal messages and that I needed to send a chat message

import time, pymetar, xmpp

# Philly International KPHL

metarRF     = pymetar.ReportFetcher("KPHL")
metarRP     = pymetar.ReportParser()
metarData   = metarRF.FetchReport()
metarReport = metarRP.ParseReport(metarData)

weather     = "looks out the window: %s, %s F (%s C)" % (metarReport.getWeather(), 
                                                         metarReport.getTemperatureFahrenheit(),
                                                         metarReport.getTemperatureCelsius())

print 'weather: %s' % weather

jid = xmpp.protocol.JID('you@jabber.org')

to_list = [xmpp.protocol.JID('twitter@twitter.com'),
          ]

c = xmpp.Client(jid.getDomain(), debug=[])

if c.connect():
    a = c.auth(jid.getNode(), 'password', resource=jid.getResource())

    if a:
        print 'authenticated using', a

        for j in to_list:
            print j, '::', c.send(xmpp.protocol.Message(j, weather, 'chat'))

        time.sleep(1)
    else:
        print 'error authenticating', a

    c.disconnect()
else:
    print 'error connecting'

Mentions