Library of useful functions for custom solutions.
Project description
MOTO CUSTOM SOLUTIONS
V 1.0
--> INSTALLING LIBRARY
- (Coming Soon) pip install motolibrary
--> IMPORTING MODULE
- import motolibrary.motocustomsolutionspkg
- from motolibrary.motocustomsolutionspkg.(FileName.py) import (Function or *)
|| DOCS ||
The following is documentation for each of the library's functions:
---> 1. dir_clean.py
Functionality: Removes all excel and csv files from a given directory.
Parameters: folder_path : string (Optional) Path to directory containing files to delete. If not specified, deletes from current inventory.
Returns: None
Side Effects: Deletes all .xlsx and .csv files from specified local directory
Test Files for Function: test_dir_clean.py
---> 2. errors.py
Functionality: Defines errors for library use.
Classes: CustomError(Exception) DataError(CustomError) FTPConnectionError(CustomError) FTPUploadError(CustomError) FTPEncodingError(CustomError) RedashAPIError(CustomError)
---> 3. ftp_cleanse.py
Functionality: Fills a dataframe with dummy values in each of the columns of which the original dataframe had data in.
Parameters: ftp_df : pandas.DataFrame DataFrame with data that will be closed. All columns filled in this DataFrame will be replaced with dummy values in the returned DataFrame.
Returns: dummy_df : pandas.DataFrame Dummy DataFrame containing only one row, of dummy values filled in the same columns as those that were filled in the original DF.
Ex. A DataFrame is passed with 3 columns, #1 and #3 are filled and #2 is not. The return would be a DF with the same columns as the original, containing only one row with columns #1 and #3 would be filled with garbage text and #2 empty.
Test Files for Function: test_ftp_cleanse.py
---> 4. ftp_down.py
Functionality: Downloads a file from an FTP server to a specified directory on the local machine.
Parameters: hostname : String FTP Host Name username : String FTP Login Username password : String FTP Login Password filename_filter : String Name of file to download from FTP download_directory : String Directory to download file to. Default is CWD.
Returns: None
Test Files for Function: test_ftp_down.py
---> 5. ftp_up.py
Functionality: Uploads a file from the local machine to a specified FTP server with an optional specified upload name.
Parameters: hostname : String FTP Host Name username : String FTP Login Username file_name : String FTP Login Password upload_name : String !! MUST INCLUDE EXTENSION !! (Optional) Specifies name of FTP Upload ie. Can be uploaded with a different name than local file.
Notes: File name must include its extension. So must the optional upload name.
Returns: True if supplement has been uploaded to FTP False if supplement did not upload to FTP
Test Files for Function: test_ftp_up.py
---> 6. redash_download.py
Functionality: Downloads data from a Redash query (with optional additional params) to the local machine as a .csv file.
Parameters: query_id : String ID of Redash Query api_key : String User API Key region : String Country for Redash (ie. CA or US) file_name : String File will be downloaded and saved locally as a .csv with this name params : Dictionary (Optional) Dictionary of query params -- Default = {} (empty)
Notes: The file name parameter should not include an extension. All query data will be processed & downloaded as a .csv file. For example, if one calls the function with "redash_data" as the file_name argument, the query will be saved under "redash_data.csv".
The region argument must be one of the following strings: ca, us, usa (capitalization does not matter... CA, US, USA will work).
Returns: None
Potential Errors Raised:
- ValueError (indicates invalid region code)
- RedashAPIError (connection issue with Redash API or invalid query info)
Test Files for Function: test_redash_download.py
---> 7. slack_funcs.py
Functionality: Send messages or files to a list of Slack of channels.
Parameters:
-
slack_send_file: slackbot_token : String Token for SlackBot Usage channels : List Contains list of channels to send to files : List Contains list of files to send titles : List Contains list of titles of files; titles should correspond to the same order of items in the files list.
-
slack_send_message: slackbot_token : String Token for SlackBot Usage channels : List Contains list of channels to send messages to via slack messages : List Contains list of messages to send
Notes: For slack_send_file, the Titles list argument must perfectly match up to the Files list argument.
Returns: None
Test Files for Functions: test_slack_funcs.py !! These are not automated tests - Manual checking of slack channels is needed !!
---> 8. supp_create.py
Functionality: Creates a standard supplement file from a DataFrame whose columns are mapped to the supplement at the user's discretion.
Parameters: df : pandas.DataFrame Pandas DataFrame containing data needed to be mapped into a supplement dealership_col : String Name of column from df to map to Dealership UID column of Supplement vin_col : String Name of column from df to map to VIN columnt of Supplement stock_col : String Name of column from df to map to Stock column of Supplement trim_col : String Name of column from df to map to Trim column of Supplement jato_col : String (Optional) Name of column from df to map to JATO column of Supplement chrmstyle_col : String (Optional) Name of column from df to map to Chrmstyle_ID column of Supplement discount_col : String (Optional) Name of column from df to map to Discounts column of Supplement misc1_col : String (Optional) Name of column from df to map to Misc 1 column of Supplement misc2_col : String (Optional) Name of column from df to map to Misc 2 column of Supplement
Returns: supp_df : pandas.DataFrame Supplement-style DataFrame with newly mapped data.
Ex. If one passes "my-dealerships" as the dealership_col parameter, the supplement's Dealership UID column will contain data from the original file's "my-dealerships" column.
Test Files for Functions: test_supp_create.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for moto-custom-solutions-1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ffda9c6a53569075bb9dc88dd08b9c47f2807c9aeccc297f879866bd2f086d |
|
MD5 | d2a43c66561b96f9768cebd5d3b18160 |
|
BLAKE2b-256 | 10161bff12d2bb0a2f078239313c472cf7602cb14aaceedc755f9d9769f54551 |