mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-14 20:18:02 +00:00
add support for extracting relations between emails, openids, and photos from libravatar's export data
* support to export script needs to be added too
This commit is contained in:
@@ -37,17 +37,10 @@ for file in os.listdir(PATH):
|
|||||||
items = libravatar_read_gzdata(fh.read())
|
items = libravatar_read_gzdata(fh.read())
|
||||||
print('Adding user "%s"' % items['username'])
|
print('Adding user "%s"' % items['username'])
|
||||||
(user, created) = User.objects.get_or_create(username=items['username'])
|
(user, created) = User.objects.get_or_create(username=items['username'])
|
||||||
for email in items['emails']:
|
|
||||||
try:
|
saved_photos = {}
|
||||||
ConfirmedEmail.objects.get_or_create(email=email, user=user)
|
|
||||||
except django.db.utils.IntegrityError:
|
|
||||||
print('%s not unique?' % email)
|
|
||||||
for openid in items['openids']:
|
|
||||||
try:
|
|
||||||
ConfirmedOpenId.objects.get_or_create(openid=openid, user=user) # pylint: disable=no-member
|
|
||||||
except django.db.utils.IntegrityError:
|
|
||||||
print('%s not unique?' % openid)
|
|
||||||
for photo in items['photos']:
|
for photo in items['photos']:
|
||||||
|
photo_id = photo['id']
|
||||||
data = base64.decodebytes(bytes(photo['data'], 'utf-8'))
|
data = base64.decodebytes(bytes(photo['data'], 'utf-8'))
|
||||||
pilobj = Image.open(BytesIO(data))
|
pilobj = Image.open(BytesIO(data))
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
@@ -59,5 +52,20 @@ for file in os.listdir(PATH):
|
|||||||
photo.format = file_format(pilobj.format)
|
photo.format = file_format(pilobj.format)
|
||||||
photo.data = out.read()
|
photo.data = out.read()
|
||||||
photo.save()
|
photo.save()
|
||||||
|
saved_photos[photo_id] = photo
|
||||||
|
|
||||||
|
for email in items['emails']:
|
||||||
|
try:
|
||||||
|
ConfirmedEmail.objects.get_or_create(email=email['email'], user=user,
|
||||||
|
photo=saved_photos.get(email['photo_id']))
|
||||||
|
except django.db.utils.IntegrityError:
|
||||||
|
print('%s not unique?' % email['email'])
|
||||||
|
|
||||||
|
for openid in items['openids']:
|
||||||
|
try:
|
||||||
|
ConfirmedOpenId.objects.get_or_create(openid=openid['openid'], user=user,
|
||||||
|
photo=saved_photos.get(openid['photo_id'])) # pylint: disable=no-member
|
||||||
|
except django.db.utils.IntegrityError:
|
||||||
|
print('%s not unique?' % openid['openid'])
|
||||||
|
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ def read_gzdata(gzdata=None):
|
|||||||
# Emails
|
# Emails
|
||||||
for email in root.findall('{%s}emails' % SCHEMAROOT)[0]:
|
for email in root.findall('{%s}emails' % SCHEMAROOT)[0]:
|
||||||
if email.tag == '{%s}email' % SCHEMAROOT:
|
if email.tag == '{%s}email' % SCHEMAROOT:
|
||||||
emails.append(email.text)
|
emails.append({'email': email.text, 'photo_id': email.attrib['photo_id']})
|
||||||
|
|
||||||
# OpenIDs
|
# OpenIDs
|
||||||
for openid in root.findall('{%s}openids' % SCHEMAROOT)[0]:
|
for openid in root.findall('{%s}openids' % SCHEMAROOT)[0]:
|
||||||
if openid.tag == '{%s}openid' % SCHEMAROOT:
|
if openid.tag == '{%s}openid' % SCHEMAROOT:
|
||||||
openids.append(openid.text)
|
openids.append({'openid': openid.text, 'photo_id': openid.attrib['photo_id']})
|
||||||
|
|
||||||
# Photos
|
# Photos
|
||||||
for photo in root.findall('{%s}photos' % SCHEMAROOT)[0]:
|
for photo in root.findall('{%s}photos' % SCHEMAROOT)[0]:
|
||||||
@@ -54,14 +54,14 @@ def read_gzdata(gzdata=None):
|
|||||||
try:
|
try:
|
||||||
data = base64.decodebytes(bytes(photo.text, 'utf-8'))
|
data = base64.decodebytes(bytes(photo.text, 'utf-8'))
|
||||||
except binascii.Error as exc:
|
except binascii.Error as exc:
|
||||||
print('Cannot decode photo; Encoding: %s, Format: %s: %s' % (
|
print('Cannot decode photo; Encoding: %s, Format: %s, Id: %s: %s' % (
|
||||||
photo.attrib['encoding'], photo.attrib['format'], exc))
|
photo.attrib['encoding'], photo.attrib['format'], photo.attrib['id'], exc))
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
Image.open(BytesIO(data))
|
Image.open(BytesIO(data))
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
print('Cannot decode photo; Encoding: %s, Format: %s: %s' % (
|
print('Cannot decode photo; Encoding: %s, Format: %s, Id: %s: %s' % (
|
||||||
photo.attrib['encoding'], photo.attrib['format'], exc))
|
photo.attrib['encoding'], photo.attrib['format'], photo.attrib['id'], exc))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
# If it is a working image, we can use it
|
# If it is a working image, we can use it
|
||||||
@@ -69,6 +69,7 @@ def read_gzdata(gzdata=None):
|
|||||||
photos.append({
|
photos.append({
|
||||||
'data': photo.text,
|
'data': photo.text,
|
||||||
'format': photo.attrib['format'],
|
'format': photo.attrib['format'],
|
||||||
|
'id': photo.attrib['id'],
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user