Skip to main content

Library of useful functions for custom solutions.

Project description

MOTO CUSTOM SOLUTIONS

V 1.0


--> INSTALLING LIBRARY

  • pip install motolibrary
  • (For Updates) pip install motolibrary --upgrade

--> IMPORTING MODULE

  • import motolib
  • from motolib.(FileName.py) import (Function or *)

|| DOCS ||

The following is documentation for each of the library's functions:


---> 1. dir_clean.py

dir_clean(...): 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

ftp_cleanse(...): 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

ftp_download(...): 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_name : String (Optional) File will be downloaded locally with this name. Default is filename_filter. download_directory : String (Optional) Directory to download file to. Default is CWD.

Returns: None

Test Files for Function: test_ftp_down.py


---> 5. ftp_up.py

ftp_upload_file(...): 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

redash_download(...): 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

slack_send_file(...): Send files to a list of Slack channels.

Parameters: 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.

Notes: The Titles list argument must perfectly match up to the Files list argument.

Returns: None

slack_send_message(...): Send messages to a list of Slack channels.

Parameters: 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

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

supplement_create(...): 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

motolibrary-1.0.4.tar.gz (10.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page