Skip to content

Commit

Permalink
test for code-bump 0.1.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenithClown committed Oct 18, 2021
1 parent 7177e3a commit 277d83c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
21 changes: 20 additions & 1 deletion VisualCrossing/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,23 @@ def __init__(self, **kwargs):
# use defaults
response = self.__args_default__()

self.__set_attr__(response, **kwargs)


def set_config(self, file : str, **kwargs):
_, response = config(file)
self.__set_attr__(response, **kwargs)


def __set_attr__(self, response : dict, **kwargs):
for k, v in response.items():
setattr(self, k, v)
# set all attribute as class attribute
# to override any attribute just send the specific
# attribute, and the same is given priority over configuration file
if k in self.__optional_args__ and k not in kwargs.keys():
setattr(self, k, v)
else:
setattr(self, k, kwargs[k] or v)


def __args_default__(self) -> dict:
Expand Down Expand Up @@ -167,3 +182,7 @@ def write_json(kv : dict, file : str):
write_json(attrs, outfile) # write to file

return True


def get_key_from_config(self):
pass
4 changes: 4 additions & 0 deletions VisualCrossing/_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- encoding: utf-8 -*-

from json import load
from os.path import join
from pathlib import Path

from . import __homepath__

# set configuration option
def config(file : str = None) -> dict:
Expand Down
35 changes: 25 additions & 10 deletions VisualCrossing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,30 @@
from .errors import * # noqa: F403

class API(base):
"""A basic API for Visual-Crossing Weather Data
"""A python wrapper to fetch weather data from VisualCrossing
The function is devised keeping in mind - minimal coding approach, and recurrent job-scheduling
for any person. All the keyword arguments that the API accepts are same as that available
in the Visual Crossing API Documentation (check README for more information). The API is configured
with default values, which is easier to understand and retreive. However, the data requires certain
required arguments defined below. The same can also be obtained from `config.json` file, but is not
recomended.
:param date: Date for which weather data is required. Pass the date in `YYYY-MM-DD` format,
or pass `FORCAST` to get the forecasted data for a particular date.
:param APIKey: All VisualCrossing API calls are made with an API key associated with your billing/free
account. Get yourself a new Key, if you do not have one. It is advised that the key
is not written to a configuration file, and suitable `environment variables` should
be called/defined. However, there is a dedicated function :func:`get_key_from_config`
which can be used to get `APIKey` from configuration file, which should be defined
under `__api_key__`. The key can also be written into file either passing `key` or
`__api_key__` as a keyword argument to :func:`generate_config`. # TODO
:param location: Location of which the weather is required. Defaults to either a place name (like `india`),
or, you can directly pass the coordinates of the particular place as (like `(long, lat)`),
or, you can also pass a list/set of locations (either name or coordinates.) # TODO
:Keyword Arguments:
* *endDate* (``str``) -- When end date is defined, the api fetches data for a given date
range which starts from :param:`date` to `endDate`, else only singe day data is fetched.
Expand All @@ -34,24 +53,20 @@ class API(base):
def __init__(
self,
date : str,
# APIKey : str,
location : str or tuple,
APIKey : str,
location : str or tuple or list or dict,
**kwargs
):
# get values from base class
super().__init__()
super().__init__(**kwargs)

# default constructor values
self.date = date
# self.APIKey = APIKey
self.APIKey = APIKey
self._location = location

# define keyword arguments
self.endDate = kwargs.get("endDate", None)
# self.unitGroup = kwargs.get("unitGroup", "metric")
self.contentType = kwargs.get("contentType", "csv")
self.aggregateHours = kwargs.get("aggregateHours", 24)


# self.checkParams() # check all parameters

Expand Down Expand Up @@ -85,7 +100,7 @@ def BaseURL(self) -> str:
return "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/weatherdata/" + \
self.queryType() + \
"&location=" + urllib.parse.quote(self._location) + \
"&key=" + self.key + \
"&key=" + self.APIKey + \
f"&contentType={self.contentType}"


Expand Down
2 changes: 1 addition & 1 deletion VisualCrossing/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- encoding: utf-8 -*-

__version__ = "0.0.2-alpha"
__version__ = "0.1.0-beta"

0 comments on commit 277d83c

Please sign in to comment.