master 3ef4e0cc4cce cached
12 files
69.4 KB
19.2k tokens
59 symbols
1 requests
Download .txt
Repository: initialstate/wunderground-sensehat
Branch: master
Commit: 3ef4e0cc4cce
Files: 12
Total size: 69.4 KB

Directory structure:
gitextract_e0spm_96/

├── ActualTemp.py
├── CPUTemp.py
├── LICENSE
├── README.md
├── darksky.py
├── sensehat.py
├── sensehat_darksky.py
├── sensehat_darksky_calibrated.py
├── sensehat_wunderground.py
├── sensehat_wunderground_calibrated.py
├── wunderground.py
└── wunderground_historical.py

================================================
FILE CONTENTS
================================================

================================================
FILE: ActualTemp.py
================================================
#!/usr/bin/python

# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola

import Adafruit_DHT
from ISStreamer.Streamer import Streamer
from time import sleep

# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = Adafruit_DHT.DHT22

# Example using a Raspberry Pi with DHT sensor
# connected to GPIO 3.
pin = 3

streamer = Streamer(bucket_key="shwu1", access_key="PLACE YOUR INITIAL STATE ACCESS KEY HERE")

while True:
	# Try to grab a sensor reading.  Use the read_retry method which will retry up
	# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
	humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

	# Note that sometimes you won't get a reading and
	# the results will be null (because Linux can't
	# guarantee the timing of calls to read the sensor).
	# If this happens try again!
	if humidity is not None and temperature is not None:
	    
	    temperatureF = 9.0/5.0*temperature+32
	    streamer.log("Actual Temperature",temperatureF)
	    print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature, humidity))
	    sleep(900)
	else:
	    print('Failed to get reading. Try again!')


================================================
FILE: CPUTemp.py
================================================
import os
import urllib2
import json
import glob
import time
import RPi.GPIO as io
from ISStreamer.Streamer import Streamer
from sense_hat import SenseHat 
import subprocess

# --------- User Settings ---------
STATE = "CA"
CITY = "San_Francisco"
SENSOR_LOCATION_NAME = "Office"
WUNDERGROUND_API_KEY = "PLACE YOUR WUNDERGROUND API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "shwu1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_conditions():
	api_conditions_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/conditions/q/" + STATE + "/" + CITY + ".json"
	try:
	  	f = urllib2.urlopen(api_conditions_url)
	except:
		print "Failed to get conditions"
		return []
	json_conditions = f.read()
	f.close()
	return json.loads(json_conditions)

def get_astronomy():
	api_astronomy_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/astronomy/q/" + STATE + "/" + CITY + ".json"
	try:
		f = urllib2.urlopen(api_astronomy_url)
	except:
		print "Failed to get astronomy"
		return []		
	json_astronomy = f.read()
	f.close()
	return json.loads(json_astronomy)

def is_night(astronomy):
	sunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])
	sunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])
	sunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])
	sunset_min   = int(astronomy['moon_phase']['sunset']['minute'])
	current_hour = int(astronomy['moon_phase']['current_time']['hour'])
	current_min  = int(astronomy['moon_phase']['current_time']['minute'])
	if ( (current_hour < sunrise_hour) or
	     (current_hour > sunset_hour) or
	     ((current_hour == sunrise_hour) and
	      (current_min < sunrise_min)) or 
	     ((current_hour == sunset_hour) and
	      (current_min > sunset_min)) ):
		return True
	return False

def moon_icon(moon_phase):
	icon = {
		"New Moon"        : ":new_moon:",
		"Waxing Crescent" : ":waxing_crescent_moon:",
		"First Quarter"   : ":first_quarter_moon:",
		"Waxing Gibbous"  : ":waxing_gibbous_moon:",
		"Full Moon"       : ":full_moon:",
		"Full"            : ":full_moon:",
		"Waning Gibbous"  : ":waning_gibbous_moon:",
		"Last Quarter"    : ":last_quarter_moon:",
		"Waning Crescent" : ":waning_crescent_moon:",
	}
	return icon.get(moon_phase,":crescent_moon:")

def weather_icon(weather_conditions):
	icon = {
		"clear"            : ":sun_with_face:",
		"cloudy"           : ":cloud:",
		"flurries"         : ":snowflake:",
		"fog"              : ":foggy:",
		"hazy"             : ":foggy:",
		"mostlycloudy"     : ":cloud:",
		"mostlysunny"      : ":sun_with_face:",
		"partlycloudy"     : ":partly_sunny:",
		"partlysunny"      : ":partly_sunny:",
		"sleet"            : ":sweat_drops: :snowflake:",
		"rain"             : ":umbrella:",
		"snow"             : ":snowflake:",
		"sunny"            : ":sun_with_face:",
		"tstorms"          : ":zap: :umbrella:",
		"unknown"          : ":sun_with_face:",
	}
	return icon.get(weather_conditions,":sun_with_face:")

def weather_status_icon(conditions, astronomy):
	moon_phase = astronomy['moon_phase']['phaseofMoon']
	weather_conditions = conditions['current_observation']['icon']
	icon = weather_icon(weather_conditions)
	if is_night(astronomy):
		if ((icon == ":sunny:") or
		    (icon == ":partly_sunny:") or
		    (icon == ":sun_with_face:")):
			return moon_icon(moon_phase)
	return icon

def wind_dir_icon(conditions, astronomy):
	icon = {
		"East"     : ":arrow_right:",
		"ENE"      : ":arrow_upper_right:",
		"ESE"      : ":arrow_lower_right:",
		"NE"       : ":arrow_upper_right:",
		"NNE"      : ":arrow_upper_right:",
		"NNW"      : ":arrow_upper_left:",
		"North"    : ":arrow_up:",
		"NW"       : ":arrow_upper_left:",
		"SE"       : ":arrow_lower_right:",
		"South"    : ":arrow_down:",
		"SSE"      : ":arrow_lower_right:",
		"SSW"      : ":arrow_lower_left:",
		"SW"       : ":arrow_lower_left:",
		"Variable" : ":arrows_counterclockwise:",
		"West"     : ":arrow_left:",
		"WNW"      : ":arrow_upper_left:",
		"WSW"      : ":arrow_lower_left:",
	}
	return icon.get(conditions['current_observation']['wind_dir'],":crescent_moon:")	

def main():
	sense = SenseHat()
	conditions = get_conditions()
	astronomy = get_astronomy()
	if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
		print "Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!"
		if 'error' in conditions['response']:
			print "Error Type: " + conditions['response']['error']['type']
			print "Error Description: " + conditions['response']['error']['description']
		exit()
	else:
		streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
		streamer.log(":house: Location",conditions['current_observation']['display_location']['full'])
	while True:
		# -------------- Sense Hat --------------
		# Read the sensors
		temp_c = sense.get_temperature()
		humidity = sense.get_humidity() 
		pressure_mb = sense.get_pressure() 
    		cpu_temp = subprocess.check_output("vcgencmd measure_temp", shell=True)
    		array = cpu_temp.split("=")
    		array2 = array[1].split("'")

    		cpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0
    		cpu_tempf = float("{0:.2f}".format(cpu_tempf))
    		streamer.log("CPU Temperature",cpu_tempf)
    		print(cpu_tempf)
    
		# Format the data
		temp_f = temp_c * 9.0 / 5.0 + 32.0
		temp_f = float("{0:.2f}".format(temp_f))
		temp_c = float("{0:.2f}".format(temp_c))
		humidity = float("{0:.2f}".format(humidity))
		pressure_in = 0.0295301*(pressure_mb)
		pressure_in = float("{0:.2f}".format(pressure_in))
		pressure_mb = float("{0:.2f}".format(pressure_mb))

		# Print and stream 
		if (METRIC_UNITS):
			print SENSOR_LOCATION_NAME + " Temperature(C): " + str(temp_c)
			print SENSOR_LOCATION_NAME + " Pressure(mb): " + str(pressure_mb)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_c)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (mb)", pressure_mb)
		else:
			print SENSOR_LOCATION_NAME + " Temperature(F): " + str(temp_f)
			print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_in)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (IN)", pressure_in)
		print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
		streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", humidity)

		# -------------- Wunderground --------------
		conditions = get_conditions()
		astronomy = get_astronomy()
		if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
			print "Error! Wunderground API call failed. Skipping a reading then continuing ..."
		else:
			humidity_pct = conditions['current_observation']['relative_humidity']
			humidity = humidity_pct.replace("%","")

			# Stream valid conditions to Initial State
			streamer.log(":cloud: " + CITY + " Weather Conditions",weather_status_icon(conditions, astronomy))
			streamer.log(":crescent_moon: Moon Phase",moon_icon(astronomy['moon_phase']['phaseofMoon']))
			streamer.log(":dash: " + CITY + " Wind Direction",wind_dir_icon(conditions, astronomy))
			if (METRIC_UNITS):
				if isFloat(conditions['current_observation']['temp_c']): 
					streamer.log(CITY + " Temperature(C)",conditions['current_observation']['temp_c'])
				if isFloat(conditions['current_observation']['dewpoint_c']):
					streamer.log(CITY + " Dewpoint(C)",conditions['current_observation']['dewpoint_c'])
				if isFloat(conditions['current_observation']['wind_kph']):
					streamer.log(":dash: " + CITY + " Wind Speed(KPH)",conditions['current_observation']['wind_kph'])
				if isFloat(conditions['current_observation']['wind_gust_kph']):
					streamer.log(":dash: " + CITY + " Wind Gust(KPH)",conditions['current_observation']['wind_gust_kph'])
				if isFloat(conditions['current_observation']['pressure_mb']):
					streamer.log(CITY + " Pressure(mb)",conditions['current_observation']['pressure_mb'])
				if isFloat(conditions['current_observation']['precip_1hr_metric']):
					streamer.log(":umbrella: " + CITY + " Precip 1 Hour(mm)",conditions['current_observation']['precip_1hr_metric'])
				if isFloat(conditions['current_observation']['precip_today_metric']):
					streamer.log(":umbrella: " + CITY + " Precip Today(mm)",conditions['current_observation']['precip_today_metric'])
			else:
				if isFloat(conditions['current_observation']['temp_f']): 
					streamer.log(CITY + " Temperature(F)",conditions['current_observation']['temp_f'])
				if isFloat(conditions['current_observation']['dewpoint_f']):
					streamer.log(CITY + " Dewpoint(F)",conditions['current_observation']['dewpoint_f'])
				if isFloat(conditions['current_observation']['wind_mph']):
					streamer.log(":dash: " + CITY + " Wind Speed(MPH)",conditions['current_observation']['wind_mph'])
				if isFloat(conditions['current_observation']['wind_gust_mph']):
					streamer.log(":dash: " + CITY + " Wind Gust(MPH)",conditions['current_observation']['wind_gust_mph'])
				if isFloat(conditions['current_observation']['pressure_in']):
					streamer.log(CITY + " Pressure(IN)",conditions['current_observation']['pressure_in'])
				if isFloat(conditions['current_observation']['precip_1hr_in']):
					streamer.log(":umbrella: " + CITY + " Precip 1 Hour(IN)",conditions['current_observation']['precip_1hr_in'])
				if isFloat(conditions['current_observation']['precip_today_in']):
					streamer.log(":umbrella: " + CITY + " Precip Today(IN)",conditions['current_observation']['precip_today_in'])
			if isFloat(conditions['current_observation']['solarradiation']):
				streamer.log(":sunny: " + CITY + " Solar Radiation (watt/m^2)",conditions['current_observation']['solarradiation'])
			if isFloat(humidity):
				streamer.log(":droplet: " + CITY + " Humidity(%)",humidity)
			if isFloat(conditions['current_observation']['UV']):
				streamer.log(":sunny: " + CITY + " UV Index:",conditions['current_observation']['UV'])
			streamer.flush()
		time.sleep(60*MINUTES_BETWEEN_READS)

