Web Apps
Stock Sync App
6 min
introduction this script is designed for mainlyextracting stock data from a cybertill, performing data transformation, and generating csv files functionality getalldata(location) this function is responsible for extracting data from a database for a specific location and writing it to a csv file it follows these steps fetch data from the database for the specified location filter the data to extract relevant information, such as brands and seasons fetch items using the getitems function with filtering criteria append the extracted data to the alldatadetails array repeat the data extraction process until all data is fetched write the combined data to a csv file with the location's name getitems(limit, offset, location id, brandsql, seasonsql) this function constructs an sql query based on the provided parameters and fetches data from the database the steps include construct a sql query with parameters like limit , offset , location id , brandsql , and seasonsql fetch data from the database using the constructed query return the fetched data getlocations() this function retrieves a list of locations from the database it constructs and executes an sql query to obtain this information generatedefaultlocationfile(locationnames) this function generates a summary csv file that aggregates data from multiple location specific csv files the steps include iterate over the provided locationnames read each location specific csv file and collect data group the collected data by the "ref" field calculate the sum of the "stock" values for each group generate a csv file with the aggregated data and write it to " /csv/default csv" main() the main function is the entry point of the script it coordinates the execution of various tasks, including fetching the list of locations iterating over each location to extract data generating the default location csv file uploading data for all locations writing the timestamp of the last run to a json file