4 ms·
I'm surprised no one has suggested using `requests` considering how easy, safe and readable it is: >>> import requests, pprint >>> >>> >>> ur
by e0a74c 5y ago
I'm surprised no one has suggested using `requests` considering how easy, safe and readable it is:
>>> import requests, pprint
>>>
>>>
>>> url = "https://en.wikipedia.org/w/api.php"
>>> resp = requests.get(
... url,
... params=dict(
... action="query",
... list="geosearch",
... format="json",
... gsradius=10000,
... gscoord=f"{latitude.value}|{longitude.value}"
... )
... )
>>>
>>> pprint.pprint(resp.json())
{'batchcomplete': '',
'query': {'geosearch': [{'dist': 26.2,
'lat': 37.7868194444444,
'lon': -122.399905555556,
'ns': 0,
...
- thamer 5y agoFor what it's worth, Copilot can do it. I typed the following prompt: def search_wikipedia(lat, lon): """ use "requests" to do a geosearch on Wikipedia and pretty-print the resulting JSON """ And it completed it with: r = requests.get('https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gsradius=10000&gscoord={0}|{1}&gslimit=20&format=json'.format(lat, lon)) pprint.pprint(r.json())
- odonnellryan 5y agoThat doesn't exactly do what the guy above you was talking about, though.
- esjeon 5y agoIt's like a junior dev who doesn't quit unnecessary code golfing. Somehow the AI is more comfortable with string-based URL manipulation, which is a straight anti-pattern.
- disgruntledphd2 5y agoPresumably because that's what it's seen in the training data. Remember, it doesn't care about what the code does, it's just doing a search for similar looking code.
- grenoire 5y agoThat's what the rest of the thread is complaining about, it's still slapping the strings in there with basic formatting. No different than the top level approach.