text
stringlengths 0
828
|
---|
api_url = APIURL_TEMPLATE.format(longitude, latitude)
|
response = urlopen(api_url)
|
data = response.read().decode('utf-8')
|
json_data = json.loads(data)
|
return json_data"
|
384,"async def async_get_forecast_api(self, longitude: str,
|
latitude: str) -> {}:
|
""""""gets data from API asyncronious""""""
|
api_url = APIURL_TEMPLATE.format(longitude, latitude)
|
if self.session is None:
|
self.session = aiohttp.ClientSession()
|
async with self.session.get(api_url) as response:
|
if response.status != 200:
|
raise SmhiForecastException(
|
""Failed to access weather API with status code {}"".format(
|
response.status)
|
)
|
data = await response.text()
|
return json.loads(data)"
|
385,"def get_forecast(self) -> List[SmhiForecast]:
|
""""""
|
Returns a list of forecasts. The first in list are the current one
|
""""""
|
json_data = self._api.get_forecast_api(self._longitude, self._latitude)
|
return _get_forecast(json_data)"
|
386,"async def async_get_forecast(self) -> List[SmhiForecast]:
|
""""""
|
Returns a list of forecasts. The first in list are the current one
|
""""""
|
json_data = await self._api.async_get_forecast_api(self._longitude,
|
self._latitude)
|
return _get_forecast(json_data)"
|
387,"def _make_decorator(measuring_func):
|
""""""morass of closures for making decorators/descriptors""""""
|
def _decorator(name = None, metric = call_default):
|
def wrapper(func):
|
name_ = name if name is not None else func.__module__ + '.' +func.__name__
|
class instrument_decorator(object): # must be a class for descriptor magic to work
|
@wraps(func)
|
def __call__(self, *args, **kwargs):
|
return measuring_func(func(*args, **kwargs), name_, metric)
|
def __get__(self, instance, class_):
|
name_ = name if name is not None else\
|
""."".join((class_.__module__, class_.__name__, func.__name__))
|
@wraps(func)
|
def wrapped_method(*args, **kwargs):
|
return measuring_func(func(instance, *args, **kwargs), name_, metric)
|
return wrapped_method
|
return instrument_decorator()
|
return wrapper
|
return _decorator"
|
388,"def all(iterable = None, *, name = None, metric = call_default):
|
""""""Measure total time and item count for consuming an iterable
|
:arg iterable: any iterable
|
:arg function metric: f(name, count, total_time)
|
:arg str name: name for the metric
|
""""""
|
if iterable is None:
|
return _iter_decorator(name, metric)
|
else:
|
return _do_all(iterable, name, metric)"
|
389,"def each(iterable = None, *, name = None, metric = call_default):
|
""""""Measure time elapsed to produce each item of an iterable
|
:arg iterable: any iterable
|
:arg function metric: f(name, 1, time)
|
:arg str name: name for the metric
|
""""""
|
if iterable is None:
|
return _each_decorator(name, metric)
|
else:
|
return _do_each(iterable, name, metric)"
|
390,"def first(iterable = None, *, name = None, metric = call_default):
|
""""""Measure time elapsed to produce first item of an iterable
|
:arg iterable: any iterable
|
:arg function metric: f(name, 1, time)
|
:arg str name: name for the metric
|
""""""
|
if iterable is None:
|
return _first_decorator(name, metric)
|
else:
|
return _do_first(iterable, name, metric)"
|
391,"def _iterable_to_varargs_method(func):
|
""""""decorator to convert a method taking a iterable to a *args one""""""
|
def wrapped(self, *args, **kwargs):
|
return func(self, args, **kwargs)
|
return wrapped"
|
392,"def _varargs_to_iterable_method(func):
|
""""""decorator to convert a *args method to one taking a iterable""""""
|
def wrapped(self, iterable, **kwargs):
|
return func(self, *iterable, **kwargs)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.