Skip to content

Instantly share code, notes, and snippets.

@josch
Created June 24, 2012 18:06
Show Gist options
  • Save josch/2984230 to your computer and use it in GitHub Desktop.
Save josch/2984230 to your computer and use it in GitHub Desktop.
download all avatars of xmpp contacts
import xmpp
import base64
import sys
# this script retrieves the avatars of all your xmpp contacts and saves them
# in the current directory
if len(sys.argv) != 4:
print "usage: "+sys.argv[0]+" user pass server"
exit(1)
username = sys.argv[1]
password = sys.argv[2]
server = sys.argv[3]
j = xmpp.Client(server)
j.connect(server=(server, 5223))
j.auth(username, password, 'test_client')
roster = j.getRoster()
queue = set()
def recieve_vcard(session, stanza, jid):
photo = stanza.getTag('vCard')
if not photo:
queue.remove(jid)
return
photo = stanza.getTag('vCard').getTag('PHOTO')
if not photo:
queue.remove(jid)
return
ext = photo.getTag('TYPE').getData().slpit("/")[1]
photo_bin = base64.b64decode(photo.getTag('BINVAL').getData())
with open(jid+"."+ext, 'wb') as f:
f.write(photo_bin)
queue.remove(jid)
for jid in roster.getItems():
queue.add(jid)
n = xmpp.Node('vCard', attrs={'xmlns': xmpp.NS_VCARD})
iq = xmpp.Protocol('iq', jid, 'get', payload=[n])
j.SendAndCallForResponse(iq, recieve_vcard, args={'jid':jid})
while queue:
j.Process(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment