-
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.
feat: create function to grab schedule uploads (dataDates)
- Loading branch information
1 parent
f2cf425
commit 1764a25
Showing
2 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from smartpm.client import SmartPMClient | ||
from smartpm.decorators import api_wrapper | ||
from smartpm.logging_config import logger | ||
|
||
class Uploads: | ||
def __init__(self, client: SmartPMClient): | ||
self.client = client | ||
|
||
@api_wrapper | ||
def get_schedule_uploads(self, project_id, scenario_id): | ||
""" | ||
Gets the schedule upload data for a specific project and scenario: https://developers.smartpmtech.com/#operation/get-scenario-schedules | ||
Parameters | ||
---------- | ||
project_id : str | ||
The Project ID containing the scenario for which you would like to pull the delay table for | ||
scenario_id : str | ||
The Scenario ID for which you would like to pull the delay table for | ||
Returns | ||
------- | ||
<response.json> : dict | ||
Schedule upload data as a JSON object | ||
""" | ||
logger.debug(f"Fetching delay table for project_id: {project_id}, scenario_id: {scenario_id}") | ||
|
||
endpoint = f'v1/projects/{project_id}/scenarios/{scenario_id}/schedules' | ||
response = self.client._get(endpoint=endpoint) | ||
|
||
return response |
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,51 @@ | ||
import os | ||
import sys | ||
import json | ||
|
||
# Add the package root directory to the sys.path | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) | ||
|
||
from dotenv import load_dotenv | ||
load_dotenv() # Load environment variables from .env file | ||
|
||
from smartpm.client import SmartPMClient | ||
from smartpm.endpoints.projects import Projects # import projects to get project IDs | ||
from smartpm.endpoints.scenarios import Scenarios | ||
from smartpm.endpoints.uploads import Uploads | ||
|
||
API_KEY = os.getenv("API_KEY") | ||
COMPANY_ID = os.getenv("COMPANY_ID") | ||
|
||
def main(): | ||
# Setup SDK | ||
client = SmartPMClient(API_KEY, COMPANY_ID) | ||
projects_api = Projects(client) | ||
scenarios_api = Scenarios(client) | ||
upload_api = Uploads(client) | ||
|
||
# Get Upload Data | ||
# --------------- | ||
# Find project by name | ||
name_to_find = "212096 - 401 FIRST STREET (College Station)" # replace with your project name | ||
project = projects_api.find_project_by_name(name=name_to_find) | ||
project_id = project["id"] | ||
|
||
# Find scenario by name | ||
scenario_to_find = "Full Schedule" # replace with your scenario name | ||
matching_scenarios = scenarios_api.find_scenario_by_name( | ||
project_id=project_id, | ||
scenario_name=scenario_to_find | ||
) | ||
scenario_id = matching_scenarios[-1].get("id") | ||
|
||
print("Get Upload Data") | ||
uploads = upload_api.get_schedule_uploads( | ||
project_id=project_id, | ||
scenario_id=scenario_id | ||
) | ||
print("Schedule upload data:") | ||
print(json.dumps(uploads, indent=4)) | ||
# --------------- | ||
|
||
if __name__ == "__main__": | ||
main() |