better UTF8 handling, older account files have no profile_fields
This commit is contained in:
parent
67b997ade4
commit
9fb97a70be
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
|
@ -52,7 +52,7 @@ class ArchiveFile:
|
|||
Constructor of the class, initialize some internal variables
|
||||
and read in the data from the JSON file.
|
||||
"""
|
||||
with open(filename) as jsonData:
|
||||
with open(filename,'r') as jsonData:
|
||||
data = json.load(jsonData)
|
||||
self.filename = filename
|
||||
self.version = data['version']
|
||||
|
@ -60,7 +60,10 @@ class ArchiveFile:
|
|||
self.user = data['user']
|
||||
self.profile = data['profile']
|
||||
self.group = data['group']
|
||||
self.profile_fields = data['profile_fields']
|
||||
try:
|
||||
self.profile_fields = data['profile_fields']
|
||||
except:
|
||||
self.profile_fields = None
|
||||
self.photo = data['photo']
|
||||
self.pconfig = data['pconfig']
|
||||
self.baseurl = data['baseurl']
|
||||
|
@ -72,43 +75,44 @@ class ArchiveFile:
|
|||
parses the JSON data and writes the content to various text files
|
||||
"""
|
||||
baseFileName = self.user["nickname"]+"-"
|
||||
with open(baseFileName+"info.txt", "w") as outFile:
|
||||
with open(baseFileName+"info.txt", "w", encoding='utf8') as outFile:
|
||||
outFile.write("Exported from Friendica Version: {}\n".format(self.version))
|
||||
outFile.write("Database schema version: {}\n".format(self.schema))
|
||||
outFile.write("Base URL: {}\n".format(self.baseurl))
|
||||
with open(baseFileName+"userdata.txt", "w") as outFile:
|
||||
with open(baseFileName+"userdata.txt", "w", encoding='utf8') as outFile:
|
||||
for k in self.user:
|
||||
outFile.write("{}: {}\n".format(k, self.user[k]))
|
||||
with open(baseFileName+"profile.txt", "w") as outFile:
|
||||
with open(baseFileName+"profile.txt", "w", encoding='utf8') as outFile:
|
||||
for k in self.profile[0]:
|
||||
outFile.write("{}: {}\n".format(k, self.profile[0].get(k)))
|
||||
with open(baseFileName+'groups.txt', "w") as outFile:
|
||||
with open(baseFileName+'groups.txt', "w", encoding='utf8') as outFile:
|
||||
for i in range(len(self.group)):
|
||||
outFile.write("Group {}\n".format(i))
|
||||
for ii in self.group[i]:
|
||||
outFile.write("{}: {}\n".format(ii, self.group[i].get(ii)))
|
||||
outFile.write("\n")
|
||||
with open(baseFileName+'profile_fields.txt', 'w') as outFile:
|
||||
for i in range(len(self.profile_fields)):
|
||||
for ii in self.profile_fields[i]:
|
||||
outFile.write('{}: {}\n'.format(ii, self.profile_fields[i].get(ii)))
|
||||
outFile.write("\n")
|
||||
with open(baseFileName+'photo.txt', 'w') as outFile:
|
||||
if self.profile_fields:
|
||||
with open(baseFileName+'profile_fields.txt', 'w', encoding='utf8') as outFile:
|
||||
for i in range(len(self.profile_fields)):
|
||||
for ii in self.profile_fields[i]:
|
||||
outFile.write('{}: {}\n'.format(ii, self.profile_fields[i].get(ii)))
|
||||
outFile.write("\n")
|
||||
with open(baseFileName+'photo.txt', 'w', encoding='utf8') as outFile:
|
||||
for i in range(len(self.photo)):
|
||||
for ii in self.photo[i]:
|
||||
outFile.write('{}: {}\n'.format(ii, self.photo[i].get(ii)))
|
||||
outFile.write("\n")
|
||||
with open(baseFileName+"pconfig.txt","w") as outFile:
|
||||
with open(baseFileName+"pconfig.txt","w", encoding='utf8') as outFile:
|
||||
for i in range(len(self.pconfig)):
|
||||
for ii in self.pconfig[i]:
|
||||
outFile.write('{}: {}\n'.format(ii, self.pconfig[i].get(ii)))
|
||||
outFile.write("\n")
|
||||
with open(baseFileName+"contact.txt","w") as outFile:
|
||||
with open(baseFileName+"contact.txt","w", encoding='utf8') as outFile:
|
||||
for i in range(len(self.contact)):
|
||||
for ii in self.contact[i]:
|
||||
outFile.write('{}: {}\n'.format(ii, self.contact[i].get(ii)))
|
||||
outFile.write("\n")
|
||||
with open(baseFileName+"group_member.txt","w") as outFile:
|
||||
with open(baseFileName+"group_member.txt","w", encoding='utf8') as outFile:
|
||||
for i in range(len(self.group_member)):
|
||||
for ii in self.group_member[i]:
|
||||
outFile.write('{}: {}\n'.format(ii, self.group_member[i].get(ii)))
|
||||
|
|
Loading…
Reference in a new issue