MCPcopy Create free account
hub / github.com/PyQt5/PyQtClient / get_avatar

Method get_avatar

Utils/GitThread.py:67–92  ·  view source on GitHub ↗
(self, uid, avatar_url)

Source from the content-addressed store, hash-verified

65 AppLog.info('login thread started')
66
67 def get_avatar(self, uid, avatar_url):
68 try:
69 req = requests.get(avatar_url)
70 if req.status_code == 200:
71 imgformat = req.headers.get('content-type',
72 'image/jpg').split('/')[1]
73 Constants.ImageAvatar = os.path.join(
74 Constants.ImageDir, str(uid)).replace('\\', '/') + '.jpg'
75 AppLog.debug('image type: {}'.format(imgformat))
76 AppLog.debug('content length: {}'.format(len(req.content)))
77
78 image = QImage()
79 if image.loadFromData(req.content):
80 # 缩放图片
81 if not image.isNull():
82 image = image.scaled(130, 130, Qt.IgnoreAspectRatio,
83 Qt.SmoothTransformation)
84 AppLog.debug('save to: {}'.format(
85 Constants.ImageAvatar))
86 image.save(Constants.ImageAvatar)
87 else:
88 AppLog.warn('avatar image is null')
89 else:
90 AppLog.warn('can not load from image data')
91 except Exception as e:
92 AppLog.exception(e)
93
94 def run(self):
95 AppLog.info('start login github')

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected