Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

(solved) python forecastio / darksky displaying current data

Fri Dec 07, 2018 2:57 pm

Afternoon all,

I am currently building an internet based weather staiton to display the current weather information i.e. temperature, humidity ect. using the Darksky api and python forsastio.

The problem is that I can print the current weather summary and current text that I can use to display an appropriate icon which is really cool! and i can even print a list of temperatures, rainfall, ozone levels ect for the last hour but after hours of searching the web I just cant find anything workable that displays just a few simple elements, in fact except for a few brief examples any information on forecatio is pretty hard to come by.

this is my code, any help will be gratefully received.

Code: Select all

[import forecastio
import time

def main():

    api_key = "-----------------------------"

    lat = 53.38 #lattidue

    lng = -1.22 #longditue

    forecast = forecastio.load_forecast(api_key,lat,lng) # send request?


    byHour = forecast.hourly() # store hourly data
    print
    print byHour.summary # print summary
    print byHour.icon    # print icon text

    for hourlyData in byHour.data:
        print hourlyData.temperature # prints a list of about 30 temperatures from the last hour

 



main()

/code]
Last edited by Dangermoth on Wed Dec 12, 2018 7:26 pm, edited 1 time in total.

User avatar
neilgl
Posts: 947
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: python forecastio / darksky displaying current data

Sat Dec 08, 2018 1:07 am

Are you using the free up to 1000 api calls per day version?
Anyway dark sky has many python (and other languages) examples (API) on their web site?

rhubarbdog
Posts: 64
Joined: Mon Dec 11, 2017 9:58 pm

Re: python forecastio / darksky displaying current data

Sat Dec 08, 2018 1:51 am

have you seen the BOSCH bme280 temperature/humidity/pressure detector.
The onlly thing that's lacking is wind speed
Search for it on GitHub https://github.com
or in the Interfacing forum on this site viewforum.php?f=44

Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

Re: python forecastio / darksky displaying current data

Sat Dec 08, 2018 12:05 pm

Yes this is the 1000 free api calls per day, I'm so glad other people know of the system.

This is my weather station, I'm pretty pleased with it especially as its my very first use of both a pi and python!
weather small.JPG
weather small.JPG (146.59 KiB) Viewed 682 times

My issue is that my company is moving premises soon to a building not dissimilar to an aircraft hanger so they wont be too thrilled about be shinning up the side of the building to fit the anemometer ect. Plus the fact that I have never had much success with humidity sensors outdoors, I tried a few DHT22's but these were dire, the temperature portion works a treat but the humidity only seems to work at room temperature, I've had better luck with HIH4000's but these only have a lifespan of a few months before they fail and indicate humidities of about 10% when its actually 95%.

I have looked around all the websites that show any sort of code examples for forecastio but they either don't work as there are vital bits missing or they just show something like an hourly summary, nothing seems to work with just a basic measurement, there seem to be many measurements available including this like ozone level which would be awesome to display.

I'm thinking I might have to abandon forecastio and write my own bit of code that sends the request directly and then decode the response, that way I might be able to use the dark sky examples, it looks fairly strait forward but my python programming isn't up to much yet.

I'm also trying to add other pages to my code so I can show graphs ect but I've put that question in the python section of the forum as I can't get any readings from the mouse to let me swap between program loops.

User avatar
neilgl
Posts: 947
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: python forecastio / darksky displaying current data

Mon Dec 10, 2018 12:00 pm

This basic measurement works for me, using currently instead of hourly

Code: Select all

...
forecast = forecastio.load_forecast(api_key, lat, lng)

current =forecast.currently()
print "summary ",current.summary
print "temperature ",current.temperature
print "windspeed ",current.windSpeed
print "ozone",current.ozone

Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

Re: (solved) python forecastio / darksky displaying current data

Wed Dec 12, 2018 10:24 am

neilgl that's perfect, works a treat thankyou so much :P

I tried all permutations of print but couldn't get anything to work, sometimes you can spend days fruitlessly trawling through the Internet trying to find something basic in fear of being flamed, then just give up and ask then have the answer in a few hours!

Return to “Beginners”