Main Scripts

Titles Generation Script Documentation

8min

Introduction

This document outlines the process of data retrieval and processing from Cybertill. It details how the script is engineered to not only fetch and manipulate data but also to formulate product titles. Subsequently, it generates CSV files which are then uploaded to FTP

Installation

1.Clone the repository and install the dependencies

Shell


2.Run the script

Shell


Script Overview

The script performs the following primary tasks:

  1. Retrieving data from a cybertill.
  2. Merging and processing the retrieved data to create product titles.
  3. Generating a CSV file containing product details.
  4. Uploading the CSV file to an FTP Server.

Script Structure

The script is organized into functions and steps. Here's an overview of the key functions and what they do:

getAllData()

This function retrieves data from the database. It uses a combination of limit and offset parameters to paginate through the data and collect it in chunks.

createFinalProducts(data)

This function processes and creates final product records from the collected data. It merges data by item ID, extracts style attributes like color and size, and generates product names.

generateCsv(data)

This function generates a CSV file containing product details. It uses the json2csv library to convert the data into CSV format.

getData(limit, offset)

This function constructs a SQL query to retrieve data from the database. It incorporates filters and conditions based on configuration constants and the limit and offset values.

main()

The main function orchestrates the entire data collection and processing workflow. It performs the following steps:

  • Retrieves data from the database.
  • Creates product records from the collected data.
  • Generates a CSV file containing product details.
  • Optionally, uploads the CSV file to an external destination.
  • Logs processing information.

Conclusion

This data collection and processing script is designed to automate the retrieval and processing of data from a database, ultimately creating product titles and generating CSV files.