Rename scripts and fix message
This commit is contained in:
parent
a87a9d228b
commit
e315c9fef0
2 changed files with 136 additions and 0 deletions
68
qsms_merge_fossify.py
Normal file
68
qsms_merge_fossify.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
class newJSON() :
|
||||
def __init__(
|
||||
self,
|
||||
old_type,
|
||||
old_address,
|
||||
old_date,
|
||||
old_dateSent,
|
||||
old_read,
|
||||
old_status,
|
||||
old_body,
|
||||
old_locked,
|
||||
old_subId,
|
||||
) :
|
||||
self.subscriptionId = old_subId
|
||||
self.address = old_address
|
||||
self.body = old_body
|
||||
self.date = old_date
|
||||
self.dateSent = old_dateSent
|
||||
self.locked = 1 if old_locked else 0
|
||||
self.protocol = None
|
||||
self.read = 1 if old_read else 0
|
||||
self.status = old_status
|
||||
self.type = old_type
|
||||
self.serviceCenter = None
|
||||
self.backupType = "sms"
|
||||
|
||||
def formatMsg(oldMsgJSON) :
|
||||
return newJSON(
|
||||
oldMsgJSON["type"],
|
||||
oldMsgJSON["address"],
|
||||
oldMsgJSON["date"],
|
||||
oldMsgJSON["dateSent"],
|
||||
oldMsgJSON["read"],
|
||||
oldMsgJSON["status"],
|
||||
oldMsgJSON["body"],
|
||||
oldMsgJSON["locked"],
|
||||
oldMsgJSON["subId"],
|
||||
).__dict__
|
||||
|
||||
def appendToBck(old_path : str,new_path : str,target_path : str) :
|
||||
# Load old backup
|
||||
with open(old_path) as file :
|
||||
old_data = json.load(file)
|
||||
# Load new backup
|
||||
with open(new_path) as file :
|
||||
target = json.load(file)
|
||||
for msg in old_data["messages"] :
|
||||
if msg["body"] != "" :
|
||||
target.append(formatMsg(msg))
|
||||
# Write to target
|
||||
with open(target_path,"w") as file :
|
||||
json.dump(target,file,indent=2)
|
||||
|
||||
def main() :
|
||||
if len(sys.argv) != 4 :
|
||||
print(
|
||||
"Unrecognized arguments :\n",
|
||||
"python3 qsms_merge_fossify.py ./backup.json ./new_backup.json ./new.json"
|
||||
)
|
||||
sys.exit(1)
|
||||
appendToBck(sys.argv[1],sys.argv[2],sys.argv[3])
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__" :
|
||||
main()
|
68
qsms_to_fossify.py
Normal file
68
qsms_to_fossify.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
class newJSON() :
|
||||
def __init__(
|
||||
self,
|
||||
old_type,
|
||||
old_address,
|
||||
old_date,
|
||||
old_dateSent,
|
||||
old_read,
|
||||
old_status,
|
||||
old_body,
|
||||
old_locked,
|
||||
old_subId,
|
||||
) :
|
||||
self.subscriptionId = old_subId
|
||||
self.address = old_address
|
||||
self.body = old_body
|
||||
self.date = old_date
|
||||
self.dateSent = old_dateSent
|
||||
self.locked = 1 if old_locked else 0
|
||||
self.protocol = None
|
||||
self.read = 1 if old_read else 0
|
||||
self.status = old_status
|
||||
self.type = old_type
|
||||
self.serviceCenter = None
|
||||
self.backupType = "sms"
|
||||
|
||||
def formatMsg(oldMsgJSON) :
|
||||
return newJSON(
|
||||
oldMsgJSON["type"],
|
||||
oldMsgJSON["address"],
|
||||
oldMsgJSON["date"],
|
||||
oldMsgJSON["dateSent"],
|
||||
oldMsgJSON["read"],
|
||||
oldMsgJSON["status"],
|
||||
oldMsgJSON["body"],
|
||||
oldMsgJSON["locked"],
|
||||
oldMsgJSON["subId"],
|
||||
).__dict__
|
||||
|
||||
def convertBck(old_path : str,new_path : str) :
|
||||
with open(old_path) as file :
|
||||
data = json.load(file)
|
||||
|
||||
newBck = []
|
||||
for msg in data["messages"] :
|
||||
# Skip all message without body
|
||||
if msg["body"] != "" :
|
||||
newBck.append(formatMsg(msg))
|
||||
# Write to new file
|
||||
with open(new_path,"w") as file :
|
||||
json.dump(newBck,file,indent=2)
|
||||
|
||||
def main() :
|
||||
if len(sys.argv) != 3 :
|
||||
print(
|
||||
"Unrecognized arguments :\n",
|
||||
"python3 qsms_to_fossify.py ./backup.json ./new.json"
|
||||
)
|
||||
sys.exit(1)
|
||||
convertBck(sys.argv[1],sys.argv[2])
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__" :
|
||||
main()
|
Loading…
Reference in a new issue