Operating system code test request...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Operating system code test request...

Post by FourthWorld » Mon May 24, 2021 9:18 pm

What does that url provide in a browser?

HTTP is HTTP...
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Mon May 24, 2021 9:28 pm

jacque wrote:
Mon May 24, 2021 9:13 pm
bogs wrote:
Mon May 24, 2021 9:05 pm
I suppose I *could* scrape that and find what I need, but I still don't see how that is better.
The info you want isn't in there. Instead it returns the front page of an actual web site at URL "http://infoIP.io".

I tried using "localhost" and variations but I'm still missing something. I'm pretty sure it's possible, I just can't find the right combination.
Yes, I'd agree, it may be possible, but I found my answer in 3 minutes of searching. I don't have decades of experience in this language to even guess what the right answer might be.
FourthWorld wrote:
Mon May 24, 2021 9:18 pm
What does that url provide in a browser?

HTTP is HTTP...
Yes, http is http, but I would suspect that the page is comprised of a lot of scripting as well which determines from YOUR browsers loading the page what *should* show up in a part of their webpage relevant to your ip's geolocation. I only need the lat. and lon. really, so even what I get back needed to be parsed out, but I think it would be a lot more work to find out where that is posted in an entire webpage of information, than to just get what I need from curl.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Operating system code test request...

Post by FourthWorld » Mon May 24, 2021 9:51 pm

That domain is configured in a way that alters its output based on specific header flags. Their documentation includes a discussion of authentication, suggesting to me (as someone who has only skimmed the page) and unauthenticated use may be a bug prone to closure.

But for now, apparently clearing the user-agent header element will invoke the JSON-format reply, and you can obtain that JSON even more easily by specifying that you want JSON in the the URL (see https://ipinfo.io/developers ):

Code: Select all

get url "http://ipinfo.io/json"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Operating system code test request...

Post by SparkOut » Mon May 24, 2021 10:02 pm

Or even more simply:

Code: Select all

get url ("http://api.infoip.io/")

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Mon May 24, 2021 10:20 pm

Well, those two certainly work here, thank you both for that. I wonder if that would solve working on Android and iOs (as Jacque asked).
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7235
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Operating system code test request...

Post by jacque » Mon May 24, 2021 10:27 pm

bogs wrote:
Mon May 24, 2021 10:20 pm
Well, those two certainly work here, thank you both for that. I wonder if that would solve working on Android and iOs (as Jacque asked).
It does. :) Then you could use JSONToArray to split it and retrieve the data you need.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Mon May 24, 2021 10:35 pm

Well, thats good to hear heh.
jacque wrote:
Mon May 24, 2021 10:27 pm
Then you could use JSONToArray to split it and retrieve the data you need.
Actually, since the return is line delimited already, I used lineOffset to pull the loc (which is all I needed) and stuff it into a cust. prop. where it gets pulled to be inserted into an address for the weather page.

Still, I don't think I would have figured out how to get that on my own, curl is much more natural to me. I would have probably ditched this in frustration long before 3 hours went by.
Image

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Operating system code test request...

Post by AxWald » Tue May 25, 2021 10:32 am

Hi,

looks like they use a geolocation API. This may give good location data on a mobile with calibrated GPS, but will usually give an awfully wrong location for a desktop machine.
It looks for GPS first. If there's none, it will try to find the loc based on charted WIFIs in the area. If this fails too (as it will on most desktop machines) it will return a location estimated by ISP ...

This isn't something you can rely on. Been there, tried that.

What could work, as long as you have address data:
Load "https://www.google.de/maps/place/" & [valid address search string] in a browser. In the source text, search for "https://www.google.de/maps/place/". After the first occurrence you should find your search string again, followed by correct location data.

This doesn't work with "put URL ..." or "put shell("curl ..."), though. But it may work with a revBrowser/ widget in LC, even a hidden one. Never tried such a beast (a browser that doesn't get security updates doesn't qualify as acceptable here).

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Tue May 25, 2021 10:56 am

AxWald wrote:
Tue May 25, 2021 10:32 am
Hi,

looks like they use a geolocation API. This may give good location data on a mobile with calibrated GPS, but will usually give an awfully wrong location for a desktop machine.
It looks for GPS first. If there's none, it will try to find the loc based on charted WIFIs in the area. If this fails too (as it will on most desktop machines) it will return a location estimated by ISP ...

This isn't something you can rely on.
Understood, but I guess that depends on how accurate your looking to be. This was one method I was thinking of and, if enough replies pile in, would give me some idea of how accurate it might be. I'd say if it is accurate within 50 miles, it is probably accurate enough for it's intended purpose. I'm not exactly turning out a military grade location program heh, just a stupid weather forecast app after seeing so many I've used go wierd. I'm pretty sure it is accurate enough for that.

Aside from that, as you probably know, I don't use any IDE new enough to have a widget in it, and revBrowser doesn't run on 'nix, so those 2 solutions are no so much for this.

Unfortunately so far, I've had exactly 2 responses that let me know how it's accuracy is, which while highly appreciated, doesn't exactly give me a wide range of information to base a decision on. I may instead wind up just asking for a zipcode from the user, but I'm not going to be getting address information beyond that.

While I am not making this for mobile per se, it will be freely available in it's final form for anyone that wants to use it for whatever. I am targeting desktops and laptops primarily for my own use at this point, the rest of this is just an exercise in making the program more general (I may have to use it in other locations, in other words).
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7235
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Operating system code test request...

Post by jacque » Tue May 25, 2021 5:17 pm

While I am not making this for mobile per se, it will be freely available in it's final form for anyone that wants to use it for whatever.
In that case, note that on Mac the JSON came in without line breaks, so lineOffset wouldn't work there. Alternately, you could replace LF with CR if the OS is Mac.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Tue May 25, 2021 5:32 pm

Now that *is* interesting to know, and it brings up something else I've always wondered. If you replace 'cr' with 'crlf' or 'return' , does that make it work universally across OS'es?

Alternately, I could just go from lineOffset to wordOffset heh.
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9385
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Operating system code test request...

Post by richmond62 » Tue May 25, 2021 7:17 pm

If you replace it with ROTFL is works everywhere, even when there is no computer.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Tue May 25, 2021 8:31 pm

<Chuckling>
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7235
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Operating system code test request...

Post by jacque » Tue May 25, 2021 9:29 pm

bogs wrote:
Tue May 25, 2021 5:32 pm
If you replace 'cr' with 'crlf' or 'return' , does that make it work universally across OS'es?
Return (in this usage) and CR are synonyms and will automatically use the native line endings for the OS. CRLF will only work on Windows. LF only works on 'nix (and Android.) If the data you're getting back contains CRLF then it would need to be replaced for OS X.

But In my test, the data came back as a single line with a carriage return at the end. That's why I split it into an array.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Operating system code test request...

Post by bogs » Tue May 25, 2021 11:05 pm

Thanks for clarifying that for me, I have to admit I didn't fully understand the dictionary entry on the subject.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”