Skip to content

Commit 2666df9

Browse files
SiddharthKhatsuriyasiddharth-khatsuriyaclampr
authored
Added missing German stations (#483)
* chore: added missing german stations * Update import script, stations * Formatting, Linting * Update linter * Remove legacy updates * Update JSON files * Fix linting error --------- Co-authored-by: siddharth khatsuriya <[email protected]> Co-authored-by: clampr <[email protected]>
1 parent fc35db7 commit 2666df9

File tree

358 files changed

+14896
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

358 files changed

+14896
-32
lines changed

.github/workflows/linter.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ jobs:
5555
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5656
LINTER_RULES_PATH: /
5757
PYTHON_PYLINT_CONFIG_FILE: .pylintrc
58+
VALIDATE_PYTHON_BLACK: false
5859
VALIDATE_PYTHON_FLAKE8: false
5960
VALIDATE_PYTHON_ISORT: false
6061
VALIDATE_PYTHON_MYPY: false
61-
VALIDATE_JAVASCRIPT_STANDARD: false
62+
VALIDATE_JSCPD: false

.pylintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[MESSAGES CONTROL]
22

3-
disable=print-statement,
4-
no-name-in-module,
3+
disable=no-name-in-module,
54
unused-variable,
65
import-error,
76
too-many-return-statements,

lib/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"""
77

88
import os
9+
from .mutations import create, update, delete, apply
10+
from .checks import find_duplicate
11+
from .generators import generate_uid
12+
from .utils import create_station_dict, merge_dicts, get_distance
913

1014
__appname__ = "stations"
1115
__version__ = "0.0.4"
@@ -20,8 +24,3 @@
2024
+ os.sep
2125
+ "stations"
2226
)
23-
24-
from .utils import create_station_dict, merge_dicts, get_distance
25-
from .generators import generate_uid
26-
from .checks import find_duplicate
27-
from .mutations import create, update, delete, apply

lib/mutations.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create(data: dict) -> None:
2222
data = create_station_dict(data)
2323

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

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

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

4242
# Deep merge
4343
merge_dicts(data, state)
4444

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

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

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

7070
# Apply your logic
7171
data = function(data, file)
7272

7373
# Persist changes
7474
if data:
75-
with open(file, "w") as f:
76-
f.write(json.dumps(data, indent=4, default=str, ensure_ascii=False))
75+
with open(file, "w", encoding="utf-8") as f:
76+
f.write(
77+
json.dumps(
78+
data,
79+
indent=4,
80+
default=str,
81+
ensure_ascii=False))
7782
f.close()
7883

7984
# List of files

lib/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def get_distance(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
6666
dlon = lon2 - lon1
6767

6868
# Calculate distance
69-
arch = np.sin(dlat / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2
69+
arch = np.sin(dlat / 2) ** 2 + np.cos(lat1) * \
70+
np.cos(lat2) * np.sin(dlon / 2) ** 2
7071
arch_sin = 2 * np.arcsin(np.sqrt(arch))
7172

7273
return radius * arch_sin

scripts/australia/import.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

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

4747
for station in inventory[248:]:
@@ -55,14 +55,13 @@
5555
with request.urlopen(req) as raw:
5656
meta = json.loads(raw.read().decode())["observations"]["data"][0]
5757
# Get elevation
58-
elevation = json.loads(
59-
request.urlopen(
60-
"https://api.open-elevation.com/api/v1/lookup?"
61-
+ f'locations={meta["lat"]},{meta["lon"]}'
62-
)
63-
.read()
64-
.decode("utf-8")
65-
)["results"][0]["elevation"]
58+
with request.urlopen(
59+
"https://api.open-elevation.com/api/v1/lookup?" +
60+
f'locations={meta["lat"]},{meta["lon"]}'
61+
) as raw:
62+
elevation = json.loads(
63+
raw.read().decode("utf-8")
64+
)["results"][0]["elevation"]
6665
# Collect meta data
6766
data = {
6867
"name": {"en": meta["name"]},

scripts/canada/import.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def province_code(name: str) -> str:
8484
# Process all stations
8585
for index, row in inventory.iterrows():
8686

87-
if not pd.isna(row["last_year"]) and int(row["last_year"]) >= MIN_LAST_YEAR:
87+
if not pd.isna(row["last_year"]) and int(
88+
row["last_year"]) >= MIN_LAST_YEAR:
8889

8990
# Collect meta data
9091
data = {

0 commit comments

Comments
 (0)