some linting
This commit is contained in:
parent
b1ba10688a
commit
8d3f6f13b2
103
account2txt.py
103
account2txt.py
|
@ -43,94 +43,99 @@ import getopt
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class ArchiveFile:
|
class ArchiveFile(object):
|
||||||
"""
|
"""
|
||||||
Class to hold the archive file data
|
Class to hold the archive file data
|
||||||
"""
|
"""
|
||||||
def __init__ (self, filename):
|
def __init__(self, filename):
|
||||||
"""
|
"""
|
||||||
Constructor of the class, initialize some internal variables
|
Constructor of the class, initialize some internal variables
|
||||||
and read in the data from the JSON file.
|
and read in the data from the JSON file.
|
||||||
"""
|
"""
|
||||||
with open(filename,'r') as jsonData:
|
with open(filename, 'r') as jason_data:
|
||||||
data = json.load(jsonData)
|
data = json.load(jason_data)
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.version = data['version']
|
self.version = data['version']
|
||||||
self.schema = data['schema']
|
self.schema = data['schema']
|
||||||
self.user = data['user']
|
self.user = data['user']
|
||||||
self.profile = data['profile']
|
self.profile = data['profile']
|
||||||
self.group = data['group']
|
self.group = data['group']
|
||||||
try:
|
# try:
|
||||||
self.profile_fields = data['profile_fields']
|
self.profile_fields = data['profile_fields']
|
||||||
except:
|
# except:
|
||||||
self.profile_fields = None
|
# self.profile_fields = None
|
||||||
self.photo = data['photo']
|
self.photo = data['photo']
|
||||||
self.pconfig = data['pconfig']
|
self.pconfig = data['pconfig']
|
||||||
self.baseurl = data['baseurl']
|
self.baseurl = data['baseurl']
|
||||||
self.contact = data['contact']
|
self.contact = data['contact']
|
||||||
self.group_member = data['group_member']
|
self.group_member = data['group_member']
|
||||||
|
|
||||||
def toFiles(self):
|
def to_files(self):
|
||||||
"""
|
"""
|
||||||
parses the JSON data and writes the content to various text files
|
parses the JSON data and writes the content to various text files
|
||||||
"""
|
"""
|
||||||
baseFileName = self.user["nickname"]+"-"
|
base_file_name = self.user["nickname"]+"-"
|
||||||
with open(baseFileName+"info.txt", "w", encoding='utf8') as outFile:
|
with open(base_file_name+"info.txt", "w", encoding='utf8') as out_file:
|
||||||
outFile.write("Exported from Friendica Version: {}\n".format(self.version))
|
out_file.write("Exported from Friendica Version: {}\n".format(self.version))
|
||||||
outFile.write("Database schema version: {}\n".format(self.schema))
|
out_file.write("Database schema version: {}\n".format(self.schema))
|
||||||
outFile.write("Base URL: {}\n".format(self.baseurl))
|
out_file.write("Base URL: {}\n".format(self.baseurl))
|
||||||
outFile.write("Converted from: {}\n".format(self.filename))
|
out_file.write("Converted from: {}\n".format(self.filename))
|
||||||
with open(baseFileName+"user.txt", "w", encoding='utf8') as outFile:
|
with open(base_file_name+"user.txt", "w", encoding='utf8') as out_file:
|
||||||
for k in self.user:
|
for k in self.user:
|
||||||
outFile.write("{}: {}\n".format(k, self.user[k]))
|
out_file.write("{}: {}\n".format(k, self.user[k]))
|
||||||
with open(baseFileName+"profile.txt", "w", encoding='utf8') as outFile:
|
with open(base_file_name+"profile.txt", "w", encoding='utf8') as out_file:
|
||||||
for k in self.profile[0]:
|
for k in self.profile[0]:
|
||||||
outFile.write("{}: {}\n".format(k, self.profile[0].get(k)))
|
out_file.write("{}: {}\n".format(k, self.profile[0].get(k)))
|
||||||
with open(baseFileName+'groups.txt', "w", encoding='utf8') as outFile:
|
with open(base_file_name+'groups.txt', "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.group)):
|
for i in range(len(self.group)):
|
||||||
outFile.write("Group {}\n".format(i))
|
out_file.write("Group {}\n".format(i))
|
||||||
for ii in self.group[i]:
|
for j in self.group[i]:
|
||||||
outFile.write("{}: {}\n".format(ii, self.group[i].get(ii)))
|
out_file.write("{}: {}\n".format(j, self.group[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
if self.profile_fields:
|
if self.profile_fields:
|
||||||
with open(baseFileName+'profile_fields.txt', 'w', encoding='utf8') as outFile:
|
with open(base_file_name+'profile_fields.txt', 'w', encoding='utf8') as out_file:
|
||||||
for i in range(len(self.profile_fields)):
|
for i in range(len(self.profile_fields)):
|
||||||
for ii in self.profile_fields[i]:
|
for j in self.profile_fields[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.profile_fields[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.profile_fields[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+'photo.txt', 'w', encoding='utf8') as outFile:
|
with open(base_file_name+'photo.txt', 'w', encoding='utf8') as out_file:
|
||||||
for i in range(len(self.photo)):
|
for i in range(len(self.photo)):
|
||||||
for ii in self.photo[i]:
|
for j in self.photo[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.photo[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.photo[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+"pconfig.txt","w", encoding='utf8') as outFile:
|
with open(base_file_name+"pconfig.txt", "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.pconfig)):
|
for i in range(len(self.pconfig)):
|
||||||
for ii in self.pconfig[i]:
|
for j in self.pconfig[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.pconfig[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.pconfig[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+"contact.txt","w", encoding='utf8') as outFile:
|
with open(base_file_name+"contact.txt", "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.contact)):
|
for i in range(len(self.contact)):
|
||||||
for ii in self.contact[i]:
|
for j in self.contact[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.contact[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.contact[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+"group_member.txt","w", encoding='utf8') as outFile:
|
with open(base_file_name+"group_member.txt", "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.group_member)):
|
for i in range(len(self.group_member)):
|
||||||
for ii in self.group_member[i]:
|
for j in self.group_member[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.group_member[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.group_member[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
options, arguments = getopt.getopt(sys.argv[1:], "vhi:",
|
"""
|
||||||
["version", "help", "input="])
|
If the script is called directly, export the data from the supplied filename.
|
||||||
for o,a in options:
|
"""
|
||||||
|
options, arguments = getopt.getopt(sys.argv[1:], "vhi:", ["version", "help", "input="])
|
||||||
|
for o, a in options:
|
||||||
if o in ("-v", "--version"):
|
if o in ("-v", "--version"):
|
||||||
print(__version__)
|
print(__version__)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if o in ("-i", "--input"):
|
if o in ("-i", "--input"):
|
||||||
arch = ArchiveFile(filename=a)
|
arch = ArchiveFile(filename=a)
|
||||||
arch.toFiles()
|
arch.to_files()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if o in ("-h", "--help"):
|
if o in ("-h", "--help"):
|
||||||
print(__usage__)
|
print(__usage__)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
122
backup2txt.py
122
backup2txt.py
|
@ -43,17 +43,17 @@ import getopt
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class ArchiveFile:
|
class ArchiveFile(object):
|
||||||
"""
|
"""
|
||||||
Class to hold the archive file data
|
Class to hold the archive file data
|
||||||
"""
|
"""
|
||||||
def __init__ (self, filename):
|
def __init__(self, filename):
|
||||||
"""
|
"""
|
||||||
Constructor of the class, initialize some internal variables
|
Constructor of the class, initialize some internal variables
|
||||||
and read in the data from the JSON file.
|
and read in the data from the JSON file.
|
||||||
"""
|
"""
|
||||||
with open(filename, 'r') as inFile:
|
with open(filename, 'r') as in_file:
|
||||||
lines = inFile.readlines()
|
lines = in_file.readlines()
|
||||||
|
|
||||||
# in the 0th line there are the account file information
|
# in the 0th line there are the account file information
|
||||||
data = json.loads(lines[0])
|
data = json.loads(lines[0])
|
||||||
|
@ -80,79 +80,83 @@ class ArchiveFile:
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
self.item = data['item']
|
self.item = data['item']
|
||||||
|
|
||||||
def toFiles(self):
|
def to_files(self):
|
||||||
"""
|
"""
|
||||||
parses the JSON data and writes the content to various text files
|
parses the JSON data and writes the content to various text files
|
||||||
"""
|
"""
|
||||||
baseFileName = self.user["nickname"]+"-"
|
base_file_name = self.user["nickname"]+"-"
|
||||||
with open(baseFileName+"info.txt", "w", encoding='utf8') as outFile:
|
with open(base_file_name+"info.txt", "w", encoding='utf8') as out_file:
|
||||||
outFile.write("Exported from Friendica Version: {}\n".format(self.version))
|
out_file.write("Exported from Friendica Version: {}\n".format(self.version))
|
||||||
outFile.write("Database schema version: {}\n".format(self.schema))
|
out_file.write("Database schema version: {}\n".format(self.schema))
|
||||||
outFile.write("Base URL: {}\n".format(self.baseurl))
|
out_file.write("Base URL: {}\n".format(self.baseurl))
|
||||||
outFile.write("Converted from: {}\n".format(self.filename))
|
out_file.write("Converted from: {}\n".format(self.filename))
|
||||||
with open(baseFileName+"user.txt", "w", encoding='utf8') as outFile:
|
with open(base_file_name+"user.txt", "w", encoding='utf8') as out_file:
|
||||||
for k in self.user:
|
for k in self.user:
|
||||||
outFile.write("{}: {}\n".format(k, self.user[k]))
|
out_file.write("{}: {}\n".format(k, self.user[k]))
|
||||||
with open(baseFileName+"profile.txt", "w", encoding='utf8') as outFile:
|
with open(base_file_name+"profile.txt", "w", encoding='utf8') as out_file:
|
||||||
for k in self.profile[0]:
|
for k in self.profile[0]:
|
||||||
outFile.write("{}: {}\n".format(k, self.profile[0].get(k)))
|
out_file.write("{}: {}\n".format(k, self.profile[0].get(k)))
|
||||||
with open(baseFileName+'groups.txt', "w", encoding='utf8') as outFile:
|
with open(base_file_name+'groups.txt', "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.group)):
|
for i in range(len(self.group)):
|
||||||
outFile.write("Group {}\n".format(i))
|
out_file.write("Group {}\n".format(i))
|
||||||
for ii in self.group[i]:
|
for j in self.group[i]:
|
||||||
outFile.write("{}: {}\n".format(ii, self.group[i].get(ii)))
|
out_file.write("{}: {}\n".format(j, self.group[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
if self.profile_fields:
|
if self.profile_fields:
|
||||||
with open(baseFileName+'profile_fields.txt', 'w', encoding='utf8') as outFile:
|
with open(base_file_name+'profile_fields.txt', 'w', encoding='utf8') as out_file:
|
||||||
for i in range(len(self.profile_fields)):
|
for i in range(len(self.profile_fields)):
|
||||||
for ii in self.profile_fields[i]:
|
for j in self.profile_fields[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.profile_fields[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.profile_fields[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+'photo.txt', 'w', encoding='utf8') as outFile:
|
with open(base_file_name+'photo.txt', 'w', encoding='utf8') as out_file:
|
||||||
for i in range(len(self.photo)):
|
for i in range(len(self.photo)):
|
||||||
for ii in self.photo[i]:
|
for j in self.photo[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.photo[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.photo[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+"pconfig.txt","w", encoding='utf8') as outFile:
|
with open(base_file_name+"pconfig.txt", "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.pconfig)):
|
for i in range(len(self.pconfig)):
|
||||||
for ii in self.pconfig[i]:
|
for j in self.pconfig[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.pconfig[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.pconfig[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+"contact.txt","w", encoding='utf8') as outFile:
|
with open(base_file_name+"contact.txt", "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.contact)):
|
for i in range(len(self.contact)):
|
||||||
for ii in self.contact[i]:
|
for j in self.contact[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.contact[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.contact[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
with open(baseFileName+"group_member.txt","w", encoding='utf8') as outFile:
|
with open(base_file_name+"group_member.txt", "w", encoding='utf8') as out_file:
|
||||||
for i in range(len(self.group_member)):
|
for i in range(len(self.group_member)):
|
||||||
for ii in self.group_member[i]:
|
for j in self.group_member[i]:
|
||||||
outFile.write('{}: {}\n'.format(ii, self.group_member[i].get(ii)))
|
out_file.write('{}: {}\n'.format(j, self.group_member[i].get(j)))
|
||||||
outFile.write("\n")
|
out_file.write("\n")
|
||||||
for item in self.item:
|
for item in self.item:
|
||||||
itemFileName = baseFileName + "item-" + item['created'].replace(' ', '_') + '-Title_' + str(item['title']).replace(' ','_') + '-' + item['guid'] + '.txt'
|
item_file_name = base_file_name + "item-" + item['created'].replace(' ', '_') + '-Title_' + str(item['title']).replace(' ', '_') + '-' + item['guid'] + '.txt'
|
||||||
with open(itemFileName, 'w', encoding='utf8') as outFile:
|
with open(item_file_name, 'w', encoding='utf8') as out_file:
|
||||||
outFile.write("# Title: {}\n".format(str(item['title'])))
|
out_file.write("# Title: {}\n".format(str(item['title'])))
|
||||||
outFile.write("# Created: {}\n".format(str(item['created'])))
|
out_file.write("# Created: {}\n".format(str(item['created'])))
|
||||||
outFile.write("# ID: {}\n".format(str(item['id'])))
|
out_file.write("# ID: {}\n".format(str(item['id'])))
|
||||||
outFile.write("# guid: {}\n".format(str(item['guid'])))
|
out_file.write("# guid: {}\n".format(str(item['guid'])))
|
||||||
outFile.write("# contact-id: {}\n".format(str(item['contact-id'])))
|
out_file.write("# contact-id: {}\n".format(str(item['contact-id'])))
|
||||||
outFile.write("# gcontact-id : {}\n".format(str(item['gcontact-id'])))
|
out_file.write("# gcontact-id : {}\n".format(str(item['gcontact-id'])))
|
||||||
outFile.write("# parent ID: {}\n".format(str(item['parent'])))
|
out_file.write("# parent ID: {}\n".format(str(item['parent'])))
|
||||||
outFile.write("# edited: {}\n".format(str(item['edited'])))
|
out_file.write("# edited: {}\n".format(str(item['edited'])))
|
||||||
outFile.write(str(item['body']))
|
out_file.write(str(item['body']))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
options, arguments = getopt.getopt(sys.argv[1:], "vhi:",
|
"""
|
||||||
["version", "help", "input="])
|
If the script is called directly, export the data from the supplied filename.
|
||||||
for o,a in options:
|
"""
|
||||||
if o in ("-v", "--version"):
|
options, arguments = getopt.getopt(sys.argv[1:], "vhi:", ["version", "help", "input="])
|
||||||
|
for opt, a in options:
|
||||||
|
if opt in ("-v", "--version"):
|
||||||
print(__version__)
|
print(__version__)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if o in ("-i", "--input"):
|
if opt in ("-i", "--input"):
|
||||||
arch = ArchiveFile(filename=a)
|
arch = ArchiveFile(filename=a)
|
||||||
arch.toFiles()
|
arch.to_files()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if o in ("-h", "--help"):
|
if opt in ("-h", "--help"):
|
||||||
print(__usage__)
|
print(__usage__)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue