[
  {
    "path": "ActualTemp.py",
    "content": "#!/usr/bin/python\n\n# Copyright (c) 2014 Adafruit Industries\n# Author: Tony DiCola\n\nimport Adafruit_DHT\nfrom ISStreamer.Streamer import Streamer\nfrom time import sleep\n\n# Sensor should be set to Adafruit_DHT.DHT11,\n# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.\nsensor = Adafruit_DHT.DHT22\n\n# Example using a Raspberry Pi with DHT sensor\n# connected to GPIO 3.\npin = 3\n\nstreamer = Streamer(bucket_key=\"shwu1\", access_key=\"PLACE YOUR INITIAL STATE ACCESS KEY HERE\")\n\nwhile True:\n\t# Try to grab a sensor reading.  Use the read_retry method which will retry up\n\t# to 15 times to get a sensor reading (waiting 2 seconds between each retry).\n\thumidity, temperature = Adafruit_DHT.read_retry(sensor, pin)\n\n\t# Note that sometimes you won't get a reading and\n\t# the results will be null (because Linux can't\n\t# guarantee the timing of calls to read the sensor).\n\t# If this happens try again!\n\tif humidity is not None and temperature is not None:\n\t    \n\t    temperatureF = 9.0/5.0*temperature+32\n\t    streamer.log(\"Actual Temperature\",temperatureF)\n\t    print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature, humidity))\n\t    sleep(900)\n\telse:\n\t    print('Failed to get reading. Try again!')\n"
  },
  {
    "path": "CPUTemp.py",
    "content": "import os\nimport urllib2\nimport json\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Streamer\nfrom sense_hat import SenseHat \nimport subprocess\n\n# --------- User Settings ---------\nSTATE = \"CA\"\nCITY = \"San_Francisco\"\nSENSOR_LOCATION_NAME = \"Office\"\nWUNDERGROUND_API_KEY = \"PLACE YOUR WUNDERGROUND API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"shwu1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_conditions():\n\tapi_conditions_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/conditions/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t  \tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\tprint \"Failed to get conditions\"\n\t\treturn []\n\tjson_conditions = f.read()\n\tf.close()\n\treturn json.loads(json_conditions)\n\ndef get_astronomy():\n\tapi_astronomy_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/astronomy/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t\tf = urllib2.urlopen(api_astronomy_url)\n\texcept:\n\t\tprint \"Failed to get astronomy\"\n\t\treturn []\t\t\n\tjson_astronomy = f.read()\n\tf.close()\n\treturn json.loads(json_astronomy)\n\ndef is_night(astronomy):\n\tsunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])\n\tsunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])\n\tsunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])\n\tsunset_min   = int(astronomy['moon_phase']['sunset']['minute'])\n\tcurrent_hour = int(astronomy['moon_phase']['current_time']['hour'])\n\tcurrent_min  = int(astronomy['moon_phase']['current_time']['minute'])\n\tif ( (current_hour < sunrise_hour) or\n\t     (current_hour > sunset_hour) or\n\t     ((current_hour == sunrise_hour) and\n\t      (current_min < sunrise_min)) or \n\t     ((current_hour == sunset_hour) and\n\t      (current_min > sunset_min)) ):\n\t\treturn True\n\treturn False\n\ndef moon_icon(moon_phase):\n\ticon = {\n\t\t\"New Moon\"        : \":new_moon:\",\n\t\t\"Waxing Crescent\" : \":waxing_crescent_moon:\",\n\t\t\"First Quarter\"   : \":first_quarter_moon:\",\n\t\t\"Waxing Gibbous\"  : \":waxing_gibbous_moon:\",\n\t\t\"Full Moon\"       : \":full_moon:\",\n\t\t\"Full\"            : \":full_moon:\",\n\t\t\"Waning Gibbous\"  : \":waning_gibbous_moon:\",\n\t\t\"Last Quarter\"    : \":last_quarter_moon:\",\n\t\t\"Waning Crescent\" : \":waning_crescent_moon:\",\n\t}\n\treturn icon.get(moon_phase,\":crescent_moon:\")\n\ndef weather_icon(weather_conditions):\n\ticon = {\n\t\t\"clear\"            : \":sun_with_face:\",\n\t\t\"cloudy\"           : \":cloud:\",\n\t\t\"flurries\"         : \":snowflake:\",\n\t\t\"fog\"              : \":foggy:\",\n\t\t\"hazy\"             : \":foggy:\",\n\t\t\"mostlycloudy\"     : \":cloud:\",\n\t\t\"mostlysunny\"      : \":sun_with_face:\",\n\t\t\"partlycloudy\"     : \":partly_sunny:\",\n\t\t\"partlysunny\"      : \":partly_sunny:\",\n\t\t\"sleet\"            : \":sweat_drops: :snowflake:\",\n\t\t\"rain\"             : \":umbrella:\",\n\t\t\"snow\"             : \":snowflake:\",\n\t\t\"sunny\"            : \":sun_with_face:\",\n\t\t\"tstorms\"          : \":zap: :umbrella:\",\n\t\t\"unknown\"          : \":sun_with_face:\",\n\t}\n\treturn icon.get(weather_conditions,\":sun_with_face:\")\n\ndef weather_status_icon(conditions, astronomy):\n\tmoon_phase = astronomy['moon_phase']['phaseofMoon']\n\tweather_conditions = conditions['current_observation']['icon']\n\ticon = weather_icon(weather_conditions)\n\tif is_night(astronomy):\n\t\tif ((icon == \":sunny:\") or\n\t\t    (icon == \":partly_sunny:\") or\n\t\t    (icon == \":sun_with_face:\")):\n\t\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon(conditions, astronomy):\n\ticon = {\n\t\t\"East\"     : \":arrow_right:\",\n\t\t\"ENE\"      : \":arrow_upper_right:\",\n\t\t\"ESE\"      : \":arrow_lower_right:\",\n\t\t\"NE\"       : \":arrow_upper_right:\",\n\t\t\"NNE\"      : \":arrow_upper_right:\",\n\t\t\"NNW\"      : \":arrow_upper_left:\",\n\t\t\"North\"    : \":arrow_up:\",\n\t\t\"NW\"       : \":arrow_upper_left:\",\n\t\t\"SE\"       : \":arrow_lower_right:\",\n\t\t\"South\"    : \":arrow_down:\",\n\t\t\"SSE\"      : \":arrow_lower_right:\",\n\t\t\"SSW\"      : \":arrow_lower_left:\",\n\t\t\"SW\"       : \":arrow_lower_left:\",\n\t\t\"Variable\" : \":arrows_counterclockwise:\",\n\t\t\"West\"     : \":arrow_left:\",\n\t\t\"WNW\"      : \":arrow_upper_left:\",\n\t\t\"WSW\"      : \":arrow_lower_left:\",\n\t}\n\treturn icon.get(conditions['current_observation']['wind_dir'],\":crescent_moon:\")\t\n\ndef main():\n\tsense = SenseHat()\n\tconditions = get_conditions()\n\tastronomy = get_astronomy()\n\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\tprint \"Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!\"\n\t\tif 'error' in conditions['response']:\n\t\t\tprint \"Error Type: \" + conditions['response']['error']['type']\n\t\t\tprint \"Error Description: \" + conditions['response']['error']['description']\n\t\texit()\n\telse:\n\t\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\t\tstreamer.log(\":house: Location\",conditions['current_observation']['display_location']['full'])\n\twhile True:\n\t\t# -------------- Sense Hat --------------\n\t\t# Read the sensors\n\t\ttemp_c = sense.get_temperature()\n\t\thumidity = sense.get_humidity() \n\t\tpressure_mb = sense.get_pressure() \n    \t\tcpu_temp = subprocess.check_output(\"vcgencmd measure_temp\", shell=True)\n    \t\tarray = cpu_temp.split(\"=\")\n    \t\tarray2 = array[1].split(\"'\")\n\n    \t\tcpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0\n    \t\tcpu_tempf = float(\"{0:.2f}\".format(cpu_tempf))\n    \t\tstreamer.log(\"CPU Temperature\",cpu_tempf)\n    \t\tprint(cpu_tempf)\n    \n\t\t# Format the data\n\t\ttemp_f = temp_c * 9.0 / 5.0 + 32.0\n\t\ttemp_f = float(\"{0:.2f}\".format(temp_f))\n\t\ttemp_c = float(\"{0:.2f}\".format(temp_c))\n\t\thumidity = float(\"{0:.2f}\".format(humidity))\n\t\tpressure_in = 0.0295301*(pressure_mb)\n\t\tpressure_in = float(\"{0:.2f}\".format(pressure_in))\n\t\tpressure_mb = float(\"{0:.2f}\".format(pressure_mb))\n\n\t\t# Print and stream \n\t\tif (METRIC_UNITS):\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(C): \" + str(temp_c)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(mb): \" + str(pressure_mb)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(C)\", temp_c)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (mb)\", pressure_mb)\n\t\telse:\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(F): \" + str(temp_f)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(IN): \" + str(pressure_in)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(F)\", temp_f)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (IN)\", pressure_in)\n\t\tprint SENSOR_LOCATION_NAME + \" Humidity(%): \" + str(humidity)\n\t\tstreamer.log(\":sweat_drops: \" + SENSOR_LOCATION_NAME + \" Humidity(%)\", humidity)\n\n\t\t# -------------- Wunderground --------------\n\t\tconditions = get_conditions()\n\t\tastronomy = get_astronomy()\n\t\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\t\tprint \"Error! Wunderground API call failed. Skipping a reading then continuing ...\"\n\t\telse:\n\t\t\thumidity_pct = conditions['current_observation']['relative_humidity']\n\t\t\thumidity = humidity_pct.replace(\"%\",\"\")\n\n\t\t\t# Stream valid conditions to Initial State\n\t\t\tstreamer.log(\":cloud: \" + CITY + \" Weather Conditions\",weather_status_icon(conditions, astronomy))\n\t\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(astronomy['moon_phase']['phaseofMoon']))\n\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Direction\",wind_dir_icon(conditions, astronomy))\n\t\t\tif (METRIC_UNITS):\n\t\t\t\tif isFloat(conditions['current_observation']['temp_c']): \n\t\t\t\t\tstreamer.log(CITY + \" Temperature(C)\",conditions['current_observation']['temp_c'])\n\t\t\t\tif isFloat(conditions['current_observation']['dewpoint_c']):\n\t\t\t\t\tstreamer.log(CITY + \" Dewpoint(C)\",conditions['current_observation']['dewpoint_c'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_kph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(KPH)\",conditions['current_observation']['wind_kph'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_gust_kph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(KPH)\",conditions['current_observation']['wind_gust_kph'])\n\t\t\t\tif isFloat(conditions['current_observation']['pressure_mb']):\n\t\t\t\t\tstreamer.log(CITY + \" Pressure(mb)\",conditions['current_observation']['pressure_mb'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_1hr_metric']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(mm)\",conditions['current_observation']['precip_1hr_metric'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_today_metric']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(mm)\",conditions['current_observation']['precip_today_metric'])\n\t\t\telse:\n\t\t\t\tif isFloat(conditions['current_observation']['temp_f']): \n\t\t\t\t\tstreamer.log(CITY + \" Temperature(F)\",conditions['current_observation']['temp_f'])\n\t\t\t\tif isFloat(conditions['current_observation']['dewpoint_f']):\n\t\t\t\t\tstreamer.log(CITY + \" Dewpoint(F)\",conditions['current_observation']['dewpoint_f'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_mph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(MPH)\",conditions['current_observation']['wind_mph'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_gust_mph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(MPH)\",conditions['current_observation']['wind_gust_mph'])\n\t\t\t\tif isFloat(conditions['current_observation']['pressure_in']):\n\t\t\t\t\tstreamer.log(CITY + \" Pressure(IN)\",conditions['current_observation']['pressure_in'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_1hr_in']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(IN)\",conditions['current_observation']['precip_1hr_in'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_today_in']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(IN)\",conditions['current_observation']['precip_today_in'])\n\t\t\tif isFloat(conditions['current_observation']['solarradiation']):\n\t\t\t\tstreamer.log(\":sunny: \" + CITY + \" Solar Radiation (watt/m^2)\",conditions['current_observation']['solarradiation'])\n\t\t\tif isFloat(humidity):\n\t\t\t\tstreamer.log(\":droplet: \" + CITY + \" Humidity(%)\",humidity)\n\t\t\tif isFloat(conditions['current_observation']['UV']):\n\t\t\t\tstreamer.log(\":sunny: \" + CITY + \" UV Index:\",conditions['current_observation']['UV'])\n\t\t\tstreamer.flush()\n\t\ttime.sleep(60*MINUTES_BETWEEN_READS)\n\nif __name__ == \"__main__\":\n    main()\n\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2019 Initial State\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Weather API (Dark Sky) + Pi Sense HAT\n![Dark Sky Dashboard](https://github.com/InitialState/darksky/wiki/img/darksky_dashboard.jpg)\nThis is a hub for the Hyper-local Weather Dashboard: Weather API (Dark Sky) + Pi Sense HAT.\n\nHere you will find code materials for the tutorial as well as the tutorial itself in the [wiki](https://github.com/InitialState/wunderground-sensehat/wiki).\n\nLet's face it, we humans talk about the weather a lot ⛅️. The average person talks about the weather four times a day, for an average of 8 minutes and 21 seconds. Do the math and that totals 10 months of your life that you will spend yapping about the weather. The weather ranks as the #1 go-to topic for conversation starters and uncomfortable silence breakers. If we are going to talk about it that much, we might as well take our weather street cred to a whole new level. This super-fun and easy project will leverage the Internet of Things (IoT) and a Raspberry Pi to do just that ... [read more](https://github.com/InitialState/wunderground-sensehat/wiki)\n"
  },
  {
    "path": "darksky.py",
    "content": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nfrom ISStreamer.Streamer import Streamer\n\n# --------- User Settings ---------\nCITY = \"Franklin\"\nGPS_COORDS = \"35.9260096,-86.868537\"\nDARKSKY_API_KEY = \"PLACE YOUR DARK SKY API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"ds1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_current_conditions():\n\tapi_conditions_url = \"https://api.darksky.net/forecast/\" + DARKSKY_API_KEY + \"/\" + GPS_COORDS + \"?units=auto\"\n\ttry:\n\t\tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\treturn []\n\tjson_currently = f.read()\n\tf.close()\n\treturn json.loads(json_currently)\n\ndef moon_icon(moon_phase):\n\tif moon_phase == 0:\n\t\treturn \":new_moon:\"\n\tif moon_phase < .125:\n\t\treturn \":waxing_crescent_moon:\"\n\tif moon_phase < .25:\n\t\treturn \":first_quarter_moon:\"\n\tif moon_phase < .48:\n\t\treturn \":waxing_gibbous_moon:\"\n\tif moon_phase < .52:\n\t\treturn \":full_moon:\"\n\tif moon_phase < .625:\n\t\treturn \":waning_gibbous_moon:\"\n\tif moon_phase < .75:\n\t\treturn \":last_quarter_moon:\"\n\tif moon_phase < 1:\n\t\treturn \":waning_crescent_moon:\"\n\treturn \":crescent_moon:\"\n\ndef weather_icon(ds_icon):\n\ticon = {\n\t\t\"clear-day\"            \t: \":sunny:\",\n\t\t\"clear-night\"           : \":new_moon_with_face:\",\n\t\t\"rain\"                  : \":umbrella:\",\n\t\t\"snow\"                  : \":snowflake:\",\n\t\t\"sleet\"                 : \":sweat_drops: :snowflake:\",\n\t\t\"wind\"                  : \":wind_blowing_face:\",\n\t\t\"fog\"                   : \":fog:\",\n\t\t\"cloudy\"                : \":cloud:\",\n\t\t\"partly-cloudy-day\"     : \":partly_sunny:\",\n\t\t\"partly-cloudy-night\"   : \":new_moon_with_face:\",\n\t\t\"unknown\"               : \":sun_with_face:\",\n\t}\n\treturn icon.get(ds_icon,\":sun_with_face:\")\n\ndef weather_status_icon(ds_icon,moon_phase):\n\ticon = weather_icon(ds_icon)\n\tif (icon == \":new_moon_with_face:\"):\n\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon(wind_bearing):\n\tif (wind_bearing < 20):\n\t\treturn \":arrow_up:\"\n\tif (wind_bearing < 70):\n\t\treturn \":arrow_upper_right:\"\n\tif (wind_bearing < 110):\n\t\treturn \":arrow_right:\"\n\tif (wind_bearing < 160):\n\t\treturn \":arrow_lower_right:\"\n\tif (wind_bearing < 200):\n\t\treturn \":arrow_down:\"\n\tif (wind_bearing < 250):\n\t\treturn \":arrow_lower_left:\"\n\tif (wind_bearing < 290):\n\t\treturn \":arrow_left:\"\n\tif (wind_bearing < 340):\n\t\treturn \":arrow_upper_left:\"\n\treturn \":arrow_up:\"\n\ndef main():\n\tcurr_conditions = get_current_conditions()\n\tif ('currently' not in curr_conditions):\n\t\tprint \"Error! Dark Sky API call failed, check your GPS coordinates and make sure your Dark Sky API key is valid!\\n\"\n\t\tprint curr_conditions\n\t\texit()\n\telse:\n\t\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\twhile True:\n\t\t\n\t\tcurr_conditions = get_current_conditions()\n\t\tif ('currently' not in curr_conditions):\n\t\t\tprint \"Error! Dark Sky API call failed. Skipping a reading then continuing ...\\n\"\n\t\t\tprint curr_conditions\n\t\telse:\n\t\t\tstreamer.log(\":house: Location\",GPS_COORDS)\n\t\t\t\n\t\t\tif 'humidity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['humidity']):\n\t\t\t\tstreamer.log(\":droplet: Humidity(%)\", curr_conditions['currently']['humidity']*100)\n\n\t\t\tif 'temperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['temperature']): \n\t\t\t\tstreamer.log(\"Temperature\",curr_conditions['currently']['temperature'])\n\n\t\t\tif 'apparentTemperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['apparentTemperature']): \n\t\t\t\tstreamer.log(\"Feels Like\",curr_conditions['currently']['apparentTemperature'])\n\n\t\t\tif 'dewPoint' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['dewPoint']):\n\t\t\t\tstreamer.log(\"Dewpoint\",curr_conditions['currently']['dewPoint'])\n\n\t\t\tif 'windSpeed' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windSpeed']):\n\t\t\t\tstreamer.log(\":dash: Wind Speed\",curr_conditions['currently']['windSpeed'])\n\n\t\t\tif 'windGust' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windGust']):\n\t\t\t\tstreamer.log(\":dash: Wind Gust\",curr_conditions['currently']['windGust'])\n\n\t\t\tif 'windBearing' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windBearing']):\n\t\t\t\tstreamer.log(\":dash: Wind Direction\",wind_dir_icon(curr_conditions['currently']['windBearing']))\n\n\t\t\tif 'pressure' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['pressure']):\n\t\t\t\tstreamer.log(\"Pressure\",curr_conditions['currently']['pressure'])\n\n\t\t\tif 'precipIntensity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipIntensity']):\n\t\t\t\tstreamer.log(\":umbrella: Precipitation Intensity\",curr_conditions['currently']['precipIntensity'])\n\n\t\t\tif 'precipProbability' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipProbability']):\n\t\t\t\tstreamer.log(\":umbrella: Precipitation Probabiity(%)\",curr_conditions['currently']['precipProbability']*100)\n\n\t\t\tif 'cloudCover' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['cloudCover']):\n\t\t\t\tstreamer.log(\":cloud: Cloud Cover(%)\",curr_conditions['currently']['cloudCover']*100)\n\n\t\t\tif 'uvIndex' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['uvIndex']):\n\t\t\t\tstreamer.log(\":sunny: UV Index:\",curr_conditions['currently']['uvIndex'])\n\n\t\t\tif 'summary' in curr_conditions['currently']:\n\t\t\t\tstreamer.log(\":cloud: Weather Summary\",curr_conditions['currently']['summary'])\n\n\t\t\tif 'hourly' in curr_conditions:\n\t\t\t\tstreamer.log(\"Today's Forecast\",curr_conditions['hourly']['summary'])\n\n\t\t\tif 'daily' in curr_conditions:\n\t\t\t\tif 'data' in curr_conditions['daily']:\n\t\t\t\t\tif 'moonPhase' in curr_conditions['daily']['data'][0]:\n\t\t\t\t\t\tmoon_phase = curr_conditions['daily']['data'][0]['moonPhase']\n\t\t\t\t\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(moon_phase))\n\t\t\t\t\t\tstreamer.log(\":cloud: Weather Conditions\",weather_status_icon(curr_conditions['currently']['icon'],moon_phase))\n\n\t\t\tstreamer.flush()\n\t\ttime.sleep(60*MINUTES_BETWEEN_READS)\n\nif __name__ == \"__main__\":\n    main()\n    \n"
  },
  {
    "path": "sensehat.py",
    "content": "from sense_hat import SenseHat  \nimport time  \nimport sys  \nfrom ISStreamer.Streamer import Streamer  \n  \n# --------- User Settings ---------\nCITY = \"Nashville\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"sensehat\"\nACCESS_KEY = \"Your_Access_Key\"\nSENSOR_LOCATION_NAME = \"Office\"\nMINUTES_BETWEEN_SENSEHAT_READS = 0.1\n# ---------------------------------\n\nstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n  \nsense = SenseHat()  \n  \nwhile True:\n  # Read the sensors\n  temp_c = sense.get_temperature()\n  humidity = sense.get_humidity() \n  pressure_mb = sense.get_pressure() \n\n  # Format the data\n  temp_f = temp_c * 9.0 / 5.0 + 32.0\n  temp_f = float(\"{0:.2f}\".format(temp_f))\n  humidity = float(\"{0:.2f}\".format(humidity))\n  pressure_in = 0.03937008*(pressure_mb)\n  pressure_in = float(\"{0:.2f}\".format(pressure_in))\n\n  # Print and stream \n  print SENSOR_LOCATION_NAME + \" Temperature(F): \" + str(temp_f)\n  print SENSOR_LOCATION_NAME + \" Humidity(%): \" + str(humidity)\n  print SENSOR_LOCATION_NAME + \" Pressure(IN): \" + str(pressure_in)\n  streamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(F)\", temp_f)\n  streamer.log(\":sweat_drops: \" + SENSOR_LOCATION_NAME + \" Humidity(%)\", humidity)\n  streamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure(IN)\", pressure_in)\n\n  streamer.flush()\n  time.sleep(60*MINUTES_BETWEEN_SENSEHAT_READS)"
  },
  {
    "path": "sensehat_darksky.py",
    "content": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Streamer\nfrom sense_hat import SenseHat \n\n# --------- User Settings ---------\nCITY = \"Franklin\"\nGPS_COORDS = \"35.9260096,-86.868537\"\nSENSOR_LOCATION_NAME = \"Office\"\nDARKSKY_API_KEY = \"PLACE YOUR DARK SKY API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"shds1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_current_conditions():\n\tapi_conditions_url = \"https://api.darksky.net/forecast/\" + DARKSKY_API_KEY + \"/\" + GPS_COORDS + \"?units=auto\"\n\ttry:\n\t\tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\treturn []\n\tjson_currently = f.read()\n\tf.close()\n\treturn json.loads(json_currently)\n\ndef moon_icon(moon_phase):\n\tif moon_phase == 0:\n\t\treturn \":new_moon:\"\n\tif moon_phase < .125:\n\t\treturn \":waxing_crescent_moon:\"\n\tif moon_phase < .25:\n\t\treturn \":first_quarter_moon:\"\n\tif moon_phase < .48:\n\t\treturn \":waxing_gibbous_moon:\"\n\tif moon_phase < .52:\n\t\treturn \":full_moon:\"\n\tif moon_phase < .625:\n\t\treturn \":waning_gibbous_moon:\"\n\tif moon_phase < .75:\n\t\treturn \":last_quarter_moon:\"\n\tif moon_phase < 1:\n\t\treturn \":waning_crescent_moon:\"\n\treturn \":crescent_moon:\"\n\ndef weather_icon(ds_icon):\n\ticon = {\n\t\t\"clear-day\"            \t: \":sunny:\",\n\t\t\"clear-night\"           : \":new_moon_with_face:\",\n\t\t\"rain\"                  : \":umbrella:\",\n\t\t\"snow\"                  : \":snowflake:\",\n\t\t\"sleet\"                 : \":sweat_drops: :snowflake:\",\n\t\t\"wind\"                  : \":wind_blowing_face:\",\n\t\t\"fog\"                   : \":fog:\",\n\t\t\"cloudy\"                : \":cloud:\",\n\t\t\"partly-cloudy-day\"     : \":partly_sunny:\",\n\t\t\"partly-cloudy-night\"   : \":new_moon_with_face:\",\n\t\t\"unknown\"               : \":sun_with_face:\",\n\t}\n\treturn icon.get(ds_icon,\":sun_with_face:\")\n\ndef weather_status_icon(ds_icon,moon_phase):\n\ticon = weather_icon(ds_icon)\n\tif (icon == \":new_moon_with_face:\"):\n\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon(wind_bearing):\n\tif (wind_bearing < 20):\n\t\treturn \":arrow_up:\"\n\tif (wind_bearing < 70):\n\t\treturn \":arrow_upper_right:\"\n\tif (wind_bearing < 110):\n\t\treturn \":arrow_right:\"\n\tif (wind_bearing < 160):\n\t\treturn \":arrow_lower_right:\"\n\tif (wind_bearing < 200):\n\t\treturn \":arrow_down:\"\n\tif (wind_bearing < 250):\n\t\treturn \":arrow_lower_left:\"\n\tif (wind_bearing < 290):\n\t\treturn \":arrow_left:\"\n\tif (wind_bearing < 340):\n\t\treturn \":arrow_upper_left:\"\n\treturn \":arrow_up:\"\n\ndef main():\n\tsense = SenseHat()\t\n\tcurr_conditions = get_current_conditions()\n\tif ('currently' not in curr_conditions):\n\t\tprint \"Error! Dark Sky API call failed, check your GPS coordinates and make sure your Dark Sky API key is valid!\\n\"\n\t\tprint curr_conditions\n\t\texit()\n\telse:\n\t\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\twhile True:\n\t\t# -------------- Sense Hat --------------\n\t\t# Read the sensors\n\t\ttemp_c = sense.get_temperature()\n\t\thumidity = sense.get_humidity() \n\t\tpressure_mb = sense.get_pressure() \n\n\t\t# Format the data\n\t\ttemp_f = temp_c * 9.0 / 5.0 + 32.0\n\t\ttemp_f = float(\"{0:.2f}\".format(temp_f))\n\t\ttemp_c = float(\"{0:.2f}\".format(temp_c))\n\t\thumidity = float(\"{0:.2f}\".format(humidity))\n\t\tpressure_in = 0.0295301*(pressure_mb)\n\t\tpressure_in = float(\"{0:.2f}\".format(pressure_in))\n\t\tpressure_mb = float(\"{0:.2f}\".format(pressure_mb))\n\n\t\t# Print and stream \n\t\tif (METRIC_UNITS):\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(C): \" + str(temp_c)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(mb): \" + str(pressure_mb)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(C)\", temp_c)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (mb)\", pressure_mb)\n\t\telse:\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(F): \" + str(temp_f)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(IN): \" + str(pressure_in)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(F)\", temp_f)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (IN)\", pressure_in)\n\t\tprint SENSOR_LOCATION_NAME + \" Humidity(%): \" + str(humidity)\n\t\tstreamer.log(\":sweat_drops: \" + SENSOR_LOCATION_NAME + \" Humidity(%)\", humidity)\n\n\t\t# -------------- Dark Sky --------------\t\t\n\t\tcurr_conditions = get_current_conditions()\n\t\tif ('currently' not in curr_conditions):\n\t\t\tprint \"Error! Dark Sky API call failed. Skipping a reading then continuing ...\\n\"\n\t\t\tprint curr_conditions\n\t\telse:\n\t\t\tstreamer.log(\":house: Location\",GPS_COORDS)\n\t\t\t\n\t\t\tif 'humidity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['humidity']):\n\t\t\t\tstreamer.log(\":droplet: Humidity(%)\", curr_conditions['currently']['humidity']*100)\n\n\t\t\tif 'temperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['temperature']): \n\t\t\t\tstreamer.log(\"Temperature\",curr_conditions['currently']['temperature'])\n\n\t\t\tif 'apparentTemperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['apparentTemperature']): \n\t\t\t\tstreamer.log(\"Feels Like\",curr_conditions['currently']['apparentTemperature'])\n\n\t\t\tif 'dewPoint' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['dewPoint']):\n\t\t\t\tstreamer.log(\"Dewpoint\",curr_conditions['currently']['dewPoint'])\n\n\t\t\tif 'windSpeed' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windSpeed']):\n\t\t\t\tstreamer.log(\":dash: Wind Speed\",curr_conditions['currently']['windSpeed'])\n\n\t\t\tif 'windGust' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windGust']):\n\t\t\t\tstreamer.log(\":dash: Wind Gust\",curr_conditions['currently']['windGust'])\n\n\t\t\tif 'windBearing' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windBearing']):\n\t\t\t\tstreamer.log(\":dash: Wind Direction\",wind_dir_icon(curr_conditions['currently']['windBearing']))\n\n\t\t\tif 'pressure' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['pressure']):\n\t\t\t\tstreamer.log(\"Pressure\",curr_conditions['currently']['pressure'])\n\n\t\t\tif 'precipIntensity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipIntensity']):\n\t\t\t\tstreamer.log(\":umbrella: Precipitation Intensity\",curr_conditions['currently']['precipIntensity'])\n\n\t\t\tif 'precipProbability' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipProbability']):\n\t\t\t\tstreamer.log(\":umbrella: Precipitation Probabiity(%)\",curr_conditions['currently']['precipProbability']*100)\n\n\t\t\tif 'cloudCover' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['cloudCover']):\n\t\t\t\tstreamer.log(\":cloud: Cloud Cover(%)\",curr_conditions['currently']['cloudCover']*100)\n\n\t\t\tif 'uvIndex' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['uvIndex']):\n\t\t\t\tstreamer.log(\":sunny: UV Index:\",curr_conditions['currently']['uvIndex'])\n\n\t\t\tif 'summary' in curr_conditions['currently']:\n\t\t\t\tstreamer.log(\":cloud: Weather Summary\",curr_conditions['currently']['summary'])\n\n\t\t\tif 'hourly' in curr_conditions:\n\t\t\t\tstreamer.log(\"Today's Forecast\",curr_conditions['hourly']['summary'])\n\n\t\t\tif 'daily' in curr_conditions:\n\t\t\t\tif 'data' in curr_conditions['daily']:\n\t\t\t\t\tif 'moonPhase' in curr_conditions['daily']['data'][0]:\n\t\t\t\t\t\tmoon_phase = curr_conditions['daily']['data'][0]['moonPhase']\n\t\t\t\t\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(moon_phase))\n\t\t\t\t\t\tstreamer.log(\":cloud: Weather Conditions\",weather_status_icon(curr_conditions['currently']['icon'],moon_phase))\n\n\t\t\tstreamer.flush()\n\t\ttime.sleep(60*MINUTES_BETWEEN_READS)\n\nif __name__ == \"__main__\":\n    main()\n\n"
  },
  {
    "path": "sensehat_darksky_calibrated.py",
    "content": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Streamer\nfrom sense_hat import SenseHat \nimport subprocess\n\n# --------- User Settings ---------\nCITY = \"Franklin\"\nGPS_COORDS = \"35.9260096,-86.868537\"\nSENSOR_LOCATION_NAME = \"Office\"\nDARKSKY_API_KEY = \"PLACE YOUR DARK SKY API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"shds1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_current_conditions():\n\tapi_conditions_url = \"https://api.darksky.net/forecast/\" + DARKSKY_API_KEY + \"/\" + GPS_COORDS + \"?units=auto\"\n\ttry:\n\t\tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\treturn []\n\tjson_currently = f.read()\n\tf.close()\n\treturn json.loads(json_currently)\n\ndef moon_icon(moon_phase):\n\tif moon_phase == 0:\n\t\treturn \":new_moon:\"\n\tif moon_phase < .125:\n\t\treturn \":waxing_crescent_moon:\"\n\tif moon_phase < .25:\n\t\treturn \":first_quarter_moon:\"\n\tif moon_phase < .48:\n\t\treturn \":waxing_gibbous_moon:\"\n\tif moon_phase < .52:\n\t\treturn \":full_moon:\"\n\tif moon_phase < .625:\n\t\treturn \":waning_gibbous_moon:\"\n\tif moon_phase < .75:\n\t\treturn \":last_quarter_moon:\"\n\tif moon_phase < 1:\n\t\treturn \":waning_crescent_moon:\"\n\treturn \":crescent_moon:\"\n\ndef weather_icon(ds_icon):\n\ticon = {\n\t\t\"clear-day\"            \t: \":sunny:\",\n\t\t\"clear-night\"           : \":new_moon_with_face:\",\n\t\t\"rain\"                  : \":umbrella:\",\n\t\t\"snow\"                  : \":snowflake:\",\n\t\t\"sleet\"                 : \":sweat_drops: :snowflake:\",\n\t\t\"wind\"                  : \":wind_blowing_face:\",\n\t\t\"fog\"                   : \":fog:\",\n\t\t\"cloudy\"                : \":cloud:\",\n\t\t\"partly-cloudy-day\"     : \":partly_sunny:\",\n\t\t\"partly-cloudy-night\"   : \":new_moon_with_face:\",\n\t\t\"unknown\"               : \":sun_with_face:\",\n\t}\n\treturn icon.get(ds_icon,\":sun_with_face:\")\n\ndef weather_status_icon(ds_icon,moon_phase):\n\ticon = weather_icon(ds_icon)\n\tif (icon == \":new_moon_with_face:\"):\n\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon(wind_bearing):\n\tif (wind_bearing < 20):\n\t\treturn \":arrow_up:\"\n\tif (wind_bearing < 70):\n\t\treturn \":arrow_upper_right:\"\n\tif (wind_bearing < 110):\n\t\treturn \":arrow_right:\"\n\tif (wind_bearing < 160):\n\t\treturn \":arrow_lower_right:\"\n\tif (wind_bearing < 200):\n\t\treturn \":arrow_down:\"\n\tif (wind_bearing < 250):\n\t\treturn \":arrow_lower_left:\"\n\tif (wind_bearing < 290):\n\t\treturn \":arrow_left:\"\n\tif (wind_bearing < 340):\n\t\treturn \":arrow_upper_left:\"\n\treturn \":arrow_up:\"\n\ndef main():\n\tsense = SenseHat()\t\n\tcurr_conditions = get_current_conditions()\n\tif ('currently' not in curr_conditions):\n\t\tprint \"Error! Dark Sky API call failed, check your GPS coordinates and make sure your Dark Sky API key is valid!\\n\"\n\t\tprint curr_conditions\n\t\texit()\n\telse:\n\t\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\twhile True:\n\t\t# -------------- Sense Hat --------------\n\t\t# Read the sensors\n\t\ttemp_c = sense.get_temperature()\n\t\thumidity = sense.get_humidity() \n\t\tpressure_mb = sense.get_pressure() \n    \t\tcpu_temp = subprocess.check_output(\"vcgencmd measure_temp\", shell=True)\n    \t\tarray = cpu_temp.split(\"=\")\n    \t\tarray2 = array[1].split(\"'\")\n\n    \t\tcpu_tempc = float(array2[0])\n    \t\tcpu_tempc = float(\"{0:.2f}\".format(cpu_tempc))\n    \t\tcpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0\n    \t\tcpu_tempf = float(\"{0:.2f}\".format(cpu_tempf))\n\n    \t\ttemp_calibrated_c = temp_c - ((cpu_tempc - temp_c)/5.466)\n    \n\t\t# Format the data\n\t\ttemp_f = temp_calibrated_c * 9.0 / 5.0 + 32.0\n\t\ttemp_f = float(\"{0:.2f}\".format(temp_f))\n\t\ttemp_calibrated_c = float(\"{0:.2f}\".format(temp_calibrated_c))\n\t\thumidity = float(\"{0:.2f}\".format(humidity))\n\t\tpressure_in = 0.0295301*(pressure_mb)\n\t\tpressure_in = float(\"{0:.2f}\".format(pressure_in))\n\t\tpressure_mb = float(\"{0:.2f}\".format(pressure_mb))\n\n\t\t# Print and stream \n\t\tif (METRIC_UNITS):\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(C): \" + str(temp_calibrated_c)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(mb): \" + str(pressure_mb)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(C)\", temp_calibrated_c)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (mb)\", pressure_mb)\n\t\t\tprint \"CPU Temperature(C): \" + str(cpu_tempc)\n\t\t\tstreamer.log(\"CPU Temperature\",cpu_tempc)\n\t\telse:\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(F): \" + str(temp_f)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(IN): \" + str(pressure_in)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(F)\", temp_f)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (IN)\", pressure_in)\n\t\t\tprint \"CPU Temperature(F): \" + str(cpu_tempf)\n\t\t\tstreamer.log(\"CPU Temperature\",cpu_tempf)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Humidity(%): \" + str(humidity)\n\t\t\tstreamer.log(\":sweat_drops: \" + SENSOR_LOCATION_NAME + \" Humidity(%)\", humidity)\n\n\t\t# -------------- Dark Sky --------------\t\t\n\t\tcurr_conditions = get_current_conditions()\n\t\tif ('currently' not in curr_conditions):\n\t\t\tprint \"Error! Dark Sky API call failed. Skipping a reading then continuing ...\\n\"\n\t\t\tprint curr_conditions\n\t\telse:\n\t\t\tstreamer.log(\":house: Location\",GPS_COORDS)\n\t\t\t\n\t\t\tif 'humidity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['humidity']):\n\t\t\t\tstreamer.log(\":droplet: Humidity(%)\", curr_conditions['currently']['humidity']*100)\n\n\t\t\tif 'temperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['temperature']): \n\t\t\t\tstreamer.log(\"Temperature\",curr_conditions['currently']['temperature'])\n\n\t\t\tif 'apparentTemperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['apparentTemperature']): \n\t\t\t\tstreamer.log(\"Feels Like\",curr_conditions['currently']['apparentTemperature'])\n\n\t\t\tif 'dewPoint' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['dewPoint']):\n\t\t\t\tstreamer.log(\"Dewpoint\",curr_conditions['currently']['dewPoint'])\n\n\t\t\tif 'windSpeed' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windSpeed']):\n\t\t\t\tstreamer.log(\":dash: Wind Speed\",curr_conditions['currently']['windSpeed'])\n\n\t\t\tif 'windGust' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windGust']):\n\t\t\t\tstreamer.log(\":dash: Wind Gust\",curr_conditions['currently']['windGust'])\n\n\t\t\tif 'windBearing' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windBearing']):\n\t\t\t\tstreamer.log(\":dash: Wind Direction\",wind_dir_icon(curr_conditions['currently']['windBearing']))\n\n\t\t\tif 'pressure' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['pressure']):\n\t\t\t\tstreamer.log(\"Pressure\",curr_conditions['currently']['pressure'])\n\n\t\t\tif 'precipIntensity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipIntensity']):\n\t\t\t\tstreamer.log(\":umbrella: Precipitation Intensity\",curr_conditions['currently']['precipIntensity'])\n\n\t\t\tif 'precipProbability' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipProbability']):\n\t\t\t\tstreamer.log(\":umbrella: Precipitation Probabiity(%)\",curr_conditions['currently']['precipProbability']*100)\n\n\t\t\tif 'cloudCover' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['cloudCover']):\n\t\t\t\tstreamer.log(\":cloud: Cloud Cover(%)\",curr_conditions['currently']['cloudCover']*100)\n\n\t\t\tif 'uvIndex' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['uvIndex']):\n\t\t\t\tstreamer.log(\":sunny: UV Index:\",curr_conditions['currently']['uvIndex'])\n\n\t\t\tif 'summary' in curr_conditions['currently']:\n\t\t\t\tstreamer.log(\":cloud: Weather Summary\",curr_conditions['currently']['summary'])\n\n\t\t\tif 'hourly' in curr_conditions:\n\t\t\t\tstreamer.log(\"Today's Forecast\",curr_conditions['hourly']['summary'])\n\n\t\t\tif 'daily' in curr_conditions:\n\t\t\t\tif 'data' in curr_conditions['daily']:\n\t\t\t\t\tif 'moonPhase' in curr_conditions['daily']['data'][0]:\n\t\t\t\t\t\tmoon_phase = curr_conditions['daily']['data'][0]['moonPhase']\n\t\t\t\t\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(moon_phase))\n\t\t\t\t\t\tstreamer.log(\":cloud: Weather Conditions\",weather_status_icon(curr_conditions['currently']['icon'],moon_phase))\n\n\t\t\tstreamer.flush()\n\t\ttime.sleep(60*MINUTES_BETWEEN_READS)\n\nif __name__ == \"__main__\":\n    main()\n\n"
  },
  {
    "path": "sensehat_wunderground.py",
    "content": "import os\nimport urllib2\nimport json\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Streamer\nfrom sense_hat import SenseHat \n\n# --------- User Settings ---------\nSTATE = \"CA\"\nCITY = \"San_Francisco\"\nSENSOR_LOCATION_NAME = \"Office\"\nWUNDERGROUND_API_KEY = \"PLACE YOUR WUNDERGROUND API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"shwu1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_conditions():\n\tapi_conditions_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/conditions/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t  \tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\tprint \"Failed to get conditions\"\n\t\treturn []\n\tjson_conditions = f.read()\n\tf.close()\n\treturn json.loads(json_conditions)\n\ndef get_astronomy():\n\tapi_astronomy_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/astronomy/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t\tf = urllib2.urlopen(api_astronomy_url)\n\texcept:\n\t\tprint \"Failed to get astronomy\"\n\t\treturn []\t\t\n\tjson_astronomy = f.read()\n\tf.close()\n\treturn json.loads(json_astronomy)\n\ndef is_night(astronomy):\n\tsunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])\n\tsunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])\n\tsunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])\n\tsunset_min   = int(astronomy['moon_phase']['sunset']['minute'])\n\tcurrent_hour = int(astronomy['moon_phase']['current_time']['hour'])\n\tcurrent_min  = int(astronomy['moon_phase']['current_time']['minute'])\n\tif ( (current_hour < sunrise_hour) or\n\t     (current_hour > sunset_hour) or\n\t     ((current_hour == sunrise_hour) and\n\t      (current_min < sunrise_min)) or \n\t     ((current_hour == sunset_hour) and\n\t      (current_min > sunset_min)) ):\n\t\treturn True\n\treturn False\n\ndef moon_icon(moon_phase):\n\ticon = {\n\t\t\"New Moon\"        : \":new_moon:\",\n\t\t\"Waxing Crescent\" : \":waxing_crescent_moon:\",\n\t\t\"First Quarter\"   : \":first_quarter_moon:\",\n\t\t\"Waxing Gibbous\"  : \":waxing_gibbous_moon:\",\n\t\t\"Full Moon\"       : \":full_moon:\",\n\t\t\"Full\"            : \":full_moon:\",\n\t\t\"Waning Gibbous\"  : \":waning_gibbous_moon:\",\n\t\t\"Last Quarter\"    : \":last_quarter_moon:\",\n\t\t\"Waning Crescent\" : \":waning_crescent_moon:\",\n\t}\n\treturn icon.get(moon_phase,\":crescent_moon:\")\n\ndef weather_icon(weather_conditions):\n\ticon = {\n\t\t\"clear\"            : \":sun_with_face:\",\n\t\t\"cloudy\"           : \":cloud:\",\n\t\t\"flurries\"         : \":snowflake:\",\n\t\t\"fog\"              : \":foggy:\",\n\t\t\"hazy\"             : \":foggy:\",\n\t\t\"mostlycloudy\"     : \":cloud:\",\n\t\t\"mostlysunny\"      : \":sun_with_face:\",\n\t\t\"partlycloudy\"     : \":partly_sunny:\",\n\t\t\"partlysunny\"      : \":partly_sunny:\",\n\t\t\"sleet\"            : \":sweat_drops: :snowflake:\",\n\t\t\"rain\"             : \":umbrella:\",\n\t\t\"snow\"             : \":snowflake:\",\n\t\t\"sunny\"            : \":sun_with_face:\",\n\t\t\"tstorms\"          : \":zap: :umbrella:\",\n\t\t\"unknown\"          : \":sun_with_face:\",\n\t}\n\treturn icon.get(weather_conditions,\":sun_with_face:\")\n\ndef weather_status_icon(conditions, astronomy):\n\tmoon_phase = astronomy['moon_phase']['phaseofMoon']\n\tweather_conditions = conditions['current_observation']['icon']\n\ticon = weather_icon(weather_conditions)\n\tif is_night(astronomy):\n\t\tif ((icon == \":sunny:\") or\n\t\t    (icon == \":partly_sunny:\") or\n\t\t    (icon == \":sun_with_face:\")):\n\t\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon(conditions, astronomy):\n\ticon = {\n\t\t\"East\"     : \":arrow_right:\",\n\t\t\"ENE\"      : \":arrow_upper_right:\",\n\t\t\"ESE\"      : \":arrow_lower_right:\",\n\t\t\"NE\"       : \":arrow_upper_right:\",\n\t\t\"NNE\"      : \":arrow_upper_right:\",\n\t\t\"NNW\"      : \":arrow_upper_left:\",\n\t\t\"North\"    : \":arrow_up:\",\n\t\t\"NW\"       : \":arrow_upper_left:\",\n\t\t\"SE\"       : \":arrow_lower_right:\",\n\t\t\"South\"    : \":arrow_down:\",\n\t\t\"SSE\"      : \":arrow_lower_right:\",\n\t\t\"SSW\"      : \":arrow_lower_left:\",\n\t\t\"SW\"       : \":arrow_lower_left:\",\n\t\t\"Variable\" : \":arrows_counterclockwise:\",\n\t\t\"West\"     : \":arrow_left:\",\n\t\t\"WNW\"      : \":arrow_upper_left:\",\n\t\t\"WSW\"      : \":arrow_lower_left:\",\n\t}\n\treturn icon.get(conditions['current_observation']['wind_dir'],\":crescent_moon:\")\t\n\ndef main():\n\tsense = SenseHat()\n\tconditions = get_conditions()\n\tastronomy = get_astronomy()\n\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\tprint \"Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!\"\n\t\tif 'error' in conditions['response']:\n\t\t\tprint \"Error Type: \" + conditions['response']['error']['type']\n\t\t\tprint \"Error Description: \" + conditions['response']['error']['description']\n\t\texit()\n\telse:\n\t\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\t\tstreamer.log(\":house: Location\",conditions['current_observation']['display_location']['full'])\n\twhile True:\n\t\t# -------------- Sense Hat --------------\n\t\t# Read the sensors\n\t\ttemp_c = sense.get_temperature()\n\t\thumidity = sense.get_humidity() \n\t\tpressure_mb = sense.get_pressure() \n\n\t\t# Format the data\n\t\ttemp_f = temp_c * 9.0 / 5.0 + 32.0\n\t\ttemp_f = float(\"{0:.2f}\".format(temp_f))\n\t\ttemp_c = float(\"{0:.2f}\".format(temp_c))\n\t\thumidity = float(\"{0:.2f}\".format(humidity))\n\t\tpressure_in = 0.0295301*(pressure_mb)\n\t\tpressure_in = float(\"{0:.2f}\".format(pressure_in))\n\t\tpressure_mb = float(\"{0:.2f}\".format(pressure_mb))\n\n\t\t# Print and stream \n\t\tif (METRIC_UNITS):\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(C): \" + str(temp_c)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(mb): \" + str(pressure_mb)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(C)\", temp_c)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (mb)\", pressure_mb)\n\t\telse:\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(F): \" + str(temp_f)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(IN): \" + str(pressure_in)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(F)\", temp_f)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (IN)\", pressure_in)\n\t\tprint SENSOR_LOCATION_NAME + \" Humidity(%): \" + str(humidity)\n\t\tstreamer.log(\":sweat_drops: \" + SENSOR_LOCATION_NAME + \" Humidity(%)\", humidity)\n\n\t\t# -------------- Wunderground --------------\n\t\tconditions = get_conditions()\n\t\tastronomy = get_astronomy()\n\t\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\t\tprint \"Error! Wunderground API call failed. Skipping a reading then continuing ...\"\n\t\telse:\n\t\t\thumidity_pct = conditions['current_observation']['relative_humidity']\n\t\t\thumidity = humidity_pct.replace(\"%\",\"\")\n\n\t\t\t# Stream valid conditions to Initial State\n\t\t\tstreamer.log(\":cloud: \" + CITY + \" Weather Conditions\",weather_status_icon(conditions, astronomy))\n\t\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(astronomy['moon_phase']['phaseofMoon']))\n\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Direction\",wind_dir_icon(conditions, astronomy))\n\t\t\tif (METRIC_UNITS):\n\t\t\t\tif isFloat(conditions['current_observation']['temp_c']): \n\t\t\t\t\tstreamer.log(CITY + \" Temperature(C)\",conditions['current_observation']['temp_c'])\n\t\t\t\tif isFloat(conditions['current_observation']['dewpoint_c']):\n\t\t\t\t\tstreamer.log(CITY + \" Dewpoint(C)\",conditions['current_observation']['dewpoint_c'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_kph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(KPH)\",conditions['current_observation']['wind_kph'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_gust_kph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(KPH)\",conditions['current_observation']['wind_gust_kph'])\n\t\t\t\tif isFloat(conditions['current_observation']['pressure_mb']):\n\t\t\t\t\tstreamer.log(CITY + \" Pressure(mb)\",conditions['current_observation']['pressure_mb'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_1hr_metric']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(mm)\",conditions['current_observation']['precip_1hr_metric'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_today_metric']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(mm)\",conditions['current_observation']['precip_today_metric'])\n\t\t\telse:\n\t\t\t\tif isFloat(conditions['current_observation']['temp_f']): \n\t\t\t\t\tstreamer.log(CITY + \" Temperature(F)\",conditions['current_observation']['temp_f'])\n\t\t\t\tif isFloat(conditions['current_observation']['dewpoint_f']):\n\t\t\t\t\tstreamer.log(CITY + \" Dewpoint(F)\",conditions['current_observation']['dewpoint_f'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_mph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(MPH)\",conditions['current_observation']['wind_mph'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_gust_mph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(MPH)\",conditions['current_observation']['wind_gust_mph'])\n\t\t\t\tif isFloat(conditions['current_observation']['pressure_in']):\n\t\t\t\t\tstreamer.log(CITY + \" Pressure(IN)\",conditions['current_observation']['pressure_in'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_1hr_in']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(IN)\",conditions['current_observation']['precip_1hr_in'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_today_in']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(IN)\",conditions['current_observation']['precip_today_in'])\n\t\t\tif isFloat(conditions['current_observation']['solarradiation']):\n\t\t\t\tstreamer.log(\":sunny: \" + CITY + \" Solar Radiation (watt/m^2)\",conditions['current_observation']['solarradiation'])\n\t\t\tif isFloat(humidity):\n\t\t\t\tstreamer.log(\":droplet: \" + CITY + \" Humidity(%)\",humidity)\n\t\t\tif isFloat(conditions['current_observation']['UV']):\n\t\t\t\tstreamer.log(\":sunny: \" + CITY + \" UV Index:\",conditions['current_observation']['UV'])\n\t\t\tstreamer.flush()\n\t\ttime.sleep(60*MINUTES_BETWEEN_READS)\n\nif __name__ == \"__main__\":\n    main()\n\n\n"
  },
  {
    "path": "sensehat_wunderground_calibrated.py",
    "content": "import os\nimport urllib2\nimport json\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Streamer\nfrom sense_hat import SenseHat \nimport subprocess\n\n# --------- User Settings ---------\nSTATE = \"CA\"\nCITY = \"San_Francisco\"\nSENSOR_LOCATION_NAME = \"Office\"\nWUNDERGROUND_API_KEY = \"PLACE YOUR WUNDERGROUND API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"shwu1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_conditions():\n\tapi_conditions_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/conditions/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t  \tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\tprint \"Failed to get conditions\"\n\t\treturn []\n\tjson_conditions = f.read()\n\tf.close()\n\treturn json.loads(json_conditions)\n\ndef get_astronomy():\n\tapi_astronomy_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/astronomy/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t\tf = urllib2.urlopen(api_astronomy_url)\n\texcept:\n\t\tprint \"Failed to get astronomy\"\n\t\treturn []\t\t\n\tjson_astronomy = f.read()\n\tf.close()\n\treturn json.loads(json_astronomy)\n\ndef is_night(astronomy):\n\tsunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])\n\tsunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])\n\tsunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])\n\tsunset_min   = int(astronomy['moon_phase']['sunset']['minute'])\n\tcurrent_hour = int(astronomy['moon_phase']['current_time']['hour'])\n\tcurrent_min  = int(astronomy['moon_phase']['current_time']['minute'])\n\tif ( (current_hour < sunrise_hour) or\n\t     (current_hour > sunset_hour) or\n\t     ((current_hour == sunrise_hour) and\n\t      (current_min < sunrise_min)) or \n\t     ((current_hour == sunset_hour) and\n\t      (current_min > sunset_min)) ):\n\t\treturn True\n\treturn False\n\ndef moon_icon(moon_phase):\n\ticon = {\n\t\t\"New Moon\"        : \":new_moon:\",\n\t\t\"Waxing Crescent\" : \":waxing_crescent_moon:\",\n\t\t\"First Quarter\"   : \":first_quarter_moon:\",\n\t\t\"Waxing Gibbous\"  : \":waxing_gibbous_moon:\",\n\t\t\"Full Moon\"       : \":full_moon:\",\n\t\t\"Full\"            : \":full_moon:\",\n\t\t\"Waning Gibbous\"  : \":waning_gibbous_moon:\",\n\t\t\"Last Quarter\"    : \":last_quarter_moon:\",\n\t\t\"Waning Crescent\" : \":waning_crescent_moon:\",\n\t}\n\treturn icon.get(moon_phase,\":crescent_moon:\")\n\ndef weather_icon(weather_conditions):\n\ticon = {\n\t\t\"clear\"            : \":sun_with_face:\",\n\t\t\"cloudy\"           : \":cloud:\",\n\t\t\"flurries\"         : \":snowflake:\",\n\t\t\"fog\"              : \":foggy:\",\n\t\t\"hazy\"             : \":foggy:\",\n\t\t\"mostlycloudy\"     : \":cloud:\",\n\t\t\"mostlysunny\"      : \":sun_with_face:\",\n\t\t\"partlycloudy\"     : \":partly_sunny:\",\n\t\t\"partlysunny\"      : \":partly_sunny:\",\n\t\t\"sleet\"            : \":sweat_drops: :snowflake:\",\n\t\t\"rain\"             : \":umbrella:\",\n\t\t\"snow\"             : \":snowflake:\",\n\t\t\"sunny\"            : \":sun_with_face:\",\n\t\t\"tstorms\"          : \":zap: :umbrella:\",\n\t\t\"unknown\"          : \":sun_with_face:\",\n\t}\n\treturn icon.get(weather_conditions,\":sun_with_face:\")\n\ndef weather_status_icon(conditions, astronomy):\n\tmoon_phase = astronomy['moon_phase']['phaseofMoon']\n\tweather_conditions = conditions['current_observation']['icon']\n\ticon = weather_icon(weather_conditions)\n\tif is_night(astronomy):\n\t\tif ((icon == \":sunny:\") or\n\t\t    (icon == \":partly_sunny:\") or\n\t\t    (icon == \":sun_with_face:\")):\n\t\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon(conditions, astronomy):\n\ticon = {\n\t\t\"East\"     : \":arrow_right:\",\n\t\t\"ENE\"      : \":arrow_upper_right:\",\n\t\t\"ESE\"      : \":arrow_lower_right:\",\n\t\t\"NE\"       : \":arrow_upper_right:\",\n\t\t\"NNE\"      : \":arrow_upper_right:\",\n\t\t\"NNW\"      : \":arrow_upper_left:\",\n\t\t\"North\"    : \":arrow_up:\",\n\t\t\"NW\"       : \":arrow_upper_left:\",\n\t\t\"SE\"       : \":arrow_lower_right:\",\n\t\t\"South\"    : \":arrow_down:\",\n\t\t\"SSE\"      : \":arrow_lower_right:\",\n\t\t\"SSW\"      : \":arrow_lower_left:\",\n\t\t\"SW\"       : \":arrow_lower_left:\",\n\t\t\"Variable\" : \":arrows_counterclockwise:\",\n\t\t\"West\"     : \":arrow_left:\",\n\t\t\"WNW\"      : \":arrow_upper_left:\",\n\t\t\"WSW\"      : \":arrow_lower_left:\",\n\t}\n\treturn icon.get(conditions['current_observation']['wind_dir'],\":crescent_moon:\")\t\n\ndef main():\n\tsense = SenseHat()\n\tconditions = get_conditions()\n\tastronomy = get_astronomy()\n\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\tprint \"Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!\"\n\t\tif 'error' in conditions['response']:\n\t\t\tprint \"Error Type: \" + conditions['response']['error']['type']\n\t\t\tprint \"Error Description: \" + conditions['response']['error']['description']\n\t\texit()\n\telse:\n\t\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\t\tstreamer.log(\":house: Location\",conditions['current_observation']['display_location']['full'])\n\twhile True:\n\t\t# -------------- Sense Hat --------------\n\t\t# Read the sensors\n\t\ttemp_c = sense.get_temperature()\n\t\thumidity = sense.get_humidity() \n\t\tpressure_mb = sense.get_pressure() \n    \t\tcpu_temp = subprocess.check_output(\"vcgencmd measure_temp\", shell=True)\n    \t\tarray = cpu_temp.split(\"=\")\n    \t\tarray2 = array[1].split(\"'\")\n\n    \t\tcpu_tempc = float(array2[0])\n    \t\tcpu_tempc = float(\"{0:.2f}\".format(cpu_tempc))\n    \t\tcpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0\n    \t\tcpu_tempf = float(\"{0:.2f}\".format(cpu_tempf))\n\n    \t\ttemp_calibrated_c = temp_c - ((cpu_tempc - temp_c)/5.466)\n    \n\t\t# Format the data\n\t\ttemp_f = temp_calibrated_c * 9.0 / 5.0 + 32.0\n\t\ttemp_f = float(\"{0:.2f}\".format(temp_f))\n\t\ttemp_calibrated_c = float(\"{0:.2f}\".format(temp_calibrated_c))\n\t\thumidity = float(\"{0:.2f}\".format(humidity))\n\t\tpressure_in = 0.0295301*(pressure_mb)\n\t\tpressure_in = float(\"{0:.2f}\".format(pressure_in))\n\t\tpressure_mb = float(\"{0:.2f}\".format(pressure_mb))\n\n\t\t# Print and stream \n\t\tif (METRIC_UNITS):\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(C): \" + str(temp_calibrated_c)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(mb): \" + str(pressure_mb)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(C)\", temp_calibrated_c)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (mb)\", pressure_mb)\n\t\t\tprint(cpu_tempc)\n\t\t\tstreamer.log(\"CPU Temperature\",cpu_tempc)\n\t\telse:\n\t\t\tprint SENSOR_LOCATION_NAME + \" Temperature(F): \" + str(temp_f)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Pressure(IN): \" + str(pressure_in)\n\t\t\tstreamer.log(\":sunny: \" + SENSOR_LOCATION_NAME + \" Temperature(F)\", temp_f)\n\t\t\tstreamer.log(\":cloud: \" + SENSOR_LOCATION_NAME + \" Pressure (IN)\", pressure_in)\n\t\t\tprint(cpu_tempf)\n\t\t\tstreamer.log(\"CPU Temperature\",cpu_tempf)\n\t\t\tprint SENSOR_LOCATION_NAME + \" Humidity(%): \" + str(humidity)\n\t\t\tstreamer.log(\":sweat_drops: \" + SENSOR_LOCATION_NAME + \" Humidity(%)\", humidity)\n\n\t\t# -------------- Wunderground --------------\n\t\tconditions = get_conditions()\n\t\tastronomy = get_astronomy()\n\t\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\t\tprint \"Error! Wunderground API call failed. Skipping a reading then continuing ...\"\n\t\telse:\n\t\t\thumidity_pct = conditions['current_observation']['relative_humidity']\n\t\t\thumidity = humidity_pct.replace(\"%\",\"\")\n\n\t\t\t# Stream valid conditions to Initial State\n\t\t\tstreamer.log(\":cloud: \" + CITY + \" Weather Conditions\",weather_status_icon(conditions, astronomy))\n\t\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(astronomy['moon_phase']['phaseofMoon']))\n\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Direction\",wind_dir_icon(conditions, astronomy))\n\t\t\tif (METRIC_UNITS):\n\t\t\t\tif isFloat(conditions['current_observation']['temp_c']): \n\t\t\t\t\tstreamer.log(CITY + \" Temperature(C)\",conditions['current_observation']['temp_c'])\n\t\t\t\tif isFloat(conditions['current_observation']['dewpoint_c']):\n\t\t\t\t\tstreamer.log(CITY + \" Dewpoint(C)\",conditions['current_observation']['dewpoint_c'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_kph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(KPH)\",conditions['current_observation']['wind_kph'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_gust_kph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(KPH)\",conditions['current_observation']['wind_gust_kph'])\n\t\t\t\tif isFloat(conditions['current_observation']['pressure_mb']):\n\t\t\t\t\tstreamer.log(CITY + \" Pressure(mb)\",conditions['current_observation']['pressure_mb'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_1hr_metric']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(mm)\",conditions['current_observation']['precip_1hr_metric'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_today_metric']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(mm)\",conditions['current_observation']['precip_today_metric'])\n\t\t\telse:\n\t\t\t\tif isFloat(conditions['current_observation']['temp_f']): \n\t\t\t\t\tstreamer.log(CITY + \" Temperature(F)\",conditions['current_observation']['temp_f'])\n\t\t\t\tif isFloat(conditions['current_observation']['dewpoint_f']):\n\t\t\t\t\tstreamer.log(CITY + \" Dewpoint(F)\",conditions['current_observation']['dewpoint_f'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_mph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(MPH)\",conditions['current_observation']['wind_mph'])\n\t\t\t\tif isFloat(conditions['current_observation']['wind_gust_mph']):\n\t\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(MPH)\",conditions['current_observation']['wind_gust_mph'])\n\t\t\t\tif isFloat(conditions['current_observation']['pressure_in']):\n\t\t\t\t\tstreamer.log(CITY + \" Pressure(IN)\",conditions['current_observation']['pressure_in'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_1hr_in']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(IN)\",conditions['current_observation']['precip_1hr_in'])\n\t\t\t\tif isFloat(conditions['current_observation']['precip_today_in']):\n\t\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(IN)\",conditions['current_observation']['precip_today_in'])\n\t\t\tif isFloat(conditions['current_observation']['solarradiation']):\n\t\t\t\tstreamer.log(\":sunny: \" + CITY + \" Solar Radiation (watt/m^2)\",conditions['current_observation']['solarradiation'])\n\t\t\tif isFloat(humidity):\n\t\t\t\tstreamer.log(\":droplet: \" + CITY + \" Humidity(%)\",humidity)\n\t\t\tif isFloat(conditions['current_observation']['UV']):\n\t\t\t\tstreamer.log(\":sunny: \" + CITY + \" UV Index:\",conditions['current_observation']['UV'])\n\t\t\tstreamer.flush()\n\t\ttime.sleep(60*MINUTES_BETWEEN_READS)\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "wunderground.py",
    "content": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nfrom ISStreamer.Streamer import Streamer\n\n# --------- User Settings ---------\nSTATE = \"CA\"\nCITY = \"San_Francisco\"\nWUNDERGROUND_API_KEY = \"PLACE YOUR WUNDERGROUND API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"wu1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nMINUTES_BETWEEN_READS = 15\nMETRIC_UNITS = False\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        return True\n    except ValueError:\n        return False\n\ndef get_conditions():\n\tapi_conditions_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/conditions/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t\tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\treturn []\n\tjson_conditions = f.read()\n\tf.close()\n\treturn json.loads(json_conditions)\n\ndef get_astronomy():\n\tapi_astronomy_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/astronomy/q/\" + STATE + \"/\" + CITY + \".json\"\n\ttry:\n\t\tf = urllib2.urlopen(api_astronomy_url)\n\texcept:\n\t\treturn []\n\tjson_astronomy = f.read()\n\tf.close()\n\treturn json.loads(json_astronomy)\n\ndef is_night(astronomy):\n\tsunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])\n\tsunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])\n\tsunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])\n\tsunset_min   = int(astronomy['moon_phase']['sunset']['minute'])\n\tcurrent_hour = int(astronomy['moon_phase']['current_time']['hour'])\n\tcurrent_min  = int(astronomy['moon_phase']['current_time']['minute'])\n\tif ( (current_hour < sunrise_hour) or\n\t     (current_hour > sunset_hour) or\n\t     ((current_hour == sunrise_hour) and\n\t      (current_min < sunrise_min)) or \n\t     ((current_hour == sunset_hour) and\n\t      (current_min > sunset_min)) ):\n\t\treturn True\n\treturn False\n\ndef moon_icon(moon_phase):\n\ticon = {\n\t\t\"New Moon\"        : \":new_moon:\",\n\t\t\"Waxing Crescent\" : \":waxing_crescent_moon:\",\n\t\t\"First Quarter\"   : \":first_quarter_moon:\",\n\t\t\"Waxing Gibbous\"  : \":waxing_gibbous_moon:\",\n\t\t\"Full Moon\"       : \":full_moon:\",\n\t\t\"Full\"            : \":full_moon:\",\n\t\t\"Waning Gibbous\"  : \":waning_gibbous_moon:\",\n\t\t\"Last Quarter\"    : \":last_quarter_moon:\",\n\t\t\"Waning Crescent\" : \":waning_crescent_moon:\",\n\t}\n\treturn icon.get(moon_phase,\":crescent_moon:\")\n\ndef weather_icon(weather_conditions):\n\ticon = {\n\t\t\"clear\"            : \":sun_with_face:\",\n\t\t\"cloudy\"           : \":cloud:\",\n\t\t\"flurries\"         : \":snowflake:\",\n\t\t\"fog\"              : \":foggy:\",\n\t\t\"hazy\"             : \":foggy:\",\n\t\t\"mostlycloudy\"     : \":cloud:\",\n\t\t\"mostlysunny\"      : \":sun_with_face:\",\n\t\t\"partlycloudy\"     : \":partly_sunny:\",\n\t\t\"partlysunny\"      : \":partly_sunny:\",\n\t\t\"sleet\"            : \":sweat_drops: :snowflake:\",\n\t\t\"rain\"             : \":umbrella:\",\n\t\t\"snow\"             : \":snowflake:\",\n\t\t\"sunny\"            : \":sun_with_face:\",\n\t\t\"tstorms\"          : \":zap: :umbrella:\",\n\t\t\"unknown\"          : \":sun_with_face:\",\n\t}\n\treturn icon.get(weather_conditions,\":sun_with_face:\")\n\ndef weather_status_icon (conditions, astronomy):\n\tmoon_phase = astronomy['moon_phase']['phaseofMoon']\n\tweather_conditions = conditions['current_observation']['icon']\n\ticon = weather_icon(weather_conditions)\n\tif is_night(astronomy):\n\t\tif ((icon == \":sunny:\") or\n\t\t    (icon == \":partly_sunny:\") or\n\t\t    (icon == \":sun_with_face:\")):\n\t\t\treturn moon_icon(moon_phase)\n\treturn icon\n\ndef wind_dir_icon (conditions, astronomy):\n\ticon = {\n\t\t\"East\"     : \":arrow_right:\",\n\t\t\"ENE\"      : \":arrow_upper_right:\",\n\t\t\"ESE\"      : \":arrow_lower_right:\",\n\t\t\"NE\"       : \":arrow_upper_right:\",\n\t\t\"NNE\"      : \":arrow_upper_right:\",\n\t\t\"NNW\"      : \":arrow_upper_left:\",\n\t\t\"North\"    : \":arrow_up:\",\n\t\t\"NW\"       : \":arrow_upper_left:\",\n\t\t\"SE\"       : \":arrow_lower_right:\",\n\t\t\"South\"    : \":arrow_down:\",\n\t\t\"SSE\"      : \":arrow_lower_right:\",\n\t\t\"SSW\"      : \":arrow_lower_left:\",\n\t\t\"SW\"       : \":arrow_lower_left:\",\n\t\t\"Variable\" : \":arrows_counterclockwise:\",\n\t\t\"West\"     : \":arrow_left:\",\n\t\t\"WNW\"      : \":arrow_upper_left:\",\n\t\t\"WSW\"      : \":arrow_lower_left:\",\n\t}\n\treturn icon.get(conditions['current_observation']['wind_dir'],\":crescent_moon:\")\t\n\nconditions = get_conditions()\nastronomy = get_astronomy()\nif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\tprint \"Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!\"\n\tif 'error' in conditions['response']:\n\t\tprint \"Error Type: \" + conditions['response']['error']['type']\n\t\tprint \"Error Description: \" + conditions['response']['error']['description']\n\texit()\nelse:\n\tstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\tstreamer.log(\":house: Location\",conditions['current_observation']['display_location']['full'])\nwhile True:\n\tconditions = get_conditions()\n\tastronomy = get_astronomy()\n\tif ('current_observation' not in conditions) or ('moon_phase' not in astronomy):\n\t\tprint \"Error! Wunderground API call failed. Skipping a reading then continuing ...\"\n\telse:\n\t\thumidity_pct = conditions['current_observation']['relative_humidity']\n\t\thumidity = humidity_pct.replace(\"%\",\"\")\n\n\t\t# Stream valid conditions to Initial State\n\t\tstreamer.log(\":clock3: Updated Time\",astronomy['moon_phase']['current_time']['hour'] + \":\" + astronomy['moon_phase']['current_time']['minute'])\n\t\tstreamer.log(\":cloud: \" + CITY + \" Weather Conditions\",weather_status_icon(conditions, astronomy))\n\t\tstreamer.log(\":crescent_moon: Moon Phase\",moon_icon(astronomy['moon_phase']['phaseofMoon']))\n\t\tstreamer.log(\":dash: \" + CITY + \" Wind Direction\",wind_dir_icon(conditions, astronomy))\n\t\tif (METRIC_UNITS):\n\t\t\tif isFloat(conditions['current_observation']['temp_c']): \n\t\t\t\tstreamer.log(CITY + \" Temperature(C)\",conditions['current_observation']['temp_c'])\n\t\t\tif isFloat(conditions['current_observation']['dewpoint_c']):\n\t\t\t\tstreamer.log(CITY + \" Dewpoint(C)\",conditions['current_observation']['dewpoint_c'])\n\t\t\tif isFloat(conditions['current_observation']['wind_kph']):\n\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(KPH)\",conditions['current_observation']['wind_kph'])\n\t\t\tif isFloat(conditions['current_observation']['wind_gust_kph']):\n\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(KPH)\",conditions['current_observation']['wind_gust_kph'])\n\t\t\tif isFloat(conditions['current_observation']['pressure_mb']):\n\t\t\t\tstreamer.log(CITY + \" Pressure(mb)\",conditions['current_observation']['pressure_mb'])\n\t\t\tif isFloat(conditions['current_observation']['precip_1hr_metric']):\n\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(mm)\",conditions['current_observation']['precip_1hr_metric'])\n\t\t\tif isFloat(conditions['current_observation']['precip_today_metric']):\n\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(mm)\",conditions['current_observation']['precip_today_metric'])\n\t\telse:\n\t\t\tif isFloat(conditions['current_observation']['temp_f']): \n\t\t\t\tstreamer.log(CITY + \" Temperature(F)\",conditions['current_observation']['temp_f'])\n\t\t\tif isFloat(conditions['current_observation']['dewpoint_f']):\n\t\t\t\tstreamer.log(CITY + \" Dewpoint(F)\",conditions['current_observation']['dewpoint_f'])\n\t\t\tif isFloat(conditions['current_observation']['wind_mph']):\n\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Speed(MPH)\",conditions['current_observation']['wind_mph'])\n\t\t\tif isFloat(conditions['current_observation']['wind_gust_mph']):\n\t\t\t\tstreamer.log(\":dash: \" + CITY + \" Wind Gust(MPH)\",conditions['current_observation']['wind_gust_mph'])\n\t\t\tif isFloat(conditions['current_observation']['pressure_in']):\n\t\t\t\tstreamer.log(CITY + \" Pressure(IN)\",conditions['current_observation']['pressure_in'])\n\t\t\tif isFloat(conditions['current_observation']['precip_1hr_in']):\n\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip 1 Hour(IN)\",conditions['current_observation']['precip_1hr_in'])\n\t\t\tif isFloat(conditions['current_observation']['precip_today_in']):\n\t\t\t\tstreamer.log(\":umbrella: \" + CITY + \" Precip Today(IN)\",conditions['current_observation']['precip_today_in'])\n\t\tif isFloat(conditions['current_observation']['solarradiation']):\n\t\t\tstreamer.log(\":sunny: \" + CITY + \" Solar Radiation (watt/m^2)\",conditions['current_observation']['solarradiation'])\n\t\tif isFloat(humidity):\n\t\t\tstreamer.log(\":droplet: \" + CITY + \" Humidity(%)\",humidity)\n\t\tif isFloat(conditions['current_observation']['UV']):\n\t\t\tstreamer.log(\":sunny: \" + CITY + \" UV Index:\",conditions['current_observation']['UV'])\n\t\tstreamer.flush()\n\ttime.sleep(60*MINUTES_BETWEEN_READS)\n"
  },
  {
    "path": "wunderground_historical.py",
    "content": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nfrom datetime import timedelta, date\nfrom ISStreamer.Streamer import Streamer\n\n# --------- User Settings ---------\nSTATE = \"CA\"\nCITY = \"San_Francisco\"\nWUNDERGROUND_API_KEY = \"PLACE YOUR WUNDERGROUND API KEY HERE\"\nBUCKET_NAME = \":partly_sunny: \" + CITY + \" Weather\"\nBUCKET_KEY = \"wu1\"\nACCESS_KEY = \"PLACE YOUR INITIAL STATE ACCESS KEY HERE\"\nSTARTDATE = date(YYYY,MM,DD)\nENDDATE = date(YYYY,MM,DD)\nSECONDS_BETWEEN_SEND = 5\n# ---------------------------------\n\ndef isFloat(string):\n    try:\n        float(string)\n        if float(string) < 0:\n        \traise ValueError\n        return True\n    except ValueError:\n        return False\n\ndef daterange(start_date, end_date):\n    for n in range(int((end_date - start_date).days)):\n        yield start_date + timedelta(n)\n\ndef get_conditions(readDate):\n\tapi_conditions_url = \"http://api.wunderground.com/api/\" + WUNDERGROUND_API_KEY + \"/history_\" + readDate + \"/q/\" + STATE +\"/\"+ CITY + \".json\"\n\ttry:\n\t  \tf = urllib2.urlopen(api_conditions_url)\n\texcept:\n\t\tprint \"Failed to get conditions\"\n\t\treturn False\n\tjson_conditions = f.read()\n\tf.close()\n\treturn json.loads(json_conditions)\t\n\nstreamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)\n\n\nwhile True:\n\tfor single_date in daterange(STARTDATE,ENDDATE):\n\t\tconditions = get_conditions(single_date.strftime(\"%Y%m%d\"))\n\n\t\tif (conditions != False):\n\t\t\tfor i in range(len(conditions['history']['observations'])):\n\t\t\t\tdateInfo = conditions['history']['observations'][i]['date']\n\t\t\t\tdate = dateInfo['mday']+\".\"+dateInfo['mon']+\".\"+dateInfo['year']+\" \"+dateInfo['hour']+\":\"+dateInfo['min']+\":00\"\n\t\t\t\tprint date\n\t\t\t\tpattern = '%d.%m.%Y %H:%M:%S'\n\t\t\t\tepoch = int(time.mktime(time.strptime(date, pattern)))\n\n\t\t\t\thumidity_wu = conditions['history']['observations'][i]['hum']\n\t\t\t\ttemp_wu = conditions['history']['observations'][i]['tempi']\n\t\t\t\tpressure_wu = conditions['history']['observations'][i]['pressurem']\n\t\t\t\tprecip_wu = conditions['history']['observations'][i]['precipi']\n\t\t\t\twind_speed_wu = conditions['history']['observations'][i]['wspdi']\n\t\t\t\t# dewpt_wu = conditions['history']['observations'][i]['dewpti']\n\t\t\t\t# wind_gust_wu = conditions['history']['observations'][i]['wgusti']\n\t\t\t\t# wind_dir_wu = conditions['history']['observations'][i]['wdird']\n\t\t\t\t# vis_wu = conditions['history']['observations'][i]['visi']\n\t\t\t\t# wind_chill_wu = conditions['history']['observations'][i]['windchilli']\n\t\t\t\t# heat_index_wu = conditions['history']['observations'][i]['heatindexi']\n\t\t\t\t# conds_wu = conditions['history']['observations'][i]['conds']\n\t\t\t\t# fog_wu = conditions['history']['observations'][i]['fog']\n\t\t\t\t# rain_wu = conditions['history']['observations'][i]['rain']\n\t\t\t\t# snow_wu = conditions['history']['observations'][i]['snow']\n\t\t\t\t# hail_wu = conditions['history']['observations'][i]['hail']\n\t\t\t\t# thunder_wu = conditions['history']['observations'][i]['thunder']\n\t\t\t\t# tornado_wu = conditions['history']['observations'][i]['tornado']\n\n\t\t\t\tif isFloat(humidity_wu):\n\t\t\t\t\tstreamer.log(\"WU Humidity (%)\",humidity_wu,epoch)\n\t\t\t\tif isFloat(temp_wu):\n\t\t\t\t\tstreamer.log(\"WU Temp\",temp_wu,epoch)\n\t\t\t\tif isFloat(pressure_wu):\n\t\t\t\t\tstreamer.log(\"WU Pressure\",pressure_wu,epoch)\n\t\t\t\tif isFloat(precip_wu):\n\t\t\t\t\tstreamer.log(\"WU Rain\",precip_wu,epoch)\n\t\t\t\tif isFloat(wind_speed_wu):\n\t\t\t\t\tstreamer.log(\"WU Wind Speed\",wind_speed_wu,epoch)\n\t\t\t\t# if isFloat(dewpt_wu):\n\t\t\t\t# \tstreamer.log(\"WU Dew Point\",dewpt_wu,epoch)\n\t\t\t\t# if isFloat(wind_gust_wu):\n\t\t\t\t# \tstreamer.log(\"WU Wind Gust\",wind_gust_wu,epoch)\n\t\t\t\t# if isFloat(wind_dir_wu):\n\t\t\t\t# \tstreamer.log(\"WU Wind Direction\",wind_dir_wu,epoch)\n\t\t\t\t# if isFloat(vis_wu):\n\t\t\t\t# \tstreamer.log(\"WU Visibility\",vis_wu,epoch)\n\t\t\t\t# if isFloat(wind_chill_wu):\n\t\t\t\t# \tstreamer.log(\"WU Wind Chill\",wind_chill_wu,epoch)\n\t\t\t\t# if isFloat(heat_index_wu):\n\t\t\t\t# \tstreamer.log(\"WU Heat Index\",heat_index_wu,epoch)\n\t\t\t\t# if isFloat(conds_wu):\n\t\t\t\t# \tstreamer.log(\"WU Conditions\",conds_wu,epoch)\n\t\t\t\t# if isFloat(fog_wu):\n\t\t\t\t# \tstreamer.log(\"WU Fog\",fog_wu,epoch)\n\t\t\t\t# if isFloat(rain_wu):\n\t\t\t\t# \tstreamer.log(\"WU Rain\",rain_wu,epoch)\n\t\t\t\t# if isFloat(snow_wu):\n\t\t\t\t# \tstreamer.log(\"WU Snow\",snow_wu,epoch)\n\t\t\t\t# if isFloat(hail_wu):\n\t\t\t\t# \tstreamer.log(\"WU Hail\",hail_wu,epoch)\n\t\t\t\t# if isFloat(thunder_wu):\n\t\t\t\t# \tstreamer.log(\"WU Thunder\",thunder_wu,epoch)\n\t\t\t\t# if isFloat(tornado_wu):\n\t\t\t\t# \tstreamer.log(\"WU Tornado\",tornado_wu,epoch)\n\n\t\t\t\tstreamer.flush()\n\t\t\t\ttime.sleep(SECONDS_BETWEEN_SEND)\n\n\t\t\tif single_date == ENDDATE:\n\t\t\t\tprint(\"All dates streamed\")\n\t\t\t\texit()\n"
  }
]