Created
June 24, 2012 18:06
-
-
Save josch/2984230 to your computer and use it in GitHub Desktop.
download all avatars of xmpp contacts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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