/
122-xml-parse-calls-backup-restore.py
46 lines (39 loc) · 2.16 KB
/
122-xml-parse-calls-backup-restore.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import xml.etree.ElementTree as ET
import datetime
try:
# f = ET.parse('../../github-data/sms-lite.xml')
# for i in f.findall('smses'):
# c = [i.find(n).text for n in ('protocol', 'address', 'date', 'type')]
# print(c)
tree = ET.parse('../../github-data/calls-20220830000140.xml')
root = tree.getroot()
for x in root:
if x.tag == 'call':
print('call')
# sql = (root.tag, root.attrib['count'], root.attrib['backup_set'], root.attrib['backup_date'], root.attrib['type'], x.tag)
sql = ("insert into datasets.calls_backup_lnd (re_val,ra_count,ra_backup_set,ra_backup_date,ra_type,ea_val,ea_number,ea_duration,ea_date,ea_type,ea_presentation,ea_subscription_id,ea_post_dial_digits,ea_subscription_component_name,ea_readable_date,ea_contact_name)values(root.attrib['val'],root.attrib['count'],root.attrib['backup_set'],root.attrib['backup_date'],root.attrib['type'],x.attrib['val'],x.attrib['number'],x.attrib['duration'],x.attrib['date'],x.attrib['type'],x.attrib['presentation'],x.attrib['subscription_id'],x.attrib['post_dial_digits'],x.attrib['subscription_component_name'],x.attrib['readable_date'],x.attrib['contact_name']);")
else:
break
# sql = "insert into github.sample_03 (item, price, description, calories) values ('" + c[0] + "', " + c[1] + ", '" + c[2] + "', '" + c[3] + "')"
print(sql)
print('The End...')
except Exception as e:
dt = datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f | ')
f_path = os.path.expanduser('~/.logs/python-by-example.log')
app_name = os.path.basename(__file__)
with open(f_path, 'a') as f:
f.write(dt + app_name + ' | ' + 'Exception Error: ' + str(e) + '\n')
print('Exception Error: ' + str(e))
sys.exit(1)
else:
dt = datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f | ')
f_path = os.path.expanduser('~/.logs/python-by-example.log')
app_name = os.path.basename(__file__)
with open(f_path, 'a') as f:
f.write(dt + app_name + ' | ' + 'Successfully Executed...\n')
print('Successfully Executed...')
sys.exit(0)