Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Proctor 8445b404bb Applying patch 2024-10-22 13:05:37 -04:00
Chris Proctor 938be1783b Add weather package 2024-10-21 10:45:08 -04:00
2 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,7 @@ version = "0.1.0"
description = ""
authors = ["Chris <chris@chrisproctor.net>"]
license = "MIT"
packages = [ { include = "weather"} ]
[tool.poetry.dependencies]
python = "^3.10"

View File

@ -13,8 +13,13 @@
# You will need to use these functions, but you don't need to edit this file.
import geocoder
from geocoder.osm import OsmQuery
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):
"""Translates a location string into latitude and longitude coordinates.
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')
{"lat": -74.010865, "lng": 40.7071407}
"""
result = geocoder.osm(location_string)
result = OsmQueryWithHeaders(location_string)
if result:
lat, lng = result.latlng
return {'lat': lat, 'lng': lng}