if __name__ == "__main__":
    main()



================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2019 Initial State

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# Weather API (Dark Sky) + Pi Sense HAT
![Dark Sky Dashboard](https://github.com/InitialState/darksky/wiki/img/darksky_dashboard.jpg)
This is a hub for the Hyper-local Weather Dashboard: Weather API (Dark Sky) + Pi Sense HAT.

Here you will find code materials for the tutorial as well as the tutorial itself in the [wiki](https://github.com/InitialState/wunderground-sensehat/wiki).

Let'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)


================================================
FILE: darksky.py
================================================
import urllib2
import json
import os
import glob
import time
from ISStreamer.Streamer import Streamer

# --------- User Settings ---------
CITY = "Franklin"
GPS_COORDS = "35.9260096,-86.868537"
DARKSKY_API_KEY = "PLACE YOUR DARK SKY API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "ds1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_current_conditions():
	api_conditions_url = "https://api.darksky.net/forecast/" + DARKSKY_API_KEY + "/" + GPS_COORDS + "?units=auto"
	try:
		f = urllib2.urlopen(api_conditions_url)
	except:
		return []
	json_currently = f.read()
	f.close()
	return json.loads(json_currently)

def moon_icon(moon_phase):
	if moon_phase == 0:
		return ":new_moon:"
	if moon_phase < .125:
		return ":waxing_crescent_moon:"
	if moon_phase < .25:
		return ":first_quarter_moon:"
	if moon_phase < .48:
		return ":waxing_gibbous_moon:"
	if moon_phase < .52:
		return ":full_moon:"
	if moon_phase < .625:
		return ":waning_gibbous_moon:"
	if moon_phase < .75:
		return ":last_quarter_moon:"
	if moon_phase < 1:
		return ":waning_crescent_moon:"
	return ":crescent_moon:"

def weather_icon(ds_icon):
	icon = {
		"clear-day"            	: ":sunny:",
		"clear-night"           : ":new_moon_with_face:",
		"rain"                  : ":umbrella:",
		"snow"                  : ":snowflake:",
		"sleet"                 : ":sweat_drops: :snowflake:",
		"wind"                  : ":wind_blowing_face:",
		"fog"                   : ":fog:",
		"cloudy"                : ":cloud:",
		"partly-cloudy-day"     : ":partly_sunny:",
		"partly-cloudy-night"   : ":new_moon_with_face:",
		"unknown"               : ":sun_with_face:",
	}
	return icon.get(ds_icon,":sun_with_face:")

def weather_status_icon(ds_icon,moon_phase):
	icon = weather_icon(ds_icon)
	if (icon == ":new_moon_with_face:"):
		return moon_icon(moon_phase)
	return icon

def wind_dir_icon(wind_bearing):
	if (wind_bearing < 20):
		return ":arrow_up:"
	if (wind_bearing < 70):
		return ":arrow_upper_right:"
	if (wind_bearing < 110):
		return ":arrow_right:"
	if (wind_bearing < 160):
		return ":arrow_lower_right:"
	if (wind_bearing < 200):
		return ":arrow_down:"
	if (wind_bearing < 250):
		return ":arrow_lower_left:"
	if (wind_bearing < 290):
		return ":arrow_left:"
	if (wind_bearing < 340):
		return ":arrow_upper_left:"
	return ":arrow_up:"

def main():
	curr_conditions = get_current_conditions()
	if ('currently' not in curr_conditions):
		print "Error! Dark Sky API call failed, check your GPS coordinates and make sure your Dark Sky API key is valid!\n"
		print curr_conditions
		exit()
	else:
		streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
	while True:
		
		curr_conditions = get_current_conditions()
		if ('currently' not in curr_conditions):
			print "Error! Dark Sky API call failed. Skipping a reading then continuing ...\n"
			print curr_conditions
		else:
			streamer.log(":house: Location",GPS_COORDS)
			
			if 'humidity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['humidity']):
				streamer.log(":droplet: Humidity(%)", curr_conditions['currently']['humidity']*100)

			if 'temperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['temperature']): 
				streamer.log("Temperature",curr_conditions['currently']['temperature'])

			if 'apparentTemperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['apparentTemperature']): 
				streamer.log("Feels Like",curr_conditions['currently']['apparentTemperature'])

			if 'dewPoint' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['dewPoint']):
				streamer.log("Dewpoint",curr_conditions['currently']['dewPoint'])

			if 'windSpeed' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windSpeed']):
				streamer.log(":dash: Wind Speed",curr_conditions['currently']['windSpeed'])

			if 'windGust' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windGust']):
				streamer.log(":dash: Wind Gust",curr_conditions['currently']['windGust'])

			if 'windBearing' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windBearing']):
				streamer.log(":dash: Wind Direction",wind_dir_icon(curr_conditions['currently']['windBearing']))

			if 'pressure' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['pressure']):
				streamer.log("Pressure",curr_conditions['currently']['pressure'])

			if 'precipIntensity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipIntensity']):
				streamer.log(":umbrella: Precipitation Intensity",curr_conditions['currently']['precipIntensity'])

			if 'precipProbability' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipProbability']):
				streamer.log(":umbrella: Precipitation Probabiity(%)",curr_conditions['currently']['precipProbability']*100)

			if 'cloudCover' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['cloudCover']):
				streamer.log(":cloud: Cloud Cover(%)",curr_conditions['currently']['cloudCover']*100)

			if 'uvIndex' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['uvIndex']):
				streamer.log(":sunny: UV Index:",curr_conditions['currently']['uvIndex'])

			if 'summary' in curr_conditions['currently']:
				streamer.log(":cloud: Weather Summary",curr_conditions['currently']['summary'])

			if 'hourly' in curr_conditions:
				streamer.log("Today's Forecast",curr_conditions['hourly']['summary'])

			if 'daily' in curr_conditions:
				if 'data' in curr_conditions['daily']:
					if 'moonPhase' in curr_conditions['daily']['data'][0]:
						moon_phase = curr_conditions['daily']['data'][0]['moonPhase']
						streamer.log(":crescent_moon: Moon Phase",moon_icon(moon_phase))
						streamer.log(":cloud: Weather Conditions",weather_status_icon(curr_conditions['currently']['icon'],moon_phase))

			streamer.flush()
		time.sleep(60*MINUTES_BETWEEN_READS)

if __name__ == "__main__":
    main()
    


================================================
FILE: sensehat.py
================================================
from sense_hat import SenseHat  
import time  
import sys  
from ISStreamer.Streamer import Streamer  
  
# --------- User Settings ---------
CITY = "Nashville"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "sensehat"
ACCESS_KEY = "Your_Access_Key"
SENSOR_LOCATION_NAME = "Office"
MINUTES_BETWEEN_SENSEHAT_READS = 0.1
# ---------------------------------

streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
  
sense = SenseHat()  
  
while True:
  # Read the sensors
  temp_c = sense.get_temperature()
  humidity = sense.get_humidity() 
  pressure_mb = sense.get_pressure() 

  # Format the data
  temp_f = temp_c * 9.0 / 5.0 + 32.0
  temp_f = float("{0:.2f}".format(temp_f))
  humidity = float("{0:.2f}".format(humidity))
  pressure_in = 0.03937008*(pressure_mb)
  pressure_in = float("{0:.2f}".format(pressure_in))

  # Print and stream 
  print SENSOR_LOCATION_NAME + " Temperature(F): " + str(temp_f)
  print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
  print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_in)
  streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
  streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", humidity)
  streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure(IN)", pressure_in)

  streamer.flush()
  time.sleep(60*MINUTES_BETWEEN_SENSEHAT_READS)

================================================
FILE: sensehat_darksky.py
================================================
import urllib2
import json
import os
import glob
import time
import RPi.GPIO as io
from ISStreamer.Streamer import Streamer
from sense_hat import SenseHat 

# --------- User Settings ---------
CITY = "Franklin"
GPS_COORDS = "35.9260096,-86.868537"
SENSOR_LOCATION_NAME = "Office"
DARKSKY_API_KEY = "PLACE YOUR DARK SKY API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "shds1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_current_conditions():
	api_conditions_url = "https://api.darksky.net/forecast/" + DARKSKY_API_KEY + "/" + GPS_COORDS + "?units=auto"
	try:
		f = urllib2.urlopen(api_conditions_url)
	except:
		return []
	json_currently = f.read()
	f.close()
	return json.loads(json_currently)

def moon_icon(moon_phase):
	if moon_phase == 0:
		return ":new_moon:"
	if moon_phase < .125:
		return ":waxing_crescent_moon:"
	if moon_phase < .25:
		return ":first_quarter_moon:"
	if moon_phase < .48:
		return ":waxing_gibbous_moon:"
	if moon_phase < .52:
		return ":full_moon:"
	if moon_phase < .625:
		return ":waning_gibbous_moon:"
	if moon_phase < .75:
		return ":last_quarter_moon:"
	if moon_phase < 1:
		return ":waning_crescent_moon:"
	return ":crescent_moon:"

def weather_icon(ds_icon):
	icon = {
		"clear-day"            	: ":sunny:",
		"clear-night"           : ":new_moon_with_face:",
		"rain"                  : ":umbrella:",
		"snow"                  : ":snowflake:",
		"sleet"                 : ":sweat_drops: :snowflake:",
		"wind"                  : ":wind_blowing_face:",
		"fog"                   : ":fog:",
		"cloudy"                : ":cloud:",
		"partly-cloudy-day"     : ":partly_sunny:",
		"partly-cloudy-night"   : ":new_moon_with_face:",
		"unknown"               : ":sun_with_face:",
	}
	return icon.get(ds_icon,":sun_with_face:")

def weather_status_icon(ds_icon,moon_phase):
	icon = weather_icon(ds_icon)
	if (icon == ":new_moon_with_face:"):
		return moon_icon(moon_phase)
	return icon

def wind_dir_icon(wind_bearing):
	if (wind_bearing < 20):
		return ":arrow_up:"
	if (wind_bearing < 70):
		return ":arrow_upper_right:"
	if (wind_bearing < 110):
		return ":arrow_right:"
	if (wind_bearing < 160):
		return ":arrow_lower_right:"
	if (wind_bearing < 200):
		return ":arrow_down:"
	if (wind_bearing < 250):
		return ":arrow_lower_left:"
	if (wind_bearing < 290):
		return ":arrow_left:"
	if (wind_bearing < 340):
		return ":arrow_upper_left:"
	return ":arrow_up:"

def main():
	sense = SenseHat()	
	curr_conditions = get_current_conditions()
	if ('currently' not in curr_conditions):
		print "Error! Dark Sky API call failed, check your GPS coordinates and make sure your Dark Sky API key is valid!\n"
		print curr_conditions
		exit()
	else:
		streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
	while True:
		# -------------- Sense Hat --------------
		# Read the sensors
		temp_c = sense.get_temperature()
		humidity = sense.get_humidity() 
		pressure_mb = sense.get_pressure() 

		# Format the data
		temp_f = temp_c * 9.0 / 5.0 + 32.0
		temp_f = float("{0:.2f}".format(temp_f))
		temp_c = float("{0:.2f}".format(temp_c))
		humidity = float("{0:.2f}".format(humidity))
		pressure_in = 0.0295301*(pressure_mb)
		pressure_in = float("{0:.2f}".format(pressure_in))
		pressure_mb = float("{0:.2f}".format(pressure_mb))

		# Print and stream 
		if (METRIC_UNITS):
			print SENSOR_LOCATION_NAME + " Temperature(C): " + str(temp_c)
			print SENSOR_LOCATION_NAME + " Pressure(mb): " + str(pressure_mb)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_c)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (mb)", pressure_mb)
		else:
			print SENSOR_LOCATION_NAME + " Temperature(F): " + str(temp_f)
			print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_in)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (IN)", pressure_in)
		print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
		streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", humidity)

		# -------------- Dark Sky --------------		
		curr_conditions = get_current_conditions()
		if ('currently' not in curr_conditions):
			print "Error! Dark Sky API call failed. Skipping a reading then continuing ...\n"
			print curr_conditions
		else:
			streamer.log(":house: Location",GPS_COORDS)
			
			if 'humidity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['humidity']):
				streamer.log(":droplet: Humidity(%)", curr_conditions['currently']['humidity']*100)

			if 'temperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['temperature']): 
				streamer.log("Temperature",curr_conditions['currently']['temperature'])

			if 'apparentTemperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['apparentTemperature']): 
				streamer.log("Feels Like",curr_conditions['currently']['apparentTemperature'])

			if 'dewPoint' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['dewPoint']):
				streamer.log("Dewpoint",curr_conditions['currently']['dewPoint'])

			if 'windSpeed' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windSpeed']):
				streamer.log(":dash: Wind Speed",curr_conditions['currently']['windSpeed'])

			if 'windGust' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windGust']):
				streamer.log(":dash: Wind Gust",curr_conditions['currently']['windGust'])

			if 'windBearing' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windBearing']):
				streamer.log(":dash: Wind Direction",wind_dir_icon(curr_conditions['currently']['windBearing']))

			if 'pressure' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['pressure']):
				streamer.log("Pressure",curr_conditions['currently']['pressure'])

			if 'precipIntensity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipIntensity']):
				streamer.log(":umbrella: Precipitation Intensity",curr_conditions['currently']['precipIntensity'])

			if 'precipProbability' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipProbability']):
				streamer.log(":umbrella: Precipitation Probabiity(%)",curr_conditions['currently']['precipProbability']*100)

			if 'cloudCover' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['cloudCover']):
				streamer.log(":cloud: Cloud Cover(%)",curr_conditions['currently']['cloudCover']*100)

			if 'uvIndex' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['uvIndex']):
				streamer.log(":sunny: UV Index:",curr_conditions['currently']['uvIndex'])

			if 'summary' in curr_conditions['currently']:
				streamer.log(":cloud: Weather Summary",curr_conditions['currently']['summary'])

			if 'hourly' in curr_conditions:
				streamer.log("Today's Forecast",curr_conditions['hourly']['summary'])

			if 'daily' in curr_conditions:
				if 'data' in curr_conditions['daily']:
					if 'moonPhase' in curr_conditions['daily']['data'][0]:
						moon_phase = curr_conditions['daily']['data'][0]['moonPhase']
						streamer.log(":crescent_moon: Moon Phase",moon_icon(moon_phase))
						streamer.log(":cloud: Weather Conditions",weather_status_icon(curr_conditions['currently']['icon'],moon_phase))

			streamer.flush()
		time.sleep(60*MINUTES_BETWEEN_READS)

if __name__ == "__main__":
    main()



================================================
FILE: sensehat_darksky_calibrated.py
================================================
import urllib2
import json
import os
import glob
import time
import RPi.GPIO as io
from ISStreamer.Streamer import Streamer
from sense_hat import SenseHat 
import subprocess

# --------- User Settings ---------
CITY = "Franklin"
GPS_COORDS = "35.9260096,-86.868537"
SENSOR_LOCATION_NAME = "Office"
DARKSKY_API_KEY = "PLACE YOUR DARK SKY API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "shds1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_current_conditions():
	api_conditions_url = "https://api.darksky.net/forecast/" + DARKSKY_API_KEY + "/" + GPS_COORDS + "?units=auto"
	try:
		f = urllib2.urlopen(api_conditions_url)
	except:
		return []
	json_currently = f.read()
	f.close()
	return json.loads(json_currently)

def moon_icon(moon_phase):
	if moon_phase == 0:
		return ":new_moon:"
	if moon_phase < .125:
		return ":waxing_crescent_moon:"
	if moon_phase < .25:
		return ":first_quarter_moon:"
	if moon_phase < .48:
		return ":waxing_gibbous_moon:"
	if moon_phase < .52:
		return ":full_moon:"
	if moon_phase < .625:
		return ":waning_gibbous_moon:"
	if moon_phase < .75:
		return ":last_quarter_moon:"
	if moon_phase < 1:
		return ":waning_crescent_moon:"
	return ":crescent_moon:"

def weather_icon(ds_icon):
	icon = {
		"clear-day"            	: ":sunny:",
		"clear-night"           : ":new_moon_with_face:",
		"rain"                  : ":umbrella:",
		"snow"                  : ":snowflake:",
		"sleet"                 : ":sweat_drops: :snowflake:",
		"wind"                  : ":wind_blowing_face:",
		"fog"                   : ":fog:",
		"cloudy"                : ":cloud:",
		"partly-cloudy-day"     : ":partly_sunny:",
		"partly-cloudy-night"   : ":new_moon_with_face:",
		"unknown"               : ":sun_with_face:",
	}
	return icon.get(ds_icon,":sun_with_face:")

def weather_status_icon(ds_icon,moon_phase):
	icon = weather_icon(ds_icon)
	if (icon == ":new_moon_with_face:"):
		return moon_icon(moon_phase)
	return icon

def wind_dir_icon(wind_bearing):
	if (wind_bearing < 20):
		return ":arrow_up:"
	if (wind_bearing < 70):
		return ":arrow_upper_right:"
	if (wind_bearing < 110):
		return ":arrow_right:"
	if (wind_bearing < 160):
		return ":arrow_lower_right:"
	if (wind_bearing < 200):
		return ":arrow_down:"
	if (wind_bearing < 250):
		return ":arrow_lower_left:"
	if (wind_bearing < 290):
		return ":arrow_left:"
	if (wind_bearing < 340):
		return ":arrow_upper_left:"
	return ":arrow_up:"

def main():
	sense = SenseHat()	
	curr_conditions = get_current_conditions()
	if ('currently' not in curr_conditions):
		print "Error! Dark Sky API call failed, check your GPS coordinates and make sure your Dark Sky API key is valid!\n"
		print curr_conditions
		exit()
	else:
		streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
	while True:
		# -------------- Sense Hat --------------
		# Read the sensors
		temp_c = sense.get_temperature()
		humidity = sense.get_humidity() 
		pressure_mb = sense.get_pressure() 
    		cpu_temp = subprocess.check_output("vcgencmd measure_temp", shell=True)
    		array = cpu_temp.split("=")
    		array2 = array[1].split("'")

    		cpu_tempc = float(array2[0])
    		cpu_tempc = float("{0:.2f}".format(cpu_tempc))
    		cpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0
    		cpu_tempf = float("{0:.2f}".format(cpu_tempf))

    		temp_calibrated_c = temp_c - ((cpu_tempc - temp_c)/5.466)
    
		# Format the data
		temp_f = temp_calibrated_c * 9.0 / 5.0 + 32.0
		temp_f = float("{0:.2f}".format(temp_f))
		temp_calibrated_c = float("{0:.2f}".format(temp_calibrated_c))
		humidity = float("{0:.2f}".format(humidity))
		pressure_in = 0.0295301*(pressure_mb)
		pressure_in = float("{0:.2f}".format(pressure_in))
		pressure_mb = float("{0:.2f}".format(pressure_mb))

		# Print and stream 
		if (METRIC_UNITS):
			print SENSOR_LOCATION_NAME + " Temperature(C): " + str(temp_calibrated_c)
			print SENSOR_LOCATION_NAME + " Pressure(mb): " + str(pressure_mb)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_calibrated_c)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (mb)", pressure_mb)
			print "CPU Temperature(C): " + str(cpu_tempc)
			streamer.log("CPU Temperature",cpu_tempc)
		else:
			print SENSOR_LOCATION_NAME + " Temperature(F): " + str(temp_f)
			print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_in)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (IN)", pressure_in)
			print "CPU Temperature(F): " + str(cpu_tempf)
			streamer.log("CPU Temperature",cpu_tempf)
			print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
			streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", humidity)

		# -------------- Dark Sky --------------		
		curr_conditions = get_current_conditions()
		if ('currently' not in curr_conditions):
			print "Error! Dark Sky API call failed. Skipping a reading then continuing ...\n"
			print curr_conditions
		else:
			streamer.log(":house: Location",GPS_COORDS)
			
			if 'humidity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['humidity']):
				streamer.log(":droplet: Humidity(%)", curr_conditions['currently']['humidity']*100)

			if 'temperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['temperature']): 
				streamer.log("Temperature",curr_conditions['currently']['temperature'])

			if 'apparentTemperature' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['apparentTemperature']): 
				streamer.log("Feels Like",curr_conditions['currently']['apparentTemperature'])

			if 'dewPoint' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['dewPoint']):
				streamer.log("Dewpoint",curr_conditions['currently']['dewPoint'])

			if 'windSpeed' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windSpeed']):
				streamer.log(":dash: Wind Speed",curr_conditions['currently']['windSpeed'])

			if 'windGust' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windGust']):
				streamer.log(":dash: Wind Gust",curr_conditions['currently']['windGust'])

			if 'windBearing' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['windBearing']):
				streamer.log(":dash: Wind Direction",wind_dir_icon(curr_conditions['currently']['windBearing']))

			if 'pressure' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['pressure']):
				streamer.log("Pressure",curr_conditions['currently']['pressure'])

			if 'precipIntensity' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipIntensity']):
				streamer.log(":umbrella: Precipitation Intensity",curr_conditions['currently']['precipIntensity'])

			if 'precipProbability' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['precipProbability']):
				streamer.log(":umbrella: Precipitation Probabiity(%)",curr_conditions['currently']['precipProbability']*100)

			if 'cloudCover' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['cloudCover']):
				streamer.log(":cloud: Cloud Cover(%)",curr_conditions['currently']['cloudCover']*100)

			if 'uvIndex' in curr_conditions['currently'] and isFloat(curr_conditions['currently']['uvIndex']):
				streamer.log(":sunny: UV Index:",curr_conditions['currently']['uvIndex'])

			if 'summary' in curr_conditions['currently']:
				streamer.log(":cloud: Weather Summary",curr_conditions['currently']['summary'])

			if 'hourly' in curr_conditions:
				streamer.log("Today's Forecast",curr_conditions['hourly']['summary'])

			if 'daily' in curr_conditions:
				if 'data' in curr_conditions['daily']:
					if 'moonPhase' in curr_conditions['daily']['data'][0]:
						moon_phase = curr_conditions['daily']['data'][0]['moonPhase']
						streamer.log(":crescent_moon: Moon Phase",moon_icon(moon_phase))
						streamer.log(":cloud: Weather Conditions",weather_status_icon(curr_conditions['currently']['icon'],moon_phase))

			streamer.flush()
		time.sleep(60*MINUTES_BETWEEN_READS)

if __name__ == "__main__":
    main()



================================================
FILE: sensehat_wunderground.py
================================================
import os
import urllib2
import json
import glob
import time
import RPi.GPIO as io
from ISStreamer.Streamer import Streamer
from sense_hat import SenseHat 

# --------- User Settings ---------
STATE = "CA"
CITY = "San_Francisco"
SENSOR_LOCATION_NAME = "Office"
WUNDERGROUND_API_KEY = "PLACE YOUR WUNDERGROUND API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "shwu1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_conditions():
	api_conditions_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/conditions/q/" + STATE + "/" + CITY + ".json"
	try:
	  	f = urllib2.urlopen(api_conditions_url)
	except:
		print "Failed to get conditions"
		return []
	json_conditions = f.read()
	f.close()
	return json.loads(json_conditions)

def get_astronomy():
	api_astronomy_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/astronomy/q/" + STATE + "/" + CITY + ".json"
	try:
		f = urllib2.urlopen(api_astronomy_url)
	except:
		print "Failed to get astronomy"
		return []		
	json_astronomy = f.read()
	f.close()
	return json.loads(json_astronomy)

def is_night(astronomy):
	sunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])
	sunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])
	sunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])
	sunset_min   = int(astronomy['moon_phase']['sunset']['minute'])
	current_hour = int(astronomy['moon_phase']['current_time']['hour'])
	current_min  = int(astronomy['moon_phase']['current_time']['minute'])
	if ( (current_hour < sunrise_hour) or
	     (current_hour > sunset_hour) or
	     ((current_hour == sunrise_hour) and
	      (current_min < sunrise_min)) or 
	     ((current_hour == sunset_hour) and
	      (current_min > sunset_min)) ):
		return True
	return False

def moon_icon(moon_phase):
	icon = {
		"New Moon"        : ":new_moon:",
		"Waxing Crescent" : ":waxing_crescent_moon:",
		"First Quarter"   : ":first_quarter_moon:",
		"Waxing Gibbous"  : ":waxing_gibbous_moon:",
		"Full Moon"       : ":full_moon:",
		"Full"            : ":full_moon:",
		"Waning Gibbous"  : ":waning_gibbous_moon:",
		"Last Quarter"    : ":last_quarter_moon:",
		"Waning Crescent" : ":waning_crescent_moon:",
	}
	return icon.get(moon_phase,":crescent_moon:")

def weather_icon(weather_conditions):
	icon = {
		"clear"            : ":sun_with_face:",
		"cloudy"           : ":cloud:",
		"flurries"         : ":snowflake:",
		"fog"              : ":foggy:",
		"hazy"             : ":foggy:",
		"mostlycloudy"     : ":cloud:",
		"mostlysunny"      : ":sun_with_face:",
		"partlycloudy"     : ":partly_sunny:",
		"partlysunny"      : ":partly_sunny:",
		"sleet"            : ":sweat_drops: :snowflake:",
		"rain"             : ":umbrella:",
		"snow"             : ":snowflake:",
		"sunny"            : ":sun_with_face:",
		"tstorms"          : ":zap: :umbrella:",
		"unknown"          : ":sun_with_face:",
	}
	return icon.get(weather_conditions,":sun_with_face:")

def weather_status_icon(conditions, astronomy):
	moon_phase = astronomy['moon_phase']['phaseofMoon']
	weather_conditions = conditions['current_observation']['icon']
	icon = weather_icon(weather_conditions)
	if is_night(astronomy):
		if ((icon == ":sunny:") or
		    (icon == ":partly_sunny:") or
		    (icon == ":sun_with_face:")):
			return moon_icon(moon_phase)
	return icon

def wind_dir_icon(conditions, astronomy):
	icon = {
		"East"     : ":arrow_right:",
		"ENE"      : ":arrow_upper_right:",
		"ESE"      : ":arrow_lower_right:",
		"NE"       : ":arrow_upper_right:",
		"NNE"      : ":arrow_upper_right:",
		"NNW"      : ":arrow_upper_left:",
		"North"    : ":arrow_up:",
		"NW"       : ":arrow_upper_left:",
		"SE"       : ":arrow_lower_right:",
		"South"    : ":arrow_down:",
		"SSE"      : ":arrow_lower_right:",
		"SSW"      : ":arrow_lower_left:",
		"SW"       : ":arrow_lower_left:",
		"Variable" : ":arrows_counterclockwise:",
		"West"     : ":arrow_left:",
		"WNW"      : ":arrow_upper_left:",
		"WSW"      : ":arrow_lower_left:",
	}
	return icon.get(conditions['current_observation']['wind_dir'],":crescent_moon:")	

def main():
	sense = SenseHat()
	conditions = get_conditions()
	astronomy = get_astronomy()
	if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
		print "Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!"
		if 'error' in conditions['response']:
			print "Error Type: " + conditions['response']['error']['type']
			print "Error Description: " + conditions['response']['error']['description']
		exit()
	else:
		streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
		streamer.log(":house: Location",conditions['current_observation']['display_location']['full'])
	while True:
		# -------------- Sense Hat --------------
		# Read the sensors
		temp_c = sense.get_temperature()
		humidity = sense.get_humidity() 
		pressure_mb = sense.get_pressure() 

		# Format the data
		temp_f = temp_c * 9.0 / 5.0 + 32.0
		temp_f = float("{0:.2f}".format(temp_f))
		temp_c = float("{0:.2f}".format(temp_c))
		humidity = float("{0:.2f}".format(humidity))
		pressure_in = 0.0295301*(pressure_mb)
		pressure_in = float("{0:.2f}".format(pressure_in))
		pressure_mb = float("{0:.2f}".format(pressure_mb))

		# Print and stream 
		if (METRIC_UNITS):
			print SENSOR_LOCATION_NAME + " Temperature(C): " + str(temp_c)
			print SENSOR_LOCATION_NAME + " Pressure(mb): " + str(pressure_mb)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_c)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (mb)", pressure_mb)
		else:
			print SENSOR_LOCATION_NAME + " Temperature(F): " + str(temp_f)
			print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_in)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (IN)", pressure_in)
		print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
		streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", humidity)

		# -------------- Wunderground --------------
		conditions = get_conditions()
		astronomy = get_astronomy()
		if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
			print "Error! Wunderground API call failed. Skipping a reading then continuing ..."
		else:
			humidity_pct = conditions['current_observation']['relative_humidity']
			humidity = humidity_pct.replace("%","")

			# Stream valid conditions to Initial State
			streamer.log(":cloud: " + CITY + " Weather Conditions",weather_status_icon(conditions, astronomy))
			streamer.log(":crescent_moon: Moon Phase",moon_icon(astronomy['moon_phase']['phaseofMoon']))
			streamer.log(":dash: " + CITY + " Wind Direction",wind_dir_icon(conditions, astronomy))
			if (METRIC_UNITS):
				if isFloat(conditions['current_observation']['temp_c']): 
					streamer.log(CITY + " Temperature(C)",conditions['current_observation']['temp_c'])
				if isFloat(conditions['current_observation']['dewpoint_c']):
					streamer.log(CITY + " Dewpoint(C)",conditions['current_observation']['dewpoint_c'])
				if isFloat(conditions['current_observation']['wind_kph']):
					streamer.log(":dash: " + CITY + " Wind Speed(KPH)",conditions['current_observation']['wind_kph'])
				if isFloat(conditions['current_observation']['wind_gust_kph']):
					streamer.log(":dash: " + CITY + " Wind Gust(KPH)",conditions['current_observation']['wind_gust_kph'])
				if isFloat(conditions['current_observation']['pressure_mb']):
					streamer.log(CITY + " Pressure(mb)",conditions['current_observation']['pressure_mb'])
				if isFloat(conditions['current_observation']['precip_1hr_metric']):
					streamer.log(":umbrella: " + CITY + " Precip 1 Hour(mm)",conditions['current_observation']['precip_1hr_metric'])
				if isFloat(conditions['current_observation']['precip_today_metric']):
					streamer.log(":umbrella: " + CITY + " Precip Today(mm)",conditions['current_observation']['precip_today_metric'])
			else:
				if isFloat(conditions['current_observation']['temp_f']): 
					streamer.log(CITY + " Temperature(F)",conditions['current_observation']['temp_f'])
				if isFloat(conditions['current_observation']['dewpoint_f']):
					streamer.log(CITY + " Dewpoint(F)",conditions['current_observation']['dewpoint_f'])
				if isFloat(conditions['current_observation']['wind_mph']):
					streamer.log(":dash: " + CITY + " Wind Speed(MPH)",conditions['current_observation']['wind_mph'])
				if isFloat(conditions['current_observation']['wind_gust_mph']):
					streamer.log(":dash: " + CITY + " Wind Gust(MPH)",conditions['current_observation']['wind_gust_mph'])
				if isFloat(conditions['current_observation']['pressure_in']):
					streamer.log(CITY + " Pressure(IN)",conditions['current_observation']['pressure_in'])
				if isFloat(conditions['current_observation']['precip_1hr_in']):
					streamer.log(":umbrella: " + CITY + " Precip 1 Hour(IN)",conditions['current_observation']['precip_1hr_in'])
				if isFloat(conditions['current_observation']['precip_today_in']):
					streamer.log(":umbrella: " + CITY + " Precip Today(IN)",conditions['current_observation']['precip_today_in'])
			if isFloat(conditions['current_observation']['solarradiation']):
				streamer.log(":sunny: " + CITY + " Solar Radiation (watt/m^2)",conditions['current_observation']['solarradiation'])
			if isFloat(humidity):
				streamer.log(":droplet: " + CITY + " Humidity(%)",humidity)
			if isFloat(conditions['current_observation']['UV']):
				streamer.log(":sunny: " + CITY + " UV Index:",conditions['current_observation']['UV'])
			streamer.flush()
		time.sleep(60*MINUTES_BETWEEN_READS)

if __name__ == "__main__":
    main()




================================================
FILE: sensehat_wunderground_calibrated.py
================================================
import os
import urllib2
import json
import glob
import time
import RPi.GPIO as io
from ISStreamer.Streamer import Streamer
from sense_hat import SenseHat 
import subprocess

# --------- User Settings ---------
STATE = "CA"
CITY = "San_Francisco"
SENSOR_LOCATION_NAME = "Office"
WUNDERGROUND_API_KEY = "PLACE YOUR WUNDERGROUND API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "shwu1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_conditions():
	api_conditions_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/conditions/q/" + STATE + "/" + CITY + ".json"
	try:
	  	f = urllib2.urlopen(api_conditions_url)
	except:
		print "Failed to get conditions"
		return []
	json_conditions = f.read()
	f.close()
	return json.loads(json_conditions)

def get_astronomy():
	api_astronomy_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/astronomy/q/" + STATE + "/" + CITY + ".json"
	try:
		f = urllib2.urlopen(api_astronomy_url)
	except:
		print "Failed to get astronomy"
		return []		
	json_astronomy = f.read()
	f.close()
	return json.loads(json_astronomy)

def is_night(astronomy):
	sunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])
	sunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])
	sunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])
	sunset_min   = int(astronomy['moon_phase']['sunset']['minute'])
	current_hour = int(astronomy['moon_phase']['current_time']['hour'])
	current_min  = int(astronomy['moon_phase']['current_time']['minute'])
	if ( (current_hour < sunrise_hour) or
	     (current_hour > sunset_hour) or
	     ((current_hour == sunrise_hour) and
	      (current_min < sunrise_min)) or 
	     ((current_hour == sunset_hour) and
	      (current_min > sunset_min)) ):
		return True
	return False

def moon_icon(moon_phase):
	icon = {
		"New Moon"        : ":new_moon:",
		"Waxing Crescent" : ":waxing_crescent_moon:",
		"First Quarter"   : ":first_quarter_moon:",
		"Waxing Gibbous"  : ":waxing_gibbous_moon:",
		"Full Moon"       : ":full_moon:",
		"Full"            : ":full_moon:",
		"Waning Gibbous"  : ":waning_gibbous_moon:",
		"Last Quarter"    : ":last_quarter_moon:",
		"Waning Crescent" : ":waning_crescent_moon:",
	}
	return icon.get(moon_phase,":crescent_moon:")

def weather_icon(weather_conditions):
	icon = {
		"clear"            : ":sun_with_face:",
		"cloudy"           : ":cloud:",
		"flurries"         : ":snowflake:",
		"fog"              : ":foggy:",
		"hazy"             : ":foggy:",
		"mostlycloudy"     : ":cloud:",
		"mostlysunny"      : ":sun_with_face:",
		"partlycloudy"     : ":partly_sunny:",
		"partlysunny"      : ":partly_sunny:",
		"sleet"            : ":sweat_drops: :snowflake:",
		"rain"             : ":umbrella:",
		"snow"             : ":snowflake:",
		"sunny"            : ":sun_with_face:",
		"tstorms"          : ":zap: :umbrella:",
		"unknown"          : ":sun_with_face:",
	}
	return icon.get(weather_conditions,":sun_with_face:")

def weather_status_icon(conditions, astronomy):
	moon_phase = astronomy['moon_phase']['phaseofMoon']
	weather_conditions = conditions['current_observation']['icon']
	icon = weather_icon(weather_conditions)
	if is_night(astronomy):
		if ((icon == ":sunny:") or
		    (icon == ":partly_sunny:") or
		    (icon == ":sun_with_face:")):
			return moon_icon(moon_phase)
	return icon

def wind_dir_icon(conditions, astronomy):
	icon = {
		"East"     : ":arrow_right:",
		"ENE"      : ":arrow_upper_right:",
		"ESE"      : ":arrow_lower_right:",
		"NE"       : ":arrow_upper_right:",
		"NNE"      : ":arrow_upper_right:",
		"NNW"      : ":arrow_upper_left:",
		"North"    : ":arrow_up:",
		"NW"       : ":arrow_upper_left:",
		"SE"       : ":arrow_lower_right:",
		"South"    : ":arrow_down:",
		"SSE"      : ":arrow_lower_right:",
		"SSW"      : ":arrow_lower_left:",
		"SW"       : ":arrow_lower_left:",
		"Variable" : ":arrows_counterclockwise:",
		"West"     : ":arrow_left:",
		"WNW"      : ":arrow_upper_left:",
		"WSW"      : ":arrow_lower_left:",
	}
	return icon.get(conditions['current_observation']['wind_dir'],":crescent_moon:")	

def main():
	sense = SenseHat()
	conditions = get_conditions()
	astronomy = get_astronomy()
	if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
		print "Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!"
		if 'error' in conditions['response']:
			print "Error Type: " + conditions['response']['error']['type']
			print "Error Description: " + conditions['response']['error']['description']
		exit()
	else:
		streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
		streamer.log(":house: Location",conditions['current_observation']['display_location']['full'])
	while True:
		# -------------- Sense Hat --------------
		# Read the sensors
		temp_c = sense.get_temperature()
		humidity = sense.get_humidity() 
		pressure_mb = sense.get_pressure() 
    		cpu_temp = subprocess.check_output("vcgencmd measure_temp", shell=True)
    		array = cpu_temp.split("=")
    		array2 = array[1].split("'")

    		cpu_tempc = float(array2[0])
    		cpu_tempc = float("{0:.2f}".format(cpu_tempc))
    		cpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0
    		cpu_tempf = float("{0:.2f}".format(cpu_tempf))

    		temp_calibrated_c = temp_c - ((cpu_tempc - temp_c)/5.466)
    
		# Format the data
		temp_f = temp_calibrated_c * 9.0 / 5.0 + 32.0
		temp_f = float("{0:.2f}".format(temp_f))
		temp_calibrated_c = float("{0:.2f}".format(temp_calibrated_c))
		humidity = float("{0:.2f}".format(humidity))
		pressure_in = 0.0295301*(pressure_mb)
		pressure_in = float("{0:.2f}".format(pressure_in))
		pressure_mb = float("{0:.2f}".format(pressure_mb))

		# Print and stream 
		if (METRIC_UNITS):
			print SENSOR_LOCATION_NAME + " Temperature(C): " + str(temp_calibrated_c)
			print SENSOR_LOCATION_NAME + " Pressure(mb): " + str(pressure_mb)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_calibrated_c)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (mb)", pressure_mb)
			print(cpu_tempc)
			streamer.log("CPU Temperature",cpu_tempc)
		else:
			print SENSOR_LOCATION_NAME + " Temperature(F): " + str(temp_f)
			print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_in)
			streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
			streamer.log(":cloud: " + SENSOR_LOCATION_NAME + " Pressure (IN)", pressure_in)
			print(cpu_tempf)
			streamer.log("CPU Temperature",cpu_tempf)
			print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
			streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", humidity)

		# -------------- Wunderground --------------
		conditions = get_conditions()
		astronomy = get_astronomy()
		if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
			print "Error! Wunderground API call failed. Skipping a reading then continuing ..."
		else:
			humidity_pct = conditions['current_observation']['relative_humidity']
			humidity = humidity_pct.replace("%","")

			# Stream valid conditions to Initial State
			streamer.log(":cloud: " + CITY + " Weather Conditions",weather_status_icon(conditions, astronomy))
			streamer.log(":crescent_moon: Moon Phase",moon_icon(astronomy['moon_phase']['phaseofMoon']))
			streamer.log(":dash: " + CITY + " Wind Direction",wind_dir_icon(conditions, astronomy))
			if (METRIC_UNITS):
				if isFloat(conditions['current_observation']['temp_c']): 
					streamer.log(CITY + " Temperature(C)",conditions['current_observation']['temp_c'])
				if isFloat(conditions['current_observation']['dewpoint_c']):
					streamer.log(CITY + " Dewpoint(C)",conditions['current_observation']['dewpoint_c'])
				if isFloat(conditions['current_observation']['wind_kph']):
					streamer.log(":dash: " + CITY + " Wind Speed(KPH)",conditions['current_observation']['wind_kph'])
				if isFloat(conditions['current_observation']['wind_gust_kph']):
					streamer.log(":dash: " + CITY + " Wind Gust(KPH)",conditions['current_observation']['wind_gust_kph'])
				if isFloat(conditions['current_observation']['pressure_mb']):
					streamer.log(CITY + " Pressure(mb)",conditions['current_observation']['pressure_mb'])
				if isFloat(conditions['current_observation']['precip_1hr_metric']):
					streamer.log(":umbrella: " + CITY + " Precip 1 Hour(mm)",conditions['current_observation']['precip_1hr_metric'])
				if isFloat(conditions['current_observation']['precip_today_metric']):
					streamer.log(":umbrella: " + CITY + " Precip Today(mm)",conditions['current_observation']['precip_today_metric'])
			else:
				if isFloat(conditions['current_observation']['temp_f']): 
					streamer.log(CITY + " Temperature(F)",conditions['current_observation']['temp_f'])
				if isFloat(conditions['current_observation']['dewpoint_f']):
					streamer.log(CITY + " Dewpoint(F)",conditions['current_observation']['dewpoint_f'])
				if isFloat(conditions['current_observation']['wind_mph']):
					streamer.log(":dash: " + CITY + " Wind Speed(MPH)",conditions['current_observation']['wind_mph'])
				if isFloat(conditions['current_observation']['wind_gust_mph']):
					streamer.log(":dash: " + CITY + " Wind Gust(MPH)",conditions['current_observation']['wind_gust_mph'])
				if isFloat(conditions['current_observation']['pressure_in']):
					streamer.log(CITY + " Pressure(IN)",conditions['current_observation']['pressure_in'])
				if isFloat(conditions['current_observation']['precip_1hr_in']):
					streamer.log(":umbrella: " + CITY + " Precip 1 Hour(IN)",conditions['current_observation']['precip_1hr_in'])
				if isFloat(conditions['current_observation']['precip_today_in']):
					streamer.log(":umbrella: " + CITY + " Precip Today(IN)",conditions['current_observation']['precip_today_in'])
			if isFloat(conditions['current_observation']['solarradiation']):
				streamer.log(":sunny: " + CITY + " Solar Radiation (watt/m^2)",conditions['current_observation']['solarradiation'])
			if isFloat(humidity):
				streamer.log(":droplet: " + CITY + " Humidity(%)",humidity)
			if isFloat(conditions['current_observation']['UV']):
				streamer.log(":sunny: " + CITY + " UV Index:",conditions['current_observation']['UV'])
			streamer.flush()
		time.sleep(60*MINUTES_BETWEEN_READS)

if __name__ == "__main__":
    main()


================================================
FILE: wunderground.py
================================================
import urllib2
import json
import os
import glob
import time
from ISStreamer.Streamer import Streamer

# --------- User Settings ---------
STATE = "CA"
CITY = "San_Francisco"
WUNDERGROUND_API_KEY = "PLACE YOUR WUNDERGROUND API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "wu1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

def get_conditions():
	api_conditions_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/conditions/q/" + STATE + "/" + CITY + ".json"
	try:
		f = urllib2.urlopen(api_conditions_url)
	except:
		return []
	json_conditions = f.read()
	f.close()
	return json.loads(json_conditions)

def get_astronomy():
	api_astronomy_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/astronomy/q/" + STATE + "/" + CITY + ".json"
	try:
		f = urllib2.urlopen(api_astronomy_url)
	except:
		return []
	json_astronomy = f.read()
	f.close()
	return json.loads(json_astronomy)

def is_night(astronomy):
	sunrise_hour = int(astronomy['moon_phase']['sunrise']['hour'])
	sunrise_min  = int(astronomy['moon_phase']['sunrise']['minute'])
	sunset_hour  = int(astronomy['moon_phase']['sunset']['hour'])
	sunset_min   = int(astronomy['moon_phase']['sunset']['minute'])
	current_hour = int(astronomy['moon_phase']['current_time']['hour'])
	current_min  = int(astronomy['moon_phase']['current_time']['minute'])
	if ( (current_hour < sunrise_hour) or
	     (current_hour > sunset_hour) or
	     ((current_hour == sunrise_hour) and
	      (current_min < sunrise_min)) or 
	     ((current_hour == sunset_hour) and
	      (current_min > sunset_min)) ):
		return True
	return False

def moon_icon(moon_phase):
	icon = {
		"New Moon"        : ":new_moon:",
		"Waxing Crescent" : ":waxing_crescent_moon:",
		"First Quarter"   : ":first_quarter_moon:",
		"Waxing Gibbous"  : ":waxing_gibbous_moon:",
		"Full Moon"       : ":full_moon:",
		"Full"            : ":full_moon:",
		"Waning Gibbous"  : ":waning_gibbous_moon:",
		"Last Quarter"    : ":last_quarter_moon:",
		"Waning Crescent" : ":waning_crescent_moon:",
	}
	return icon.get(moon_phase,":crescent_moon:")

