ISI Middleware
GCM
Overview
The script is designed to periodically fetch data from a SQL Server database (ISI_Stock table) using OCR and send this data to an external API via POST requests. Each row from the ISI_Stock table populates a template payload, which is then sent as a POST request to the specified API.
If there’s any error during the POST request (like a failed addition of material to the ISI database), an email alert is sent to a specified developer email to notify about the error. The script keeps track of which parts have been emailed about, ensuring that multiple emails aren’t sent about the same part.
The script runs indefinitely with a 100-minute wait period between each run. There’s also commented-out code for a scheduled run at a specific time, but that functionality is currently not in use.
Key Features
- Imports:
- Essential libraries are imported like pyodbcfor database connectivity,requestsfor API requests,jsonfor handling JSON data,pandasfor data manipulation, and email-related libraries for sending emails.
 
- Essential libraries are imported like 
- Global Variables:
- headers: Contains an API key and content type for API requests.
- url: Endpoint URL for API requests.
- TempPayload: A template payload for the API request.
- Database connection credentials: server,database,username, andpassword.
 
- SMTP Class:
- Provides features to send email alerts using SMTP protocol.
- Contains attributes like port,password,smtp_server,sender_email, and various recipient emails.
- Contains methods ClearErrors,EmailAlertfor email error handling.
 
- ISIPost Function:
- Makes a POST request to the specified url.
- If the POST request results in an error, it sends an email alert using the SMTP class.
 
- Makes a POST request to the specified 
- PostData Function:
- Reads data from the SQL database table ISI_Stock.
- Iterates through the dataframe, populates the TempPayloaddictionary, and sends a POST request using theISIPostfunction for each row.
 
- Reads data from the SQL database table 
- Scheduling:
- Commented out code suggests that the PostDatafunction was intended to be scheduled to run every day at 06:00.
- Currently, the PostDatafunction runs in an infinite loop with a 6000-second (100 minutes) wait between each run.
 
- Commented out code suggests that the 
Below are snippets and simplifications of the Middleware that was purchased.










