Skip to content

Commit

Permalink
Updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
anikets95 committed Nov 7, 2024
1 parent d73fed1 commit 74103e6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea
.idea

.env
2 changes: 1 addition & 1 deletion bmtc-data
Submodule bmtc-data updated 5616 files
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pandas==2.2.2
requests==2.32.3
transitfeed-py3==1.2.16
geopandas==1.0.1
python-on-whales==0.72.0
python-on-whales==0.72.0
python-dotenv==1.0.1
30 changes: 29 additions & 1 deletion scripts/orchestrator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
from scripts import scrape, geojson_creator, gtfs, csv_creator
import json
import os
from datetime import datetime
from dotenv import load_dotenv

from python_on_whales import DockerClient

from scripts import geojson_creator, csv_creator, scrape, gtfs

docker = DockerClient(compose_files=["./docker-compose.yml"])


# Load environment variables from the .env file
load_dotenv()


# Function to read, edit, and save JSON
def modify_json(file_path, key, new_value):
# Step 1: Read the JSON file
with open(file_path, 'r') as file:
data = json.load(file)

# Step 2: Modify the JSON data
data[key] = new_value

# Step 3: Write the updated JSON back to the file
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)


config_path = "bmtc-data/html/config.json"
scrape.main()
gtfs.main()
modify_json(config_path, "effectiveDate", datetime.now().strftime("%B %d, %Y"))
modify_json(config_path, "mapboxAccessToken", os.getenv("MAPBOX_ACCESS_TOKEN"))
docker.compose.build()
docker.compose.up()
docker.compose.down()
geojson_creator.main()
csv_creator.main()
modify_json(config_path, "mapboxAccessToken", "")
6 changes: 4 additions & 2 deletions scripts/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ def fetch_timetable(route, dow, date):
"routeid": route['routeid'],
"fromStationId": route['fromstationid'],
"toStationId": route['tostationid'],
"current_date": date.strftime("%Y-%m-%d")
"current_date": date.strftime("%Y-%m-%d")+"T00:00:00.000Z",
"endtime": date.strftime("%Y-%m-%d")+" 23:59",
"starttime": date.strftime("%Y-%m-%d")+" 00:00",
})
response = session.post(f'{BASE_URL}GetTimetableByRouteid_v2', headers=HEADERS, data=data)
response = session.post(f'{BASE_URL}GetTimetableByRouteid_v3', headers=HEADERS, data=data)

if response.json().get('Message') == "No Records Found" or not response.json().get('Issuccess'):
logging.error(f"No timetable records found In API call for routeid {route['routeid']} "
Expand Down

0 comments on commit 74103e6

Please sign in to comment.