Forum Użytkowników Stacji Pogodowych

Stacje Pogody - oprogramowanie => Inne oprogramowanie => Wątek zaczęty przez: 1979 w 16 Styczeń, 2017, 08:19:03

Tytuł: API - Open Weather Map i CUMULUS
Wiadomość wysłana przez: 1979 w 16 Styczeń, 2017, 08:19:03
Czy ktoś z szanownego grona forumowego raportuje do nich przez Cumulusa?  ::)

http://openweathermap.org

Tytuł: Odp: API - Open Weather Map i CUMULUS
Wiadomość wysłana przez: 1979 w 17 Styczeń, 2017, 11:14:33
Dobra, jakby co to cumulusem tego nie zrobię, znalazłem info, że można to zrobić w pytonie

#!/usr/bin/python
import MySQLdb
import subprocess
# To read databases and submit info to OpenWeatherMap
# Should be run via crontab every 15 mins (suggested)
# some constants

mphtms = 0.447       # convert mph to m/s

db1 = MySQLdb.connect(host="localhost", user="xxx", passwd="yyy", db="ws3083")
db2 = MySQLdb.connect(host="localhost", user="mmm", passwd="nnn", db="weather")

# create Cursor objects.
cur1 = db1.cursor()
cur2 = db2.cursor()

# Use all the SQL you like
cur1.execute("SELECT Windspeed, Windbearing, UVindex, SolarRad FROM Monthly ORDER BY LogDateTime DESC LIMIT 1")
cur2.execute("SELECT LogDateTime, Temp, Humidity, TodayRainSoFar, Pressure FROM Monthly ORDER BY LogDateTime DESC LIMIT 1")

# process result - should only be one record - the last record entered
for row in cur1.fetchall():
    ws = row
for row in cur2.fetchall():
    dv = row
db1.close()
db2.close()

# now generate the command to send

endstr = " --user 'user:password' -H 'x-api-key:apikey'  http://openweathermap.org/data/post"
posstr = "&lat=nn.nn&long=-nn.nn&alt=mmm&name=MyStation" + "'"
val1 = "'"+"temp="+str(dv[1])+"&wind_speed="+str("%1.1f"%(float(ws[0])*mphtms))+"&wind_dir="+str(ws[1])+"&pressure="+str(dv[4])
val2 = "&rain_today="+str(dv[3])+"&uv="+str(ws[2])+"&radiation="+str(ws[3])
cmd = "curl -d "+val1+val2+posstr+endstr
#print cmd
subprocess.call(cmd, shell=True)

Może komuś się przyda, tu są szczegóły:
http://sandaysoft.com/forum/viewtopic.php?f=27&t=15311&p=117691&hilit=OpenWeatherMap#p117667