-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add files to get UISP data and process nn
- Loading branch information
1 parent
1cbb381
commit 112b963
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import requests | ||
import json | ||
from dotenv import load_dotenv | ||
import os | ||
import re | ||
|
||
load_dotenv() | ||
|
||
def get_uisp_devices(): | ||
response = requests.get("https://uisp.mesh.nycmesh.net/nms/api/v2.1/devices", headers={'x-auth-token': os.environ.get('NYCMESH_TOOL_AUTH_TOKEN')}, verify=False) | ||
|
||
devices = json.loads(response.content) | ||
|
||
if devices == []: | ||
raise ValueError('Problem downloading UISP devices.') | ||
|
||
return devices | ||
|
||
def nn_from_uisp_name(uisp_name): | ||
matches = re.findall("(?:^|-)(\d{3,})(?:-|$)", uisp_name) | ||
if not matches: | ||
return None | ||
|
||
return int(matches[0]) | ||
|
||
def filter_devices_by_nn(devices, nn): | ||
filtered_devices = [] | ||
for device in devices: | ||
try: | ||
name = device['identification']['displayName'] | ||
nn = nn_from_uisp_name(name) | ||
if nn: | ||
filtered_devices.append(device) | ||
except: | ||
pass | ||
return filtered_devices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from supportbot.utils.uisp_data import nn_from_uisp_name, get_uisp_devices | ||
|
||
load_dotenv() | ||
|
||
def test_get_uisp_devices(): | ||
assert len(get_uisp_devices()) > 0 | ||
|
||
def test_nn_from_uisp_name(): | ||
assert nn_from_uisp_name("lbe-5134-diy-455") == 5134 | ||
assert nn_from_uisp_name("lbe-5134") == 5134 | ||
assert nn_from_uisp_name("5134-lbe") == 5134 | ||
|
||
if __name__ == "__main__": | ||
test_nn_from_uisp_name() |