Created
July 18, 2019 21:51
-
-
Save unforgiven512/d7e72ddd3da90b52542355ae614f7d1a 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
import argparse | |
import locale | |
import logging | |
import time | |
import threading | |
import json | |
import requests | |
import datetime | |
#from aiy.board import Board | |
#from aiy.voice.audio import AudioFormat, play_wav, record_file, Recorder | |
#from aiy.board import Board, Led | |
#from aiy.cloudspeech import CloudSpeechClient | |
def main(): | |
COMED_HP_API_BASE_URL = 'https://hourlypricing.comed.com/api?type=' | |
logging.basicConfig(level=logging.DEBUG) | |
parser = argparse.ArgumentParser(description='ComEd Hourly Pricing API Data Access') | |
parser.add_argument('--pricetype', '-t', default='hour') | |
parser.add_argument('--datapoints', '-n', default='1') | |
args = parser.parse_args() | |
logging.info('The --pricetype argument provided was: %s', args.pricetype) | |
if args.pricetype == 'hour': | |
comed_hp_api_url = COMED_HP_API_BASE_URL + 'currenthouraverage' | |
logging.info('Getting the current hour average price from the ComEd Hourly Pricing API...') | |
numdatapoints = 1 | |
elif args.pricetype == '5minute': | |
comed_hp_api_url = COMED_HP_API_BASE_URL + '5minutefeed' | |
logging.info('Getting the 5-minute price data from the ComEd Hourly Pricing API...') | |
numdatapoints = int(args.datapoints) | |
response = requests.get(comed_hp_api_url) | |
pricedatalist = json.loads(response.text) | |
logging.debug("Price Data:\n%s", pricedatalist) | |
pricedata = pricedatalist[0] | |
mtimeupdated = int(pricedata.get("millisUTC")) | |
currentprice = float(pricedata.get("price")) | |
timeupdated = datetime.datetime.fromtimestamp(mtimeupdated/1000.0) | |
logging.info("The price data was last updated at %s", timeupdated) | |
print(currentprice) | |
# for x in pricedata.values(): | |
# print(x) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment