
#!/usr/local/bin/python3
#
#Change first line above to the correct directory for your system
#You can use the "$which python3" commmand to find out
 
from pyowm.owm import OWM
from pyowm.utils import timestamps
 
#Change this to the place of interest in quotes
#Look up specific city callouts here:  
#https://openweathermap.org/find?q=
 
location_identifier = 'Tigard,US'
 
#Put your auth key from openweathermap.org below in quotes
 
auth_key = 'Your_Auth_Key'
 
# Device ID, Create a unique device name so JEDI One can uniquely tag the data
 
devID = "OWMdata"
 
#Conversion factor hPa to inHg (commonly used in USA)
c_factor=0.029529983071445
 
owm = OWM(auth_key)
 
mgr = owm.weather_manager()
 
observation = mgr.weather_at_place(location_identifier)
 
weather = observation.weather
 
# Device ID, Create a unique device name so JEDI One knows the source of the data
 
devID = "OWMdata"
 
 
tempF = weather.temperature('fahrenheit')
humi = weather.humidity
pres = weather.pressure
wind_info = weather.wind(unit='miles_hour')
time_stamp = timestamps.now('iso')
pres_inHg = (float(pres['press'])) * c_factor
 
#Debug print statements
#print(time_stamp)
#print('%0.1f' % float(tempF['temp']))
#print('%0.1f' % float(humi))
#print(pres)
#print('%0.2f' % pres_inHg)
#print(float(wind_info['speed']))
#print(float(wind_info['deg']))
 
#Tag data for JEDI one consumption
print("metric:id=%s,n=Temperature,vd=%0.1f,u=F,ts=%s" % (devID, float(tempF['temp']),time_stamp))
print("metric:id=%s,n=Humidity,vd=%0.1f,u=%%,ts=%s" % (devID, float(humi),time_stamp))
print("metric:id=%s,n=Pressure,vd=%0.2f,u=inHg,ts=%s" % (devID, float(pres_inHg),time_stamp))
print("metric:id=%s,n=Wind_Speed,vd=%0.1f,u=mph,ts=%s" % (devID, float(wind_info['speed']),time_stamp))
print("metric:id=%s,n=Wind_Dir,vd=%0.1f,u=deg,ts=%s" % (devID, float(wind_info['deg']),time_stamp))