{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction: Using Watt Time to Find Energy Sources\n", "\n", "The purpose of this notebook is to explore the Watt Time API to find what kind of electricity we are currently using. The Watt Time API allows us to see a breakdown of the energy generation for a given location." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T02:02:52.063494Z", "start_time": "2018-12-19T02:02:50.485580Z" } }, "outputs": [], "source": [ "# Standard Data Science Helpers\n", "import numpy as np\n", "import pandas as pd\n", "import scipy\n", "\n", "import featuretools as ft\n", "\n", "# Graphic libraries\n", "import matplotlib as plt\n", "%matplotlib inline\n", "plt.style.use('fivethirtyeight');plt.rcParams['font.size']=18\n", "import seaborn as sns\n", "\n", "# Extra options\n", "pd.options.display.max_rows = 10\n", "# Show all code cells outputs\n", "from IPython.core.interactiveshell import InteractiveShell\n", "InteractiveShell.ast_node_interactivity = 'all'\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Location\n", "\n", "This code is from Stack Overflow: " ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T02:40:36.678067Z", "start_time": "2018-12-19T02:40:36.674077Z" } }, "outputs": [], "source": [ "from IPython.display import HTML" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T02:44:35.725236Z", "start_time": "2018-12-19T02:44:35.722217Z" } }, "outputs": [], "source": [ "info = open('C:/users/willk/OneDrive/Desktop/watt_time_api.txt', 'r').read()\n", "u, p = info.split(',')" ] }, { "cell_type": "code", "execution_count": 113, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T03:02:56.053230Z", "start_time": "2018-12-19T03:02:55.782820Z" } }, "outputs": [], "source": [ "from requests.auth import HTTPBasicAuth\n", "\n", "values = \"\"\"{\n", " \"username\": \"willkoehrsen\",\n", " \"password\": \"introduction\",\n", " \"email\": \"wjk68@case.edu\",\n", " \"org\": \"Cortex Intel\"\n", " }\"\"\"\n", " \n", "headers = {\n", " \"Content-Type\": \"application/json\"\n", "}\n", "\n", "r = requests.post('https://api2.watttime.org/v2/login', \n", " headers={'username': u, 'password': p},\n", " auth = ('token', 'bb4d607fc7e94417718f6a70a92c72def85ffbe4'))\n", "\n", "# import ast\n", "# token = ast.literal_eval(r.text.strip())['token']" ] }, { "cell_type": "code", "execution_count": 114, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T03:02:56.549311Z", "start_time": "2018-12-19T03:02:56.544322Z" } }, "outputs": [ { "data": { "text/plain": [ "'{\"message\":\"Authorization header requires \\'Credential\\' parameter. Authorization header requires \\'Signature\\' parameter. Authorization header requires \\'SignedHeaders\\' parameter. Authorization header requires existence of either a \\'X-Amz-Date\\' or a \\'Date\\' header. Authorization=Basic dG9rZW46YmI0ZDYwN2ZjN2U5NDQxNzcxOGY2YTcwYTkyYzcyZGVmODVmZmJlNA==\"}'" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.text" ] }, { "cell_type": "code", "execution_count": 105, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T03:01:07.620967Z", "start_time": "2018-12-19T03:01:07.615984Z" } }, "outputs": [ { "data": { "text/plain": [ "'P@*7XDxq6q84rJboRxK4Al&iw4Wi&w^!u*Twj82H3GyR'" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "ExecuteTime": { "end_time": "2018-12-19T02:47:24.074745Z", "start_time": "2018-12-19T02:46:53.810735Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\t\n", "\t
\n", "\t\t\n", "\t\t\n", "\t\t\n", "Generated by cloudfront (CloudFront)\n", "Request ID: LeDj5M7pr28h-aiQyKEVaViQ_jDkLWqfjPBNp6tFKWPCFHBO_PCQkw==\n", "\n", "\n", "\n", "" ], "text/plain": [ "