Last active
August 20, 2019 10:16
-
-
Save Danielhiversen/5de82ad46a3177944c62f30f9c9d735f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install openpyxl pyTibber | |
import tibber | |
import openpyxl | |
YOUR_TIBBER_TOKEN = 'd1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a' | |
if __name__ == '__main__': | |
tibber_connection = tibber.Tibber(access_token=YOUR_TIBBER_TOKEN) | |
tibber_connection.sync_update_info() | |
wbk_name = 'Tibber_data.xlsx' | |
wbk = openpyxl.Workbook() | |
for home in tibber_connection.get_homes(): | |
home.sync_update_info() | |
data = home.sync_get_historic_data(1000) | |
wks = wbk.create_sheet(home.address1) | |
k = 1 | |
wks.cell(row=k, column=1).value = 'from' | |
wks.cell(row=k, column=2).value = 'totalCost' | |
wks.cell(row=k, column=3).value = 'consumption' | |
for d in data: | |
if d.get('consumption') is None: | |
continue | |
k += 1 | |
wks.cell(row=k, column=1).value = d.get('from') | |
wks.cell(row=k, column=2).value = d.get('totalCost') | |
wks.cell(row=k, column=3).value = d.get('consumption') | |
wbk.save(wbk_name) | |
wbk.close() | |
tibber_connection.sync_close_connection() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment