From 73cbdfa268fb69a3bdecebce8798d90d9e27111c Mon Sep 17 00:00:00 2001 From: renarde Date: Mon, 11 Nov 2024 16:12:30 +0100 Subject: [PATCH] Add examples and a README --- README.md | 33 ++++++++ conv_backup.py | 81 ------------------- edit_backup.py | 68 ---------------- ...ew_sms_backup.json => Fossify_backup.json} | 0 .../{old_sms_backup.json => QSMS_backup.json} | 0 5 files changed, 33 insertions(+), 149 deletions(-) create mode 100644 README.md delete mode 100644 conv_backup.py delete mode 100644 edit_backup.py rename examples/{new_sms_backup.json => Fossify_backup.json} (100%) rename examples/{old_sms_backup.json => QSMS_backup.json} (100%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..b48e4a6 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# SMS Scripts : + +Scripts to convert SMS backup from [QKSMS](https://github.com/moezbhatti/qksms) or [QUIK-SMS](https://github.com/octoshrimpy/quik) to [Fossify Messages](https://github.com/FossifyOrg/Messages) backup + +**The scripts don't work with MMS !!!** + +## Usage : + +If you just want to convert your old QKSMS to Fossify Messages : + +```sh +python qsms_to_fossify ./QSMS_Backup.json ./New_Backup_Name.json +``` + +If you already use Fossify on your new phone **After** using QKSMS/QUIKSMS : + +```sh +python qsms_merge_fossify ./QSMS_Backup.json ./Fossify_Backup.json New_Backup_Name.json +``` + +## Examples : + +Convert backup : + +```sh +python qsms_to_fossify ./examples/QSMS_backup.json ./examples/Converted_Backup.json +``` + +Merge backup : + +```sh +python qsms_merge_fossify ./examples/QSMS_backup.json ./examples/Fossify_backup.json ./examples/Merged_Backup.json +``` \ No newline at end of file diff --git a/conv_backup.py b/conv_backup.py deleted file mode 100644 index f804036..0000000 --- a/conv_backup.py +++ /dev/null @@ -1,81 +0,0 @@ -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 appendToBck(old_path : str,target_path : str) : - # Load file to import - with open(old_path) as file : - old_data = json.load(file) - # Load file to edit - with open(new_path,"rw") as file : - target = json.load(file) - for msg in data["messages"] : - if msg["body"] != "" : - data.append(formatMsg(msg)) - 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 conv_backup.py ./backup.json ./new.json" - ) - sys.exit(1) - convertBck(sys.argv[1],sys.argv[2]) - sys.exit(0) - - -if __name__ == "__main__" : - main() diff --git a/edit_backup.py b/edit_backup.py deleted file mode 100644 index f244678..0000000 --- a/edit_backup.py +++ /dev/null @@ -1,68 +0,0 @@ -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 edit_backup.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() \ No newline at end of file diff --git a/examples/new_sms_backup.json b/examples/Fossify_backup.json similarity index 100% rename from examples/new_sms_backup.json rename to examples/Fossify_backup.json diff --git a/examples/old_sms_backup.json b/examples/QSMS_backup.json similarity index 100% rename from examples/old_sms_backup.json rename to examples/QSMS_backup.json