-
-
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.
* Add Arnhem and Eindhoven to project * 📚 Update the docs
- Loading branch information
1 parent
291a36c
commit 2f48765
Showing
4 changed files
with
96 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json, datetime, uuid, os | ||
import urllib.request | ||
|
||
from database import connection, cursor | ||
from dotenv import load_dotenv | ||
from pathlib import Path | ||
|
||
city = "Arnhem" | ||
|
||
load_dotenv() | ||
env_path = Path('.')/'.env' | ||
load_dotenv(dotenv_path=env_path) | ||
|
||
def download(): | ||
"""Download the data as JSON file.""" | ||
|
||
# Create a variable and pass the url of file to be downloaded | ||
url = f'{os.getenv("SOURCE")}/6f301547133a4acda9074ec3ca9b075b_0.geojson' | ||
# Copy a network object to a local file | ||
urllib.request.urlretrieve(url, 'data/parking-arnhem.json') | ||
print(f'{city} - KLAAR met downloaden') | ||
|
||
def upload(): | ||
"""Upload the data from the JSON file to the database.""" | ||
|
||
arnhem_file = "data/parking-arnhem.json" | ||
arnhem_data = open(arnhem_file).read() | ||
arnhem_obj = json.loads(arnhem_data) | ||
try: | ||
for item in arnhem_obj["features"]: | ||
id = uuid.uuid4().hex[:8] | ||
item = item["properties"] | ||
|
||
sql= """INSERT INTO `parking_cities` (`id`, `city`, `street`, `orientation`, `number`, `longitude`, `latitude`, `visibility`, `created_at`, `updated_at`) | ||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""" | ||
val = (id, str(city), str(item["LOCATIE"]), str(item["TYPE_VAK"]), int(item["AANTAL"]), float(item["LON"]), float(item["LAT"]), bool(True), (datetime.datetime.now()), (datetime.datetime.now())) | ||
cursor.execute(sql, val) | ||
connection.commit() | ||
except Exception as e: | ||
print(f'MySQL error: {e}') | ||
finally: | ||
print(f'{city} - KLAAR met updaten van database') |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import uuid, parking_eindhoven, datetime, aiohttp | ||
|
||
from database import connection, cursor | ||
|
||
city = "Eindhoven" | ||
|
||
async def async_get_locations(number, type): | ||
"""Get parking data from API.""" | ||
|
||
async with aiohttp.ClientSession() as client: | ||
return await parking_eindhoven.get_locations(number, type, client) | ||
|
||
def upload(data_set): | ||
"""Upload the data_set to the database.""" | ||
|
||
try: | ||
for item in data_set: | ||
id = uuid.uuid4().hex[:8] | ||
sql = """INSERT INTO `parking_cities` (`id`, `city`, `street`, `orientation`, `number`, `longitude`, `latitude`, `visibility`, `created_at`, `updated_at`) | ||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""" | ||
val = (id, str(city), str(item.street), None, item.number, float(item.longitude), float(item.latitude), bool(True), (datetime.datetime.now()), (datetime.datetime.now())) | ||
cursor.execute(sql, val) | ||
connection.commit() | ||
except Exception as e: | ||
print(f'MySQL error: {e}') | ||
finally: | ||
print(f'{city} - KLAAR met updaten van database') | ||
|
||
def update(): | ||
return |