0

Use 2 urls with PyPortal
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Use 2 urls with PyPortal

by kajmaya on Wed May 01, 2019 12:26 pm

Is it possible to use 2 or more url's with PyPortal? If so how?

My situation is that I get the lon/lat. (I'm do it with the IP here: http://api.ipstack.com) Then I use the returned lon/lat to get data from another URL. Can I do the same using PyPortal?

kajmaya
 
Posts: 3
Joined: Sat Oct 20, 2012 7:10 pm

Re: Use 2 urls with PyPortal

by franklin97355 on Wed May 01, 2019 12:54 pm

What is the code you are using now to get the data? You should be able to drop a connection and make a new one.

franklin97355
 
Posts: 20753
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Use 2 urls with PyPortal

by kajmaya on Wed May 01, 2019 1:15 pm

Here is the snippet:

Code: Select all | TOGGLE FULL SIZE
DATA_SOURCE = "http://api.ipstack.com/Local_IP_Here? \
        access_key=Key_Here"

pyportal = PyPortal(
    url=DATA_SOURCE,
    json_path=DATA_LOCATION,
    status_neopixel=board.NEOPIXEL,
    default_bg=0x000000,
)


and further down I'm using: pyportal.fetch(). Everything works. I just need to use a second URL.

Im intrigued, how do I drop the connection?

Thanks for your help

kajmaya
 
Posts: 3
Joined: Sat Oct 20, 2012 7:10 pm

Re: Use 2 urls with PyPortal

by brubell on Thu May 09, 2019 10:05 am

You might want to take a look at the CircuitPython_PyPortal library's url parameter:

https://github.com/adafruit/Adafruit_Ci ... al.py#L144

After the initial pyportal.fetch, you can change the URL passed in by changing the url (pyportal._url, via https://github.com/adafruit/Adafruit_Ci ... al.py#L167) and then calling fetch() again.

brubell
 
Posts: 430
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.