Posts: 11
Threads: 1
Joined: May 2017
May-07-2017, 01:48 PM
(This post was last modified: May-07-2017, 04:30 PM by buran.)
I am working on having an led sign I bought scroll through weather data. I can get the sign to say information, but I cant get it to read out weather data, it will only read the literal words when I input them in data= '' for example I want it to read 48 degrees, party cloudy, but it will just ready the call literally, forecast.currently or whatever I put in.
any help is greatly appreciated!
import datetime
import forecastio
def main():
"""
Run load_forecast() with the given lat, lng, and time arguments.
"""
api_key = "My actual key is here, I just took it out for sample"
lat = -31.967819
lng = 115.87718
time = datetime.datetime(2017, 06, 05, 6, 0, 0)
forecast = forecastio.load_forecast(api_key, lat, lng, time=time)
print "===========Currently Data========="
print forecast.currently()
print "===========Hourly Data========="
by_hour = forecast.hourly()
print "Hourly Summary: %s" % (by_hour.summary)
for hourly_data_point in by_hour.data:
print hourly_data_point
print "===========Daily Data========="
by_day = forecast.daily()
print "Daily Summary: %s" % (by_day.summary)
for daily_data_point in by_day.data:
print daily_data_point
if __name__ == "__main__":
main()
from pyledsign.minisign import MiniSign
mysign = MiniSign(devicetype='sign')
# queuemsg queues a message to be sent with the send method
mysign.queuemsg(data= 'forecast.currently doesnt seem to work, Weather text is supposed to be called here')
mysign.sendqueue(device='/dev/ttyUSB0')
Posts: 12,031
Threads: 485
Joined: Sep 2016
need More information
what is the make and model of LED sign
what is the interface?
have you printed out the data that you want to send to the sign to make content and format is correct
Please provide all pertinent information
Posts: 8,160
Threads: 160
Joined: Sep 2016
May-07-2017, 04:39 PM
(This post was last modified: May-07-2017, 04:40 PM by buran.)
it looks like you try to use script written by someone else and add the functionality you need. As it is all the forecast data are not accessible outside main() function. Also, your description, that it reads literally 'forecast.currently', suggest that you pass just that sting. so, not able to test, but would suggest something like this
#!/usr/bin/python
import datetime
import forecastio
from pyledsign.minisign import MiniSign
def main():
"""
Run load_forecast() with the given lat, lng, and time arguments.
"""
api_key = "My actual key is here, I just took it out for sample"
lat = -31.967819
lng = 115.87718
time = datetime.datetime(2017, 06, 05, 6, 0, 0)
forecast = forecastio.load_forecast(api_key, lat, lng, time=time)
mysign = MiniSign(devicetype='sign')
print "===========Currently Data========="
current_forecast = forecast.currently()
print current_forecast
# queuemsg queues a message to be sent with the send method
mysign.queuemsg(data=current_forecast)
mysign.sendqueue(device='/dev/ttyUSB0')
print "===========Hourly Data========="
by_hour = forecast.hourly()
print "Hourly Summary: %s" % (by_hour.summary)
for hourly_data_point in by_hour.data:
print hourly_data_point
print "===========Daily Data========="
by_day = forecast.daily()
print "Daily Summary: %s" % (by_day.summary)
for daily_data_point in by_day.data:
print daily_data_point
if __name__ == "__main__":
main() this assumes that forecast.currently() actually returns string, that can be passed to your device to read it.
Posts: 11
Threads: 1
Joined: May 2017
(May-07-2017, 04:14 PM)Larz60+ Wrote: need More information
what is the make and model of LED sign
what is the interface?
have you printed out the data that you want to send to the sign to make content and format is correct
Please provide all pertinent information
Thanks for the reply! it wouldnt let me include links
here is the link to the sign
https://brightledsigns.com/programmable/...-4x16-mini
here is the code for the sign
https://github.com/BrightLedSigns/pyleds...inisign.md
and for the weather
https://github.com/zeevg/python-forecast.io
Posts: 11
Threads: 1
Joined: May 2017
May-07-2017, 08:30 PM
(This post was last modified: May-07-2017, 08:32 PM by buran.)
(May-07-2017, 04:39 PM)buran Wrote: it looks like you try to use script written by someone else and add the functionality you need. As it is all the forecast data are not accessible outside main() function. Also, your description, that it reads literally 'forecast.currently', suggest that you pass just that sting. so, not able to test, but would suggest something like this
#!/usr/bin/python
import datetime
import forecastio
from pyledsign.minisign import MiniSign
def main():
"""
Run load_forecast() with the given lat, lng, and time arguments.
"""
api_key = "My actual key is here, I just took it out for sample"
lat = -31.967819
lng = 115.87718
time = datetime.datetime(2017, 06, 05, 6, 0, 0)
forecast = forecastio.load_forecast(api_key, lat, lng, time=time)
mysign = MiniSign(devicetype='sign')
print "===========Currently Data========="
current_forecast = forecast.currently()
print current_forecast
# queuemsg queues a message to be sent with the send method
mysign.queuemsg(data=current_forecast)
mysign.sendqueue(device='/dev/ttyUSB0')
print "===========Hourly Data========="
by_hour = forecast.hourly()
print "Hourly Summary: %s" % (by_hour.summary)
for hourly_data_point in by_hour.data:
print hourly_data_point
print "===========Daily Data========="
by_day = forecast.daily()
print "Daily Summary: %s" % (by_day.summary)
for daily_data_point in by_day.data:
print daily_data_point
if __name__ == "__main__":
main() this assumes that forecast.currently() actually returns string, that can be passed to your device to read it.
thanks! I've never written code for python until yesterday, just trying to figure out how to get the weather information working but could not find many sources on it besides the links I've put in the post above this one. That's why it's copied and pasted, I wouldn't know how to write my own.
Posts: 8,160
Threads: 160
Joined: Sep 2016
So, does it work? I saw that actually the second part (not main()) is from the examples for the pyledsign
Posts: 11
Threads: 1
Joined: May 2017
May-08-2017, 12:35 AM
(This post was last modified: May-08-2017, 05:49 AM by buran.)
(May-07-2017, 08:33 PM)buran Wrote: So, does it work? I saw that actually the second part (not main()) is from the examples for the pyledsign
I get importerror: no module named plyedsign.minisign when running in terminal
(May-07-2017, 08:33 PM)buran Wrote: So, does it work? I saw that actually the second part (not main()) is from the examples for the pyledsign
whoops realised pyledsign was spelt wrong on my part, but still it shows this in terminal -
===========Currently Data=========
Error: <ForecastioDataPoint instance: Partly Cloudy at 2017-06-04 22:00:00>
Traceback (most recent call last):
File "mysign.py", line 45, in <module>
main()
File "mysign.py", line 26, in main
mysign.sendqueue(device='/dev/ttyUSB0')
File "/usr/local/lib/python2.7/dist-packages/pyledsign/minisign.py", line 118, in sendqueue
msgobj.data=this.processtags(msgobj.data)
File "/usr/local/lib/python2.7/dist-packages/pyledsign/minisign.py", line 273, in processtags
data=data.replace('<f:normal>',normal)
File "/usr/local/lib/python2.7/dist-packages/forecastio/models.py", line 107, in __getattr__
" or is not available for this forecast".format(name)
forecastio.utils.PropertyUnavailable: Property 'replace' is not valid or is not available for this forecast
Posts: 8,160
Threads: 160
Joined: Sep 2016
As I said it assumes that forecast.currently() actually returns string, that can be passed to your device to read it. This was not the case - it returns ForecastioDataPoint object. So you need to access its properties to get what you want - str.
import datetime
import forecastio
from pyledsign.minisign import MiniSign
def main():
"""
Run load_forecast() with the given lat, lng, and time arguments.
"""
api_key = 'YOUR API KEY'
lat = -31.967819
lng = 115.87718
time = datetime.datetime(2017, 06, 05, 6, 0, 0)
forecast = forecastio.load_forecast(api_key, lat, lng, time=time)
mysign = MiniSign(devicetype='sign')
print "===========Currently Data========="
current_weather = forecast.currently()
print current_weather.summary
print current_weather.temperature
mysign.queuemsg(data=current_weather.summary)
mysign.queuemsg(data='Temperature: {}'.format(current_weather.temperature))
by_hour = forecast.hourly()
print 'Hourly Summary: {}'.format(by_hour.summary)
mysign.queuemsg(data='Hourly Summary: {}'.format(by_hour.summary))
mysign.sendqueue(device='/dev/ttyUSB0')
if __name__ == "__main__":
main() I keep this to minimum - i.e. only current weather and hourly forecast summary. Note that minutely(), hourly(), daily() return ForecastioDataBlock object. Anyway you need to read forecastio docs to develop further (I assume that's what you want at the end)
Posts: 11
Threads: 1
Joined: May 2017
(May-08-2017, 07:07 AM)buran Wrote: As I said it assumes that forecast.currently() actually returns string, that can be passed to your device to read it. This was not the case - it returns ForecastioDataPoint object. So you need to access its properties to get what you want - str.
import datetime
import forecastio
from pyledsign.minisign import MiniSign
def main():
"""
Run load_forecast() with the given lat, lng, and time arguments.
"""
api_key = 'YOUR API KEY'
lat = -31.967819
lng = 115.87718
time = datetime.datetime(2017, 06, 05, 6, 0, 0)
forecast = forecastio.load_forecast(api_key, lat, lng, time=time)
mysign = MiniSign(devicetype='sign')
print "===========Currently Data========="
current_weather = forecast.currently()
print current_weather.summary
print current_weather.temperature
mysign.queuemsg(data=current_weather.summary)
mysign.queuemsg(data='Temperature: {}'.format(current_weather.temperature))
by_hour = forecast.hourly()
print 'Hourly Summary: {}'.format(by_hour.summary)
mysign.queuemsg(data='Hourly Summary: {}'.format(by_hour.summary))
mysign.sendqueue(device='/dev/ttyUSB0')
if __name__ == "__main__":
main() I keep this to minimum - i.e. only current weather and hourly forecast summary. Note that minutely(), hourly(), daily() return ForecastioDataBlock object. Anyway you need to read forecastio docs to develop further (I assume that's what you want at the end) Thanks! I got the data to read onto the sign using str, so a small step forward, but for some reason it will read <forecastioDataPoint instance: Clear skies , rather than just reading the clear skies part, any clue why the str is pulling that information?
I am using the
# queue up a text message
mysign.queuemesg(
data= str(forecast.currently())
)
Posts: 8,160
Threads: 160
Joined: Sep 2016
May-16-2017, 07:35 PM
(This post was last modified: May-16-2017, 07:35 PM by buran.)
well, in this case you should not use str(). That's not what you want.
From the docs:
Quote:str() Return a string version of object. If object is not provided, returns the empty string. Otherwise, the behavior of str() depends on whether encoding or errors is given, as follows.
If neither encoding nor errors is given, str(object) returns object.__str__(), which is the “informal” or nicely printable string representation of object. For string objects, this is the string itself. If object does not have a __str__() method, then str() falls back to returning repr(object). If neither encoding nor errors is given, str(object) returns object.__str__(), which is the “informal” or nicely printable string representation of object. For string objects, this is the string itself. If object does not have a __str__() method, then str() falls back to returning repr(object).
see this example
class Foo(): # class with __str__() method not implemented
pass
class Bar(): # class with __str__() method implemented
pass
def __str__(self):
return 'This is nice representation of Bar instance'
if __name__ == '__main__':
foo = Foo()
bar = Bar()
print(foo)
print (str(foo))
print (repr(foo))
print(bar)
print(str(bar))
print(repr(bar)) Output: <__main__.Foo object at 0x7fea281004e0>
<__main__.Foo object at 0x7fea281004e0>
<__main__.Foo object at 0x7fea281004e0>
This is nice representation of Bar instance
This is nice representation of Bar instance
<__main__.Bar object at 0x7fea28100518>
hope you see the difference
Back to your particular issue... In my code I showed that you need to use summary property of the ForecastioDataPoint object. Strongly encourage you to read the docs of the forecastio package
|