-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmltocsv.py
executable file
·40 lines (33 loc) · 1.02 KB
/
xmltocsv.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
#!/usr/bin/env python
import datetime
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cm as cm, matplotlib.font_manager as fm
import xmltodict
f = open("rvg.csv",'w')
f.write("date,usage\n")
with open('rvg.xml') as fd:
obj = xmltodict.parse(fd.read())
feed = obj['feed']
entries = feed['entry']
readings = []
index = []
for entry in entries:
if 'IntervalBlock' in entry['content']:
iblocks = entry['content']['IntervalBlock']['IntervalReading']
for iblock in iblocks:
usage = interval['value']
starttime= interval['timePeriod']['start']
ts = pd.to_datetime(int(starttime),unit='s')
for entry in entries:
if 'IntervalBlock' in entry['content']:
iblocks = entry['content']['IntervalBlock']
for iblock in iblocks:
intervals = iblock['IntervalReading']
for interval in intervals:
usage = interval['value']
starttime= interval['timePeriod']['start']
ts = pd.to_datetime(int(starttime),unit='s')
f.write(str(ts)+","+usage+"\n")