def weather_icon(weather_conditions):
	icon = {
		"clear"            : ":sun_with_face:",
		"cloudy"           : ":cloud:",
		"flurries"         : ":snowflake:",
		"fog"              : ":foggy:",
		"hazy"             : ":foggy:",
		"mostlycloudy"     : ":cloud:",
		"mostlysunny"      : ":sun_with_face:",
		"partlycloudy"     : ":partly_sunny:",
		"partlysunny"      : ":partly_sunny:",
		"sleet"            : ":sweat_drops: :snowflake:",
		"rain"             : ":umbrella:",
		"snow"             : ":snowflake:",
		"sunny"            : ":sun_with_face:",
		"tstorms"          : ":zap: :umbrella:",
		"unknown"          : ":sun_with_face:",
	}
	return icon.get(weather_conditions,":sun_with_face:")

def weather_status_icon (conditions, astronomy):
	moon_phase = astronomy['moon_phase']['phaseofMoon']
	weather_conditions = conditions['current_observation']['icon']
	icon = weather_icon(weather_conditions)
	if is_night(astronomy):
		if ((icon == ":sunny:") or
		    (icon == ":partly_sunny:") or
		    (icon == ":sun_with_face:")):
			return moon_icon(moon_phase)
	return icon

def wind_dir_icon (conditions, astronomy):
	icon = {
		"East"     : ":arrow_right:",
		"ENE"      : ":arrow_upper_right:",
		"ESE"      : ":arrow_lower_right:",
		"NE"       : ":arrow_upper_right:",
		"NNE"      : ":arrow_upper_right:",
		"NNW"      : ":arrow_upper_left:",
		"North"    : ":arrow_up:",
		"NW"       : ":arrow_upper_left:",
		"SE"       : ":arrow_lower_right:",
		"South"    : ":arrow_down:",
		"SSE"      : ":arrow_lower_right:",
		"SSW"      : ":arrow_lower_left:",
		"SW"       : ":arrow_lower_left:",
		"Variable" : ":arrows_counterclockwise:",
		"West"     : ":arrow_left:",
		"WNW"      : ":arrow_upper_left:",
		"WSW"      : ":arrow_lower_left:",
	}
	return icon.get(conditions['current_observation']['wind_dir'],":crescent_moon:")	

conditions = get_conditions()
astronomy = get_astronomy()
if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
	print "Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!"
	if 'error' in conditions['response']:
		print "Error Type: " + conditions['response']['error']['type']
		print "Error Description: " + conditions['response']['error']['description']
	exit()
else:
	streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
	streamer.log(":house: Location",conditions['current_observation']['display_location']['full'])
while True:
	conditions = get_conditions()
	astronomy = get_astronomy()
	if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
		print "Error! Wunderground API call failed. Skipping a reading then continuing ..."
	else:
		humidity_pct = conditions['current_observation']['relative_humidity']
		humidity = humidity_pct.replace("%","")

		# Stream valid conditions to Initial State
		streamer.log(":clock3: Updated Time",astronomy['moon_phase']['current_time']['hour'] + ":" + astronomy['moon_phase']['current_time']['minute'])
		streamer.log(":cloud: " + CITY + " Weather Conditions",weather_status_icon(conditions, astronomy))
		streamer.log(":crescent_moon: Moon Phase",moon_icon(astronomy['moon_phase']['phaseofMoon']))
		streamer.log(":dash: " + CITY + " Wind Direction",wind_dir_icon(conditions, astronomy))
		if (METRIC_UNITS):
			if isFloat(conditions['current_observation']['temp_c']): 
				streamer.log(CITY + " Temperature(C)",conditions['current_observation']['temp_c'])
			if isFloat(conditions['current_observation']['dewpoint_c']):
				streamer.log(CITY + " Dewpoint(C)",conditions['current_observation']['dewpoint_c'])
			if isFloat(conditions['current_observation']['wind_kph']):
				streamer.log(":dash: " + CITY + " Wind Speed(KPH)",conditions['current_observation']['wind_kph'])
			if isFloat(conditions['current_observation']['wind_gust_kph']):
				streamer.log(":dash: " + CITY + " Wind Gust(KPH)",conditions['current_observation']['wind_gust_kph'])
			if isFloat(conditions['current_observation']['pressure_mb']):
				streamer.log(CITY + " Pressure(mb)",conditions['current_observation']['pressure_mb'])
			if isFloat(conditions['current_observation']['precip_1hr_metric']):
				streamer.log(":umbrella: " + CITY + " Precip 1 Hour(mm)",conditions['current_observation']['precip_1hr_metric'])
			if isFloat(conditions['current_observation']['precip_today_metric']):
				streamer.log(":umbrella: " + CITY + " Precip Today(mm)",conditions['current_observation']['precip_today_metric'])
		else:
			if isFloat(conditions['current_observation']['temp_f']): 
				streamer.log(CITY + " Temperature(F)",conditions['current_observation']['temp_f'])
			if isFloat(conditions['current_observation']['dewpoint_f']):
				streamer.log(CITY + " Dewpoint(F)",conditions['current_observation']['dewpoint_f'])
			if isFloat(conditions['current_observation']['wind_mph']):
				streamer.log(":dash: " + CITY + " Wind Speed(MPH)",conditions['current_observation']['wind_mph'])
			if isFloat(conditions['current_observation']['wind_gust_mph']):
				streamer.log(":dash: " + CITY + " Wind Gust(MPH)",conditions['current_observation']['wind_gust_mph'])
			if isFloat(conditions['current_observation']['pressure_in']):
				streamer.log(CITY + " Pressure(IN)",conditions['current_observation']['pressure_in'])
			if isFloat(conditions['current_observation']['precip_1hr_in']):
				streamer.log(":umbrella: " + CITY + " Precip 1 Hour(IN)",conditions['current_observation']['precip_1hr_in'])
			if isFloat(conditions['current_observation']['precip_today_in']):
				streamer.log(":umbrella: " + CITY + " Precip Today(IN)",conditions['current_observation']['precip_today_in'])
		if isFloat(conditions['current_observation']['solarradiation']):
			streamer.log(":sunny: " + CITY + " Solar Radiation (watt/m^2)",conditions['current_observation']['solarradiation'])
		if isFloat(humidity):
			streamer.log(":droplet: " + CITY + " Humidity(%)",humidity)
		if isFloat(conditions['current_observation']['UV']):
			streamer.log(":sunny: " + CITY + " UV Index:",conditions['current_observation']['UV'])
		streamer.flush()
	time.sleep(60*MINUTES_BETWEEN_READS)


================================================
FILE: wunderground_historical.py
================================================
import urllib2
import json
import os
import glob
import time
from datetime import timedelta, date
from ISStreamer.Streamer import Streamer

# --------- User Settings ---------
STATE = "CA"
CITY = "San_Francisco"
WUNDERGROUND_API_KEY = "PLACE YOUR WUNDERGROUND API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "wu1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
STARTDATE = date(YYYY,MM,DD)
ENDDATE = date(YYYY,MM,DD)
SECONDS_BETWEEN_SEND = 5
# ---------------------------------

def isFloat(string):
    try:
        float(string)
        if float(string) < 0:
        	raise ValueError
        return True
    except ValueError:
        return False

def daterange(start_date, end_date):
    for n in range(int((end_date - start_date).days)):
        yield start_date + timedelta(n)

def get_conditions(readDate):
	api_conditions_url = "http://api.wunderground.com/api/" + WUNDERGROUND_API_KEY + "/history_" + readDate + "/q/" + STATE +"/"+ CITY + ".json"
	try:
	  	f = urllib2.urlopen(api_conditions_url)
	except:
		print "Failed to get conditions"
		return False
	json_conditions = f.read()
	f.close()
	return json.loads(json_conditions)	

streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)


