Snippets

Edel SM XG scratch

Created by Edelberto Mania
#!/usr/bin/env python
## parse users.json file from exported data and then download the profile pictures
## Edelberto Mania <edelberto.mania@xogito.com>
## https://xogito.atlassian.net/browse/ITSM-1109
## 20230518

import requests,json,shutil

users={}
with open("users.json","r") as slack:
    users=json.loads(slack.read())

for user in users:
    if 'image_original' in user['profile']:pic_url=user['profile']['image_original']
    else:pic_url=user['profile']['image_512']
    ext=pic_url.split('.')[-1]
    r=requests.get(pic_url,stream=True)
    if r.status_code==200:
        r.raw.decode_content=True
        try:filename=user['profile']['email']
        except KeyError:filename=user['profile']['real_name']
        with open('{}.{}'.format(filename.lstrip('/'),ext),'wb') as f:shutil.copyfileobj(r.raw,f)
        print("success: {}.{}".format(filename,ext))
    else:print("failed: {}.{}".format(filename,ext))

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.