-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbrt.py
executable file
·74 lines (67 loc) · 2.15 KB
/
sbrt.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
import argparse
import os
import sys
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
from datetime import datetime
from queue import Queue
from smsbackuptools.dbs import SQLite
from smsbackuptools.elasticsms import QueueUpload
from smsbackuptools.parser import ParseXML
def main():
start_time = datetime.now()
print("[I] START TIME: {t}".format(t=start_time))
print("\n")
parsexml = ParseXML()
argparser = argparse.ArgumentParser()
argparser.add_argument('-x', '--xml', default="sms.xml")
argparser.add_argument('-e', '--elastic', action='store_true')
argparser.add_argument('-s', '--sqlite', action='store_true')
argparser.add_argument('-u', '--upload_threads', default="15")
args = argparser.parse_args()
xml = args.xml
elastic = args.elastic
sqlite = args.sqlite
upload_threads = args.upload_threads
try:
tree = ET.parse(xml)
except FileNotFoundError as err:
print(err)
print("[!] QUITTING!!!")
sys.exit(1)
except:
print("\"{f}\" is malformed or not an xml!!!".format(f=xml))
print("[!] QUITTING!!!")
sys.exit(1)
root = tree.getroot()
if elastic:
queueupload = QueueUpload
queue = Queue()
for x in range(int(upload_threads)):
worker = queueupload(queue)
worker.daemon = True
worker.start()
for message in root:
message = parsexml.human_readable(message)
if message is not None:
queue.put(message)
queue.join()
if sqlite:
sqlite = SQLite()
if os.stat("sbrt.db").st_size == 0:
print("[I] DATABASE DOESN'T EXIST, CREATING...\n")
sqlite.create_tables()
for message in root:
message = parsexml.human_readable(message)
sqlite.insert_row(message)
sqlite.commit_db()
else:
parsexml.print_all(root)
end_time = datetime.now()
print("[I] END TIME: {t}".format(t=end_time))
print("[I] TOOK {t}".format(t=end_time - start_time))
if __name__ == "__main__":
main()