Skip to content

Commit

Permalink
feat: create function to grab schedule uploads (dataDates)
Browse files Browse the repository at this point in the history
  • Loading branch information
HagenFritz committed Jun 12, 2024
1 parent f2cf425 commit 1764a25
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
31 changes: 31 additions & 0 deletions smartpm/endpoints/uploads.py
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
51 changes: 51 additions & 0 deletions snippets/explore_uploads.py
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()

0 comments on commit 1764a25

Please sign in to comment.