Marketplaces Scripts

Handling Marketplaces Data and FTP Operations

7min

This document provides an overview of key components and processes for managing marketplace data and performing FTP operations in our script.

Code Overview

Main Scripts

In this section, we will delve into the two primary modules that play a central role in our script.

  • get_data module - The most pivotal module in our script is get_data, which is used globally. It contains a function, get_listing_data, designed to Extract, Transform, and Load (ETL) data into a CSV file. The function connects to a database, executes SQL scripts, fetches data, processes it, and saves it to a CSV file.
Python


The code snippet provides a brief overview of what happens in the function.

  • ftp_config module - The ftp_config module houses the upload_files function, which is responsible for uploading files to an FTP server. This function ensures proper FTP host, user, and password values are provided, logs into the FTP server, and uploads files to a specified path.
Python


This snippet provided an overview of how the function works

Now lets Look at how the FTP Marketplaces Function.

FTP Marketplaces

This module contains 3 functions, execute_sql, upload_files_to_ftp and main. Before this 2 list that contain tuples are defined. 1. sql_scripts_and_filenames - This list contains typles that reference maretplace name, sql script, and filenames. 2. file_and_upload_paths - This List contains tuples that contains the upload paths and the fienames of the files.

  • execute_sql function - The execute_sql function executes a list of SQL scripts and saves the results to corresponding files. It iterates through the list of tuples, calling the get_listing_data function for each tuple and logging progress.
Python

  • upload_files_to_ftp - This function uploads a list of files to an FTP server. It iterates through the list of tuples, calls the upload_files function for each, and logs the upload process.
Python

  • main function - The main function combines the above functions for seamless execution and scheduling. It orchestrates the data retrieval and FTP upload processes.

Conclusion

This document has provided an insight into how marketplace data is fetched and uploaded to the FTP server for listing. For further details, refer to the code and comments within the script.