Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

131 locate free extensions #139

Merged
merged 9 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions odins_spear/scripter.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def remove_numbers(self, service_provider_id: str, group_id: str, start_of_range
return scripts.remove_numbers.main(self.api, service_provider_id, group_id, start_of_range_number,
end_of_range_number)

def locate_free_extension(self, service_provider_id: str, group_id: str, field: list):

Jordan-Prescott marked this conversation as resolved.
Show resolved Hide resolved
return scripts.locate_free_extension(self.api, service_provider_id, group_id, field)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you ran the code? Missing '.main()' here on the end of 'locate_free_extension' which would have errored if you ran it.


def service_provider_trunking_capacity(self, service_provider_id: str):
"""Returns a JSON breakdown of the Trunking Call Capacity of a Service Provider/ Enterprise (SP/ENT).
Expand Down
1 change: 1 addition & 0 deletions odins_spear/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
from .user_activity import main
from .user_association import main
from .webex_builder import main
from .locate_free_extension import main
104 changes: 104 additions & 0 deletions odins_spear/scripts/locate_free_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

Jordan-Prescott marked this conversation as resolved.
Show resolved Hide resolved
def retrieve_extensions(
api,
service_provider_id: str,
group_id: str
) -> list:

extensions = []

dataset = api.get.users(
service_provider_id,
group_id
)

for data in dataset:
if not data['extension']:
continue
###

extensions.append(data['extension'])

dataset = api.get.group_hunt_groups(
service_provider_id,
group_id
)

for data in dataset:
if not data['extension']:
continue
###

extensions.append(data['extension'])

dataset = api.get.group_call_centers(
service_provider_id,
group_id
)

for data in dataset:
if not data['extension']:
continue
###

extensions.append(data['extension'])

dataset = api.get.auto_attendants(
service_provider_id,
group_id
)

for data in dataset:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little repetitive looping three times, can we be more efficient here collecting all data and looping once maybe?

if not data['extension']:
continue

extensions.append(data['extension'])
###

if not extensions:
return

return extensions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condensed version of lines 58-61:

return extensions if extensions else None

###

def main(
api,
service_provider_id,
group_id,
field: list
):
'''
Retrieves The Lowest Free Extension Available In The Designated Group Passed.

field is passed as such [100, 1000]
'''
### Retrieve List Of Occupied Extensions Within The Group
extensions = retrieve_extensions(
api,
service_provider_id,
group_id,
)

### Cull Out Of Range Extensions
for extension in extensions:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is needed as we have the range we are looking for anyway and in line 94/95 you achieve looking for only numbers in the range given to us.


if field[0] < extension and field[1] > extension:
continue

extensions.remove(extension)
###

### Locate Initial Free Extension
extension_set = set(extensions)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you've done this dude, extensions is already an iterable. Converting to a set is usually only done when we want to remove duplicates or need specific set functionality.


for extension in range(field[0] + 1, field[1]):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you skip the first extension in the range by adding 1? Range starts at the first value and goes up to but doesn't include the last value so would have thought you'd add 1 to the end to include the last value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believed the range would be better suitable for extensions between the passed range values however

if extension not in extension_set:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work as extensions will be a set of strings right like '100' and you are looking for an integer just 100.

return extension
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just keeping convention we have but here return a python dict like the below.

return {'extension': extension}

####

print("Unable To Locate A Free Extension Within The Range")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we want to raise an a new error that the user hasn't been found. The reason we do this is if a developer has a script that uses this function to first find a free extension and in the next step takes what is returned from this and inserts into a new function to build it printing we didnt find it has no control flow value. We need to interrupt otherwise we will cause rurther errors down the line.

return