-
Notifications
You must be signed in to change notification settings - Fork 4
/
sms_import.py
31 lines (30 loc) · 1.26 KB
/
sms_import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
import logging
from sail_sms import SMSParser, SMSImporter, SMSBackup
import os
if __name__ == '__main__':
commhistory_path = "/home/nemo/.local/share/commhistory/commhistory.db"
backup_tool = SMSBackup(commhistory_path, "backup/")
if len(sys.argv) >= 3:
if sys.argv[1] == "--import" and os.path.isfile(sys.argv[2]):
parser = SMSParser(sys.argv[2])
importer = SMSImporter(commhistory_path)
sms_list = parser.get_all_sms_in_sf_format()
backup_tool.create_backup()
for sms in sms_list:
importer.import_sms(sms)
logging.info("Imported %d SMS", len(sms_list))
elif sys.argv[1] == "--restore" and os.path.isfile(sys.argv[2]):
backup_tool.restore_backup(sys.argv[2])
elif len(sys.argv) == 2:
if sys.argv[1] == "--backup":
backup_tool.create_backup()
else:
print("SMS Backup & Restore Importer for Sailfish OS")
print("Import a XML-File:")
print("\tpython sms_import.py --import [xml-file]")
print("Create a backup:")
print("\tpython sms_import.py --backup")
print("Import a commhistory.db Backup:")
print("\tpython sms_import.py --restore [backup-file]")
sys.exit()