Skip to content

Commit

Permalink
Duke energy converter
Browse files Browse the repository at this point in the history
  • Loading branch information
za3k committed Jun 3, 2024
1 parent a88a47a commit ecee01a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions duke2csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/python3
import csv, datetime
import xml.etree.ElementTree as ET

tree = ET.parse("Energy Usage.xml").getroot()
csvfile = open("duke-energy.csv", "w")

csv = csv.writer(csvfile)
csv.writerow(["time (local)", "watts", "quality", "timestamp", "quality"])

for child in tree[1][1].findall("{http://naesb.org/espi}IntervalReading"):
start = child.find("{http://naesb.org/espi}timePeriod").find("{http://naesb.org/espi}start").text
quality = child.find("{http://naesb.org/espi}readingQuality").text
value = child.find("{http://naesb.org/espi}value").text
watts = float(value)*1000 * 4 # Because it's in delta kWH, for 0.25 hours

dt = datetime.datetime.fromtimestamp(int(start))
date = dt.strftime('%Y-%m-%d')
time = dt.strftime('%H:%M:%S')

csv.writerow([date + " " + time, watts, quality, start])

0 comments on commit ecee01a

Please sign in to comment.