while True:
	for single_date in daterange(STARTDATE,ENDDATE):
		conditions = get_conditions(single_date.strftime("%Y%m%d"))

		if (conditions != False):
			for i in range(len(conditions['history']['observations'])):
				dateInfo = conditions['history']['observations'][i]['date']
				date = dateInfo['mday']+"."+dateInfo['mon']+"."+dateInfo['year']+" "+dateInfo['hour']+":"+dateInfo['min']+":00"
				print date
				pattern = '%d.%m.%Y %H:%M:%S'
				epoch = int(time.mktime(time.strptime(date, pattern)))

				humidity_wu = conditions['history']['observations'][i]['hum']
				temp_wu = conditions['history']['observations'][i]['tempi']
				pressure_wu = conditions['history']['observations'][i]['pressurem']
				precip_wu = conditions['history']['observations'][i]['precipi']
				wind_speed_wu = conditions['history']['observations'][i]['wspdi']
				# dewpt_wu = conditions['history']['observations'][i]['dewpti']
				# wind_gust_wu = conditions['history']['observations'][i]['wgusti']
				# wind_dir_wu = conditions['history']['observations'][i]['wdird']
				# vis_wu = conditions['history']['observations'][i]['visi']
				# wind_chill_wu = conditions['history']['observations'][i]['windchilli']
				# heat_index_wu = conditions['history']['observations'][i]['heatindexi']
				# conds_wu = conditions['history']['observations'][i]['conds']
				# fog_wu = conditions['history']['observations'][i]['fog']
				# rain_wu = conditions['history']['observations'][i]['rain']
				# snow_wu = conditions['history']['observations'][i]['snow']
				# hail_wu = conditions['history']['observations'][i]['hail']
				# thunder_wu = conditions['history']['observations'][i]['thunder']
				# tornado_wu = conditions['history']['observations'][i]['tornado']

				if isFloat(humidity_wu):
					streamer.log("WU Humidity (%)",humidity_wu,epoch)
				if isFloat(temp_wu):
					streamer.log("WU Temp",temp_wu,epoch)
				if isFloat(pressure_wu):
					streamer.log("WU Pressure",pressure_wu,epoch)
				if isFloat(precip_wu):
					streamer.log("WU Rain",precip_wu,epoch)
				if isFloat(wind_speed_wu):
					streamer.log("WU Wind Speed",wind_speed_wu,epoch)
				# if isFloat(dewpt_wu):
				# 	streamer.log("WU Dew Point",dewpt_wu,epoch)
				# if isFloat(wind_gust_wu):
				# 	streamer.log("WU Wind Gust",wind_gust_wu,epoch)
				# if isFloat(wind_dir_wu):
				# 	streamer.log("WU Wind Direction",wind_dir_wu,epoch)
				# if isFloat(vis_wu):
				# 	streamer.log("WU Visibility",vis_wu,epoch)
				# if isFloat(wind_chill_wu):
				# 	streamer.log("WU Wind Chill",wind_chill_wu,epoch)
				# if isFloat(heat_index_wu):
				# 	streamer.log("WU Heat Index",heat_index_wu,epoch)
				# if isFloat(conds_wu):
				# 	streamer.log("WU Conditions",conds_wu,epoch)
				# if isFloat(fog_wu):
				# 	streamer.log("WU Fog",fog_wu,epoch)
				# if isFloat(rain_wu):
				# 	streamer.log("WU Rain",rain_wu,epoch)
				# if isFloat(snow_wu):
				# 	streamer.log("WU Snow",snow_wu,epoch)
				# if isFloat(hail_wu):
				# 	streamer.log("WU Hail",hail_wu,epoch)
				# if isFloat(thunder_wu):
				# 	streamer.log("WU Thunder",thunder_wu,epoch)
				# if isFloat(tornado_wu):
				# 	streamer.log("WU Tornado",tornado_wu,epoch)

				streamer.flush()
				time.sleep(SECONDS_BETWEEN_SEND)

			if single_date == ENDDATE:
				print("All dates streamed")
				exit()
Download .txt
gitextract_e0spm_96/

├── ActualTemp.py
├── CPUTemp.py
├── LICENSE
├── README.md
├── darksky.py
├── sensehat.py
├── sensehat_darksky.py
├── sensehat_darksky_calibrated.py
├── sensehat_wunderground.py
├── sensehat_wunderground_calibrated.py
├── wunderground.py
└── wunderground_historical.py
Download .txt
SYMBOL INDEX (59 symbols across 8 files)

FILE: CPUTemp.py
  function isFloat (line 23) | def isFloat(string):
  function get_conditions (line 30) | def get_conditions():
  function get_astronomy (line 41) | def get_astronomy():
  function is_night (line 52) | def is_night(astronomy):
  function moon_icon (line 68) | def moon_icon(moon_phase):
  function weather_icon (line 82) | def weather_icon(weather_conditions):
  function weather_status_icon (line 102) | def weather_status_icon(conditions, astronomy):
  function wind_dir_icon (line 113) | def wind_dir_icon(conditions, astronomy):
  function main (line 135) | def main():

FILE: darksky.py
  function isFloat (line 19) | def isFloat(string):
  function get_current_conditions (line 26) | def get_current_conditions():
  function moon_icon (line 36) | def moon_icon(moon_phase):
  function weather_icon (line 55) | def weather_icon(ds_icon):
  function weather_status_icon (line 71) | def weather_status_icon(ds_icon,moon_phase):
  function wind_dir_icon (line 77) | def wind_dir_icon(wind_bearing):
  function main (line 96) | def main():

FILE: sensehat_darksky.py
  function isFloat (line 22) | def isFloat(string):
  function get_current_conditions (line 29) | def get_current_conditions():
  function moon_icon (line 39) | def moon_icon(moon_phase):
  function weather_icon (line 58) | def weather_icon(ds_icon):
  function weather_status_icon (line 74) | def weather_status_icon(ds_icon,moon_phase):
  function wind_dir_icon (line 80) | def wind_dir_icon(wind_bearing):
  function main (line 99) | def main():

FILE: sensehat_darksky_calibrated.py
  function isFloat (line 23) | def isFloat(string):
  function get_current_conditions (line 30) | def get_current_conditions():
  function moon_icon (line 40) | def moon_icon(moon_phase):
  function weather_icon (line 59) | def weather_icon(ds_icon):
  function weather_status_icon (line 75) | def weather_status_icon(ds_icon,moon_phase):
  function wind_dir_icon (line 81) | def wind_dir_icon(wind_bearing):
  function main (line 100) | def main():

FILE: sensehat_wunderground.py
  function isFloat (line 22) | def isFloat(string):
  function get_conditions (line 29) | def get_conditions():
  function get_astronomy (line 40) | def get_astronomy():
  function is_night (line 51) | def is_night(astronomy):
  function moon_icon (line 67) | def moon_icon(moon_phase):
  function weather_icon (line 81) | def weather_icon(weather_conditions):
  function weather_status_icon (line 101) | def weather_status_icon(conditions, astronomy):
  function wind_dir_icon (line 112) | def wind_dir_icon(conditions, astronomy):
  function main (line 134) | def main():

FILE: sensehat_wunderground_calibrated.py
  function isFloat (line 23) | def isFloat(string):
  function get_conditions (line 30) | def get_conditions():
  function get_astronomy (line 41) | def get_astronomy():
  function is_night (line 52) | def is_night(astronomy):
  function moon_icon (line 68) | def moon_icon(moon_phase):
  function weather_icon (line 82) | def weather_icon(weather_conditions):
  function weather_status_icon (line 102) | def weather_status_icon(conditions, astronomy):
  function wind_dir_icon (line 113) | def wind_dir_icon(conditions, astronomy):
  function main (line 135) | def main():

FILE: wunderground.py
  function isFloat (line 19) | def isFloat(string):
  function get_conditions (line 26) | def get_conditions():
  function get_astronomy (line 36) | def get_astronomy():
  function is_night (line 46) | def is_night(astronomy):
  function moon_icon (line 62) | def moon_icon(moon_phase):
  function weather_icon (line 76) | def weather_icon(weather_conditions):
  function weather_status_icon (line 96) | def weather_status_icon (conditions, astronomy):
  function wind_dir_icon (line 107) | def wind_dir_icon (conditions, astronomy):

FILE: wunderground_historical.py
  function isFloat (line 21) | def isFloat(string):
  function daterange (line 30) | def daterange(start_date, end_date):
  function get_conditions (line 34) | def get_conditions(readDate):
Condensed preview — 12 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (78K chars).
[
  {
    "path": "ActualTemp.py",
    "chars": 1189,
    "preview": "#!/usr/bin/python\n\n# Copyright (c) 2014 Adafruit Industries\n# Author: Tony DiCola\n\nimport Adafruit_DHT\nfrom ISStreamer.S"
  },
  {
    "path": "CPUTemp.py",
    "chars": 10320,
    "preview": "import os\nimport urllib2\nimport json\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Strea"
  },
  {
    "path": "LICENSE",
    "chars": 1070,
    "preview": "MIT License\n\nCopyright (c) 2019 Initial State\n\nPermission is hereby granted, free of charge, to any person obtaining a c"
  },
  {
    "path": "README.md",
    "chars": 1046,
    "preview": "# Weather API (Dark Sky) + Pi Sense HAT\n![Dark Sky Dashboard](https://github.com/InitialState/darksky/wiki/img/darksky_d"
  },
  {
    "path": "darksky.py",
    "chars": 6283,
    "preview": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nfrom ISStreamer.Streamer import Streamer\n\n# --------- User "
  },
  {
    "path": "sensehat.py",
    "chars": 1404,
    "preview": "from sense_hat import SenseHat  \nimport time  \nimport sys  \nfrom ISStreamer.Streamer import Streamer  \n  \n# --------- Us"
  },
  {
    "path": "sensehat_darksky.py",
    "chars": 7734,
    "preview": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Strea"
  },
  {
    "path": "sensehat_darksky_calibrated.py",
    "chars": 8409,
    "preview": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Strea"
  },
  {
    "path": "sensehat_wunderground.py",
    "chars": 9973,
    "preview": "import os\nimport urllib2\nimport json\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Strea"
  },
  {
    "path": "sensehat_wunderground_calibrated.py",
    "chars": 10588,
    "preview": "import os\nimport urllib2\nimport json\nimport glob\nimport time\nimport RPi.GPIO as io\nfrom ISStreamer.Streamer import Strea"
  },
  {
    "path": "wunderground.py",
    "chars": 8475,
    "preview": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nfrom ISStreamer.Streamer import Streamer\n\n# --------- User "
  },
  {
    "path": "wunderground_historical.py",
    "chars": 4579,
    "preview": "import urllib2\nimport json\nimport os\nimport glob\nimport time\nfrom datetime import timedelta, date\nfrom ISStreamer.Stream"
  }
]

About this extraction

This page contains the full source code of the initialstate/wunderground-sensehat GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 12 files (69.4 KB), approximately 19.2k tokens, and a symbol index with 59 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!