Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added missing german stations #483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: /
PYTHON_PYLINT_CONFIG_FILE: .pylintrc
VALIDATE_PYTHON_BLACK: false
VALIDATE_PYTHON_FLAKE8: false
VALIDATE_PYTHON_ISORT: false
VALIDATE_PYTHON_MYPY: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_JSCPD: false
3 changes: 1 addition & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[MESSAGES CONTROL]

disable=print-statement,
no-name-in-module,
disable=no-name-in-module,
unused-variable,
import-error,
too-many-return-statements,
Expand Down
9 changes: 4 additions & 5 deletions lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"""

import os
from .mutations import create, update, delete, apply
from .checks import find_duplicate
from .generators import generate_uid
from .utils import create_station_dict, merge_dicts, get_distance

__appname__ = "stations"
__version__ = "0.0.4"
Expand All @@ -20,8 +24,3 @@
+ os.sep
+ "stations"
)

from .utils import create_station_dict, merge_dicts, get_distance
from .generators import generate_uid
from .checks import find_duplicate
from .mutations import create, update, delete, apply
17 changes: 11 additions & 6 deletions lib/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create(data: dict) -> None:
data = create_station_dict(data)

# Write into file
with open(file, "w") as f:
with open(file, "w", encoding="utf-8") as f:
f.write(json.dumps(data, indent=4, default=str, ensure_ascii=False))
f.close()

Expand All @@ -36,14 +36,14 @@ def update(data: dict) -> None:
file = stations_path + os.sep + data["id"] + ".json"

# Read file and parse JSON
with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
state: dict = json.load(f)

# Deep merge
merge_dicts(data, state)

# Write into file
with open(file, "w") as f:
with open(file, "w", encoding="utf-8") as f:
f.write(json.dumps(state, indent=4, default=str, ensure_ascii=False))
f.close()

Expand All @@ -64,16 +64,21 @@ def apply(function, threads=12) -> None:

def _update(file: str) -> None:
# Read file and parse JSON
with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
data: dict = json.load(f)

# Apply your logic
data = function(data, file)

# Persist changes
if data:
with open(file, "w") as f:
f.write(json.dumps(data, indent=4, default=str, ensure_ascii=False))
with open(file, "w", encoding="utf-8") as f:
f.write(
json.dumps(
data,
indent=4,
default=str,
ensure_ascii=False))
f.close()

# List of files
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def get_distance(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
dlon = lon2 - lon1

# Calculate distance
arch = np.sin(dlat / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2
arch = np.sin(dlat / 2) ** 2 + np.cos(lat1) * \
np.cos(lat2) * np.sin(dlon / 2) ** 2
arch_sin = 2 * np.arcsin(np.sqrt(arch))

return radius * arch_sin
17 changes: 8 additions & 9 deletions scripts/australia/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# returns JSON object as
# a dictionary
with open(JSON_FILE) as file:
with open(JSON_FILE, encoding="utf-8") as file:
inventory = json.load(file)

for station in inventory[248:]:
Expand All @@ -55,14 +55,13 @@
with request.urlopen(req) as raw:
meta = json.loads(raw.read().decode())["observations"]["data"][0]
# Get elevation
elevation = json.loads(
request.urlopen(
"https://api.open-elevation.com/api/v1/lookup?"
+ f'locations={meta["lat"]},{meta["lon"]}'
)
.read()
.decode("utf-8")
)["results"][0]["elevation"]
with request.urlopen(
"https://api.open-elevation.com/api/v1/lookup?" +
f'locations={meta["lat"]},{meta["lon"]}'
) as raw:
elevation = json.loads(
raw.read().decode("utf-8")
)["results"][0]["elevation"]
# Collect meta data
data = {
"name": {"en": meta["name"]},
Expand Down
3 changes: 2 additions & 1 deletion scripts/canada/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def province_code(name: str) -> str:
# Process all stations
for index, row in inventory.iterrows():

if not pd.isna(row["last_year"]) and int(row["last_year"]) >= MIN_LAST_YEAR:
if not pd.isna(row["last_year"]) and int(
row["last_year"]) >= MIN_LAST_YEAR:

# Collect meta data
data = {
Expand Down
Loading