-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: data request from api is now included in the main script
- Loading branch information
1 parent
0f5c7c9
commit 11422d1
Showing
4 changed files
with
52 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import requests | ||
|
||
url = f"https://boundaries-api.io/api/denmark/geometry/find/level/" | ||
params = { | ||
"level": 2 | ||
} | ||
response = requests.get(url, params=params) | ||
def get_municipalities(): | ||
url = f"https://boundaries-api.io/api/denmark/geometry/find/level/" | ||
params = { | ||
"level": 2 | ||
} | ||
response = requests.get(url, params=params) | ||
|
||
print(response.status_code) | ||
print(response.reason) | ||
print("Writing data..") | ||
with open("municipalities_by_id.json", "w") as f: | ||
f.write(response.text) | ||
print(response.status_code) | ||
print(response.reason) | ||
print("Writing data..") | ||
with open("municipalities_by_id.json", "w") as f: | ||
f.write(response.text) | ||
|
||
if __name__ == "__main__": | ||
get_municipalities() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import json | ||
import requests | ||
|
||
json_file = "municipalities_by_id.json" | ||
with open(json_file, "r", encoding="utf-8") as f: | ||
my_dict = json.loads("".join(f.readlines())) | ||
def get_municipality_name(): | ||
json_file = "municipalities_by_id.json" | ||
with open(json_file, "r", encoding="utf-8") as f: | ||
my_dict = json.loads("".join(f.readlines())) | ||
|
||
ids = "" | ||
ids = "" | ||
|
||
for municipality in my_dict["geometries"]["features"]: | ||
ids += municipality["properties"]["id"] + "," | ||
for municipality in my_dict["geometries"]["features"]: | ||
ids += municipality["properties"]["id"] + "," | ||
|
||
ids = ids[:-1] | ||
print(ids) | ||
ids = ids[:-1] | ||
print(ids) | ||
|
||
url = f"https://boundaries-api.io/api/denmark/attributes/find/id/" | ||
params = { | ||
"id": ids | ||
} | ||
url = f"https://boundaries-api.io/api/denmark/attributes/find/id/" | ||
params = { | ||
"id": ids | ||
} | ||
|
||
response = requests.get(url, params=params) | ||
response = requests.get(url, params=params) | ||
|
||
print(response.status_code) | ||
print(response.reason) | ||
print(response.status_code) | ||
print(response.reason) | ||
|
||
print("Writing data (municipalities_by_name)..") | ||
with open("municipalities_by_name.json", "w") as f: | ||
f.write(response.text) | ||
print("Writing data (municipalities_by_name)..") | ||
with open("municipalities_by_name.json", "w") as f: | ||
f.write(response.text) | ||
|
||
names = response.json() | ||
with open("municipalities_by_id.json", "r") as id_file: | ||
id_file_contents = id_file.read() | ||
for municipality in names["attributes"]: | ||
id_file_contents = id_file_contents.replace(municipality["id"], municipality["name"]["dan"]) | ||
with open("municipalities_unformatted.json", "w") as f: | ||
f.write(id_file_contents) | ||
names = response.json() | ||
with open("municipalities_by_id.json", "r") as id_file: | ||
id_file_contents = id_file.read() | ||
for municipality in names["attributes"]: | ||
id_file_contents = id_file_contents.replace(municipality["id"], municipality["name"]["dan"]) | ||
with open("municipalities_unformatted.json", "w") as f: | ||
f.write(id_file_contents) | ||
|
||
if __name__ == "__main__": | ||
get_municipality_name() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters