2 Commits

Author SHA1 Message Date
Patrick McDonagh
1a443a07e9 Reorganize Files 2018-05-22 12:03:28 -05:00
Patrick McDonagh
4a03ac9026 Moves files around and completes #7 2018-04-12 11:05:49 -05:00
26 changed files with 1 additions and 77 deletions

View File

@@ -44,7 +44,7 @@
data-nodename="transferstation.ft01_flow"
data-units="BPD"
data-min="0"
data-max="50000"
data-max="75000"
data-decimalplaces="2"
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
data-valuefontsize="18px">

View File

@@ -1,38 +0,0 @@
"""Query Meshify for data."""
import requests
import json
from os import getenv
from sys import exit
MESHIFY_BASE_URL = "https://henrypump.meshify.com/api/v3/"
MESHIFY_USERNAME = getenv("MESHIFY_USERNAME")
MESHIFY_PASSWORD = getenv("MESHIFY_PASSWORD")
MESHIFY_AUTH = requests.auth.HTTPBasicAuth(MESHIFY_USERNAME, MESHIFY_PASSWORD)
if not MESHIFY_USERNAME or not MESHIFY_PASSWORD:
print("Be sure to set the meshify username and password as environment variables MESHIFY_USERNAME and MESHIFY_PASSWORD")
exit()
def find_by_name(name, list_of_stuff):
"""Find an object in a list of stuff by its name parameter."""
for x in list_of_stuff:
if x['name'] == name:
return x
return False
def query_meshify_api(endpoint):
"""Make a query to the meshify API."""
q_url = MESHIFY_BASE_URL + endpoint
q_req = requests.get(q_url, auth=MESHIFY_AUTH)
return json.loads(q_req.text) if q_req.status_code == 200 else []
def post_meshify_api(endpoint, data):
"""Post data to the meshify API."""
q_url = MESHIFY_BASE_URL + endpoint
q_req = requests.post(q_url, data=json.dumps(data), auth=MESHIFY_AUTH)
if q_req.status_code != 200:
print(q_req.status_code)
return json.loads(q_req.text) if q_req.status_code == 200 else []

Binary file not shown.

View File

@@ -1,38 +0,0 @@
"""Read a CSV file of channels and post them to Meshify via the API."""
import csv
import meshify
import sys
def main(csv_file, devicetype):
"""Main function."""
csvfile = open(csv_file, 'rU')
reader = csv.DictReader(csvfile, dialect=csv.excel)
channels = []
idx = 0
for x in reader:
channels.append(x)
channels[idx]["fromMe"] = False
channels[idx]["regex"] = ""
channels[idx]["regexErrMsg"] = ""
channels[idx]["dataType"] = int(channels[idx]["dataType"])
channels[idx]["deviceTypeId"] = int(channels[idx]["deviceTypeId"])
channels[idx]["channelType"] = int(channels[idx]["channelType"])
channels[idx]["io"] = bool(channels[idx]["io"])
idx += 1
try:
this_devicetype = meshify.find_by_name(devicetype, meshify.query_meshify_api("devicetypes"))
for c in channels:
print(meshify.post_meshify_api("devicetypes/{}/channels".format(this_devicetype['id']), c))
except KeyError:
print("Could not find key {}".format(devicetype))
if __name__ == '__main__':
if len(sys.argv) == 3:
main(sys.argv[1], sys.argv[2])
else:
print("Syntax is python postChannels.py <filepath.csv> <devicetype name>")

Binary file not shown.