This repository has been archived by the owner on Mar 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsms.py
48 lines (40 loc) · 1.61 KB
/
sms.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import os
import codecs
import ios_parser
# Nasty hack to force utf-8 encoding by default:
reload(sys)
sys.setdefaultencoding('utf8')
# Change stdout to allow printing of unicode characters:
streamWriter = codecs.lookup('utf-8')[-1]
sys.stdout = streamWriter(sys.stdout)
if __name__ == "__main__":
"""Allow the parser to be run from the command line.
Optionally, the function allows specifying the filename to read in from
as the first argument."""
if len(sys.argv) >= 2:
# If filname passed in and a recognised format, continue:
if ((".db" in sys.argv[1]) or (".sqlite" in sys.argv[1]) or (".pickle" in sys.argv[1])):
fname = sys.argv[1]
else:
# If not a recognised format, stop but allow override:
print "File is not a .db file, a .sqlite file or a pickle file."
print "Later code will verify the file is an sms.db file, and will terminate anyway if not."
cont = raw_input("Continue now? (y/n)")
if cont == "n":
sys.exit(-1)
else:
# If no argument, attempt to open the default sms.db file:
fname = "sms.db"
if not os.path.isfile(fname):
print "File " + fname + " does not exist or could not be found! Abort."
sys.exit(-1)
# Some example code to add functionality immediately.
# Create the parser, and parse the messages file:
if ".pickle" in fname:
SMS = ios_parser.iOSMessageParse(fname, load_pickle=True)
else:
SMS = ios_parser.iOSMessageParse(fname)
SMS.parse_messages()
print SMS.Texts
SMS.write_to_csv()