generated from mwc/lab_weather
Compare commits
2 Commits
ab5959075d
...
8445b404bb
Author | SHA1 | Date |
---|---|---|
|
8445b404bb | |
|
938be1783b |
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Chris <chris@chrisproctor.net>"]
|
authors = ["Chris <chris@chrisproctor.net>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
packages = [ { include = "weather"} ]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
|
|
|
@ -13,8 +13,13 @@
|
||||||
# You will need to use these functions, but you don't need to edit this file.
|
# You will need to use these functions, but you don't need to edit this file.
|
||||||
|
|
||||||
import geocoder
|
import geocoder
|
||||||
|
from geocoder.osm import OsmQuery
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
class OsmQueryWithHeaders(OsmQuery):
|
||||||
|
def _build_headers(self, provider_key, **kwargs):
|
||||||
|
return {"User-Agent": "Making With Code CS Curriculum"}
|
||||||
|
|
||||||
def geocode_location(location_string):
|
def geocode_location(location_string):
|
||||||
"""Translates a location string into latitude and longitude coordinates.
|
"""Translates a location string into latitude and longitude coordinates.
|
||||||
Uses the OpenStreetMap API. Returns a dict with keys 'lat' and 'lng'
|
Uses the OpenStreetMap API. Returns a dict with keys 'lat' and 'lng'
|
||||||
|
@ -23,7 +28,7 @@ def geocode_location(location_string):
|
||||||
>>> geocode_location('11 Wall Street, New York')
|
>>> geocode_location('11 Wall Street, New York')
|
||||||
{"lat": -74.010865, "lng": 40.7071407}
|
{"lat": -74.010865, "lng": 40.7071407}
|
||||||
"""
|
"""
|
||||||
result = geocoder.osm(location_string)
|
result = OsmQueryWithHeaders(location_string)
|
||||||
if result:
|
if result:
|
||||||
lat, lng = result.latlng
|
lat, lng = result.latlng
|
||||||
return {'lat': lat, 'lng': lng}
|
return {'lat': lat, 'lng': lng}
|
||||||
|
|
Loading…
Reference in New Issue