Browse Source

some linting

stable v0.0.1
Tobias Diekershoff 1 year ago
parent
commit
8d3f6f13b2
  1. 103
      account2txt.py
  2. 124
      backup2txt.py

103
account2txt.py

@ -43,94 +43,99 @@ import getopt
import json
import sys
class ArchiveFile:
class ArchiveFile(object):
"""
Class to hold the archive file data
"""
def __init__ (self, filename):
def __init__(self, filename):
"""
Constructor of the class, initialize some internal variables
and read in the data from the JSON file.
"""
with open(filename,'r') as jsonData:
data = json.load(jsonData)
with open(filename, 'r') as jason_data:
data = json.load(jason_data)
self.filename = filename
self.version = data['version']
self.schema = data['schema']
self.user = data['user']
self.profile = data['profile']
self.group = data['group']
try:
self.profile_fields = data['profile_fields']
except:
self.profile_fields = None
# try:
self.profile_fields = data['profile_fields']
# except:
# self.profile_fields = None
self.photo = data['photo']
self.pconfig = data['pconfig']
self.baseurl = data['baseurl']
self.contact = data['contact']
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
"""
baseFileName = self.user["nickname"]+"-"
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))
outFile.write("Converted from: {}\n".format(self.filename))
with open(baseFileName+"user.txt", "w", encoding='utf8') as outFile:
base_file_name = self.user["nickname"]+"-"
with open(base_file_name+"info.txt", "w", encoding='utf8') as out_file:
out_file.write("Exported from Friendica Version: {}\n".format(self.version))
out_file.write("Database schema version: {}\n".format(self.schema))
out_file.write("Base URL: {}\n".format(self.baseurl))
out_file.write("Converted from: {}\n".format(self.filename))
with open(base_file_name+"user.txt", "w", encoding='utf8') as out_file:
for k in self.user:
outFile.write("{}: {}\n".format(k, self.user[k]))
with open(baseFileName+"profile.txt", "w", encoding='utf8') as outFile:
out_file.write("{}: {}\n".format(k, self.user[k]))
with open(base_file_name+"profile.txt", "w", encoding='utf8') as out_file:
for k in self.profile[0]:
outFile.write("{}: {}\n".format(k, self.profile[0].get(k)))
with open(baseFileName+'groups.txt', "w", encoding='utf8') as outFile:
out_file.write("{}: {}\n".format(k, self.profile[0].get(k)))
with open(base_file_name+'groups.txt', "w", encoding='utf8') as out_file:
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")
out_file.write("Group {}\n".format(i))
for j in self.group[i]:
out_file.write("{}: {}\n".format(j, self.group[i].get(j)))
out_file.write("\n")
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 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 j in self.profile_fields[i]:
out_file.write('{}: {}\n'.format(j, self.profile_fields[i].get(j)))
out_file.write("\n")
with open(base_file_name+'photo.txt', 'w', encoding='utf8') as out_file:
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", encoding='utf8') as outFile:
for j in self.photo[i]:
out_file.write('{}: {}\n'.format(j, self.photo[i].get(j)))
out_file.write("\n")
with open(base_file_name+"pconfig.txt", "w", encoding='utf8') as out_file:
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", encoding='utf8') as outFile:
for j in self.pconfig[i]:
out_file.write('{}: {}\n'.format(j, self.pconfig[i].get(j)))
out_file.write("\n")
with open(base_file_name+"contact.txt", "w", encoding='utf8') as out_file:
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", encoding='utf8') as outFile:
for j in self.contact[i]:
out_file.write('{}: {}\n'.format(j, self.contact[i].get(j)))
out_file.write("\n")
with open(base_file_name+"group_member.txt", "w", encoding='utf8') as out_file:
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)))
outFile.write("\n")
for j in self.group_member[i]:
out_file.write('{}: {}\n'.format(j, self.group_member[i].get(j)))
out_file.write("\n")
if __name__ == "__main__":
options, arguments = getopt.getopt(sys.argv[1:], "vhi:",
["version", "help", "input="])
for o,a in options:
def main():
"""
If the script is called directly, export the data from the supplied filename.
"""
options, arguments = getopt.getopt(sys.argv[1:], "vhi:", ["version", "help", "input="])
for o, a in options:
if o in ("-v", "--version"):
print(__version__)
sys.exit()
if o in ("-i", "--input"):
arch = ArchiveFile(filename=a)
arch.toFiles()
arch.to_files()
sys.exit()
if o in ("-h", "--help"):
print(__usage__)
sys.exit()
if __name__ == "__main__":
main()

124
backup2txt.py

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