Skip to content

Commit

Permalink
Naming things
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jun 2, 2020
1 parent 40537f8 commit 9e6a4af
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -91,16 +91,16 @@ Usage as library
from dwdweather import DwdWeather
# Create client object.
dw = DwdWeather(resolution="hourly")
dwd = DwdWeather(resolution="hourly")
# Find closest station to position.
closest = dw.nearest_station(lon=7.0, lat=51.0)
closest = dwd.nearest_station(lon=7.0, lat=51.0)
# The hour you're interested in.
# The example is 2014-03-22 12:00 (UTC).
query_hour = datetime(2014, 3, 22, 12)
result = dw.query(station_id=closest["station_id"], timestamp=query_hour)
result = dwd.query(station_id=closest["station_id"], timestamp=query_hour)
print(result)
``DwdWeather.query()`` returns a dictionary with the full set of
Expand Down
16 changes: 8 additions & 8 deletions dwdweather/commands.py
Expand Up @@ -16,29 +16,29 @@

def run():
def get_station(args):
dw = DwdWeather(
dwd = DwdWeather(
resolution=args.resolution,
category_names=args.categories,
cache_path=args.cache_path,
reset_cache=args.reset_cache,
)
output = json.dumps(dw.nearest_station(lon=args.lon, lat=args.lat), indent=4)
output = json.dumps(dwd.nearest_station(lon=args.lon, lat=args.lat), indent=4)
print(output)

def get_stations(args):
dw = DwdWeather(
dwd = DwdWeather(
resolution=args.resolution,
category_names=args.categories,
cache_path=args.cache_path,
reset_cache=args.reset_cache,
)
output = ""
if args.type == "geojson":
output = dw.stations_geojson()
output = dwd.stations_geojson()
elif args.type == "csv":
output = dw.stations_csv()
output = dwd.stations_csv()
elif args.type == "plain":
output = dw.stations_csv(delimiter="\t")
output = dwd.stations_csv(delimiter="\t")
if args.output_path is None:
print(output)
else:
Expand All @@ -49,7 +49,7 @@ def get_stations(args):
def get_weather(args):

# Workhorse
dw = DwdWeather(
dwd = DwdWeather(
resolution=args.resolution,
category_names=args.categories,
cache_path=args.cache_path,
Expand All @@ -67,7 +67,7 @@ def get_weather(args):
**locals()
)
)
results = dw.query(station_id, timestamp)
results = dwd.query(station_id, timestamp)
print(json.dumps(results, indent=4, sort_keys=True))

argparser = argparse.ArgumentParser(
Expand Down
4 changes: 2 additions & 2 deletions dwdweather/core.py
Expand Up @@ -625,8 +625,8 @@ def nearest_station(self, lon, lat, surrounding=False):
--------
>>> from dwdweather import DwdWeather
>>> dw = DwdWeather(resolution="hourly")
>>> dw.nearest_station(lon=7.0, lat=51.0, surrounding=10000)
>>> dwd = DwdWeather(resolution="hourly")
>>> dwd.nearest_station(lon=7.0, lat=51.0, surrounding=10000)
"""

Expand Down
24 changes: 12 additions & 12 deletions tests/test_dwdweather.py
Expand Up @@ -7,21 +7,21 @@ def test_dwdclass_init_no_args():
"""
Test class can be initialized without arguments.
"""
dw = DwdWeather()
dwd = DwdWeather()


@pytest.mark.parametrize("resolution", ["hourly", "10_minutes"])
def test_dwdclass_init(resolution):
"""
Test class can be initialized with plausible resolutions.
"""
dw = DwdWeather(resolution=resolution)
dwd = DwdWeather(resolution=resolution)


def test_hourly_recent_base():
# hourly, 2020-06-01T08, Aachen
dw = DwdWeather(resolution='hourly')
result = dw.query(44, datetime(2020, 6, 1, 8))
dwd = DwdWeather(resolution='hourly')
result = dwd.query(44, datetime(2020, 6, 1, 8))
assert result['datetime'] == 2020060108
assert result['station_id'] == 44
assert result['air_temperature_200'] == 15.3
Expand All @@ -40,8 +40,8 @@ def test_hourly_recent_base():

def test_hourly_recent_more():
# hourly, 2020-06-01T08
dw = DwdWeather(resolution='hourly')
result = dw.query(96, datetime(2020, 6, 1, 8))
dwd = DwdWeather(resolution='hourly')
result = dwd.query(96, datetime(2020, 6, 1, 8))
assert result['datetime'] == 2020060108
assert result['station_id'] == 96
assert result['air_temperature_200'] == 18.4
Expand All @@ -64,8 +64,8 @@ def test_hourly_recent_more():

def test_hourly_recent_solar():
# hourly, 2020-05-19T08, Zugspitze
dw = DwdWeather(resolution='hourly')
result = dw.query(5792, datetime(2020, 5, 19, 8))
dwd = DwdWeather(resolution='hourly')
result = dwd.query(5792, datetime(2020, 5, 19, 8))
assert result['datetime'] == 2020051908
assert result['station_id'] == 5792
assert result['solar_dhi'] is None
Expand All @@ -77,8 +77,8 @@ def test_hourly_recent_solar():

def test_10_minutes_recent_base():
# 10 minutes, 2020-06-01T08:00, Aachen
dw = DwdWeather(resolution='10_minutes')
result = dw.query(44, datetime(2020, 6, 1, 8, 0))
dwd = DwdWeather(resolution='10_minutes')
result = dwd.query(44, datetime(2020, 6, 1, 8, 0))
assert result['datetime'] == 202006010800
assert result['station_id'] == 44
assert result['air_temperature_005'] == 21.2
Expand All @@ -90,8 +90,8 @@ def test_10_minutes_recent_base():

def test_10_minutes_recent_more():
# 10 minutes, 2020-06-01T08:00, Zugspitze
dw = DwdWeather(resolution='10_minutes')
result = dw.query(5792, datetime(2020, 6, 1, 8, 0))
dwd = DwdWeather(resolution='10_minutes')
result = dwd.query(5792, datetime(2020, 6, 1, 8, 0))
assert result['datetime'] == 202006010800
assert result['station_id'] == 5792
assert result['pressure_station'] == 713.3
Expand Down

0 comments on commit 9e6a4af

Please sign in to comment.