Skip to content

Commit

Permalink
Update cs.py so that the json data from get is formatted the same whe…
Browse files Browse the repository at this point in the history
…n running in the computer or the router.
  • Loading branch information
tsnuggs committed Jul 3, 2017
1 parent 8d4efc9 commit c291619
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app_template/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down
22 changes: 18 additions & 4 deletions common/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions email/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions ftp_client/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions ftp_server/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions gps_localhost/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions gps_probe/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions hello_world/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions hspt/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
22 changes: 18 additions & 4 deletions list_serial_ports/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return json.loads(response.text)['data']
return json.loads(response.text)

def put(self, base, value='', query='', tree=0):
"""Send a put request."""
Expand Down Expand Up @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0):

def append(self, base, value='', query=''):
"""Send an append request."""
value = json.dumps(value).replace(' ', '')
if sys.platform == 'linux2':
value = json.dumps(value).replace(' ', '')
cmd = "post\n{}\n{}\n{}\n".format(base, query, value)
return self._dispatch(cmd)
else:
print('Append is only available when running the app in the router.')
raise NotImplementedError
# Running in a computer so use http to send the post to the router.
import requests
router_ip, router_username, router_password = self._get_router_access_info()
router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query)

try:
response = requests.post(router_api,
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=requests.auth.HTTPDigestAuth(router_username, router_password),
data={"data": '{}'.format(value)})
except (requests.exceptions.Timeout,
requests.exceptions.ConnectionError):
print("Timeout: router at {} did not respond.".format(router_ip))
return None

return response.text

def delete(self, base, query=''):
"""Send a delete request."""
Expand Down
Loading

0 comments on commit c291619

Please sign in to comment.