Open SelwynChan opened 1 year ago
You can modify the retrieve_and_export_order_data()
function to accept the loid_roid_mapping
and output_directory
as arguments. Then, you can call this function from your other function to trigger the retrieval job.
Here's the slightly modified version of the retrieve_and_export_order_data()
function:
def retrieve_and_export_order_data(loid_roid_mapping, output_directory, login_details):
driver, history_server, history_user, history_password = login_details["history"]
archive_server, archive_user, archive_password = login_details["archive"]
for logical_order_id, received_order_id in loid_roid_mapping.items():
try:
data = retrieve_data_from_databases(
driver, history_server, history_user, history_password,
archive_server, archive_user, archive_password, received_order_id
)
write_data_to_csv(output_directory, received_order_id, data)
except Exception as e:
print(f"Error processing receivedOrderID {received_order_id}: {e}")
Now, from your other function, you can call retrieve_and_export_order_data()
with the loid_roid_mapping
and output_directory
as arguments. For example:
def your_function():
# Your code...
loid_roid_mapping = {
"logicalOrderID1": "receivedOrderID1",
"logicalOrderID2": "receivedOrderID2"
}
output_directory = "output"
get_login_details(driver)
retrieve_and_export_order_data(loid_roid_mapping, output_directory, login_details)
Make sure to have the login_details
variable accessible in the scope of your function or pass it as an argument as well. This way, you can trigger the retrieval job with the specified loid_roid_mapping
and output_directory
.
First, install the required packages:
Now, create a
config.yaml
file with the server details:Here's the full Python code that meets your requirements:
This code uses
tkinter
to create a simple UI for the user to enter login details. Theretrieve_and_export_order_data()
function retrieves data from theoma_history
andoma_archive
databases and writes it to CSV files in the output directory. Theretrieve_data_from_databases()
function searches for the receivedOrderID in theoma_history
database first and then searches theoma_archive
databases in reverse chronological order.Make sure to replace
<history_server_address>
and<archive_server_address>
in theconfig.yaml
file with the correct server addresses. The user only needs to provide login details once for each run. The code ensures that database connections are properly closed, even in case of exceptions, and is designed to be modular, extendable, and well-organized.