Last active
July 2, 2020 15:15
-
-
Save chand1012/c3fad288cfe879b8356e8657f9c33d18 to your computer and use it in GitHub Desktop.
US government weather api response time test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
class USGovWeatherSearch(): | |
def __init__(self): | |
self.lat = 41.08 | |
self.lng = -81.51 | |
self.gridx = 0 | |
self.gridy = 0 | |
self.base_url = "https://api.weather.gov/" | |
self.json = None | |
self.url = self.base_url | |
self.forecast_url = None | |
self.forecasts = [] | |
def get_points(self): | |
self.url = self.base_url + f"/points/{self.lat},{self.lng}" | |
req = requests.get(self.url) | |
self.json = req.json() | |
self.gridx = self.json['properties']['gridX'] | |
self.gridy = self.json['properties']['gridY'] | |
self.forecast_url = self.json['properties']['forecast'] | |
def search(self, lat, lng): | |
self.lat = lat | |
self.lng = lng | |
self.get_points() | |
req = requests.get(self.forecast_url) | |
try: | |
self.json = req.json() | |
except Exception as e: | |
print(e) | |
print(req.content) | |
self.forecasts = self.json['properties']['periods'] | |
return self.forecasts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from weather import USGovWeatherSearch | |
import time | |
def millis(): | |
return int(round(time.time() * 1000)) | |
start = millis() | |
search = USGovWeatherSearch() | |
search.search(41.49, -81.69) | |
end = millis() | |
print(f"Time to execute: {end-start} ms") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment