Scrape production data from POCloud to push to accounting servers
Developed by Patrick McDonagh @patrickjmcd, Henry pump
System variables must be set up for the script to run. Add the following lines to /etc/environment
MESHIFY_USERNAME="<yourMeshifyUsername>"
MESHIFY_PASSWORD="<yourMeshifyPassword>"
python3 -m venv env # Creates the virtual environment in a folder ./env
source env/bin/activate # activates the virtual environment
pip install xlsxwriter requests tzlocal meshify # installs the python modules
This section will show you how to configure the S3 Bucket within AWS. It assumes a strong knowledge of AWS platforms.
Populating channel config files tells the Lambda function which devices to prepare reports for and which channels to include data from. Devices will not be recognized unless they have both a Channel Config file and a To file.
Prepare a file named devicetype_channels.json where “devicetype” is the Meshify name for the devicetype.
touch <devicetype>_channels.json
In the text editor of your choice, develop a JSON list of objects that contains properties “meshify_name” and “vanity_name”.
[
{
"meshify_name": "<channel name in meshify>",
"vanity_name": "<vanity name for report header>"
},
{
"meshify_name": "<another channel name in meshify>",
"vanity_name": "<another vanity name for report header>"
},
]
Upload this file to the “channel_config” folder in the S3 Bucket.
Populating To files tells the Lambda function which devices to prepare reports for and whom to send the reports for each company. Devices will not be recognized unless they have both a Channel Config file and a To file.
Prepare a file named devicetype_to.json where “devicetype” is the Meshify name for the devicetype.
touch <devicetype>_to.json
In the text editor of your choice, develop a JSON object that contains properties of the format below. CompanyA and CompanyB should be replaced by the full name of the company as recorded in Meshify.
{
"CompanyA": [
"person@email.com",
"place@email.com"
],
"CompanyB": [
"person@email.com",
"thing@email.com"
]
}
Upload this file to the “to_files” folder in the S3 Bucket.
As long as everything has been setup correctly, all it takes is running:
python local_test.py
This performs a “dry-run” where it will generate the reports and print to the console the list of recipients, but it will not actually send the reports. The script can trigger the sending of reports by running:
python local_test.py --send