-
Notifications
You must be signed in to change notification settings - Fork 18
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
Sourcery Starbot ⭐ refactored dannywade/devnet-expert #2
base: main
Are you sure you want to change the base?
Conversation
|
||
from tqdm import tqdm | ||
import time | ||
|
||
i = 1 | ||
for i in tqdm(range(int(60))): | ||
for _ in tqdm(range(60)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 6-6
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Replace unused for index with underscore (
for-index-underscore
)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the following improvement in Function add_static_routes
:
self.log.info('Creating VLAN {} (id {})'.format(service._path, service.id)) | ||
self.log.info(f'Creating VLAN {service._path} (id {service.id})') | ||
|
||
vars = ncs.template.Variables() | ||
|
||
template = ncs.template.Template(service) | ||
# Creates the VLAN | ||
template.apply('vlan-template', vars) | ||
|
||
# Apply template to access ports in this VLAN | ||
self.log.info('Configuring access ports for VLAN {}'.format(service.id)) | ||
self.log.info(f'Configuring access ports for VLAN {service.id}') | ||
template.apply('access-port-template') | ||
|
||
# Apply template to trunk ports in this VLAN | ||
self.log.info('Configuring trunk ports for VLAN {}'.format(service.id)) | ||
self.log.info(f'Configuring trunk ports for VLAN {service.id}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function VLANService.cb_create
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
@@ -35,7 +35,6 @@ def dnac_cli(): | |||
def get(): | |||
""" Action for read-only tasks and gathering information. """ | |||
click.echo("Getting information...") | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
|
||
for device in device_list: | ||
table.add_row(device["hostname"], device["type"], device["serialNumber"], device["softwareVersion"]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the following improvement in Function devices
:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the following improvement in Function devices
:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the following improvement in Function clients
:
click.echo('Debug is %s' % (ctx.obj['DEBUG'] and 'on' or 'off')) | ||
click.echo(f"Debug is {ctx.obj['DEBUG'] and 'on' or 'off'}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function sync
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
|
||
parsed_output = result.genie_parse_output() | ||
|
||
ios_version = parsed_output["version"]["version"] | ||
parsed_output = result.genie_parse_output() | ||
|
||
return ios_version | ||
return parsed_output["version"]["version"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_ios_version
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if request.method == "POST": | ||
# Debugging purposes | ||
print("Data received from Webhook is: ", request.json) | ||
if request.method != "POST": | ||
return | ||
# Debugging purposes | ||
print("Data received from Webhook is: ", request.json) | ||
|
||
# Collect Meraki JSON data | ||
response = request.json | ||
# Collect Meraki JSON data | ||
response = request.json | ||
|
||
# Parsing out interesting data from Meraki alert data and marking down for Webex payload | ||
webex_message = f""" | ||
# Parsing out interesting data from Meraki alert data and marking down for Webex payload | ||
webex_message = f""" | ||
ALERT: Network {response['networkName']} in organization {response['organizationName']} had the following change occur: | ||
``` | ||
{response['alertData']} | ||
``` | ||
""" | ||
|
||
# Base URL to post messages to Webex | ||
webex_url = "https://webexapis.com/v1/messages" | ||
# Base URL to post messages to Webex | ||
webex_url = "https://webexapis.com/v1/messages" | ||
|
||
# Payload for Webex Messages API | ||
message_body = json.dumps({"roomId": WEBEX_ROOM_ID, "markdown": webex_message}) | ||
# Payload for Webex Messages API | ||
message_body = json.dumps({"roomId": WEBEX_ROOM_ID, "markdown": webex_message}) | ||
|
||
# Required headers for Webex Messages API call | ||
webex_headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": f"Bearer {WEBEX_BOT_TOKEN}", | ||
} | ||
# Required headers for Webex Messages API call | ||
webex_headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": f"Bearer {WEBEX_BOT_TOKEN}", | ||
} | ||
|
||
# Send parsed data to Webex Teams room | ||
webex_post = requests.post( | ||
url=webex_url, headers=webex_headers, data=message_body, verify=False | ||
) | ||
# Send parsed data to Webex Teams room | ||
webex_post = requests.post( | ||
url=webex_url, headers=webex_headers, data=message_body, verify=False | ||
) | ||
|
||
# Print out response body and status code | ||
print(webex_post.status_code) | ||
print(webex_post.json()) | ||
# Print out response body and status code | ||
print(webex_post.status_code) | ||
print(webex_post.json()) | ||
|
||
# Indicate whether request was successful (should be a log message) | ||
if webex_post.ok: | ||
print("Webex message sent!") | ||
else: | ||
print("Error sending to Webex") | ||
# Indicate whether request was successful (should be a log message) | ||
if webex_post.ok: | ||
print("Webex message sent!") | ||
else: | ||
print("Error sending to Webex") | ||
|
||
return "Webhook received!" | ||
return "Webhook received!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function data_intake
refactored with the following changes:
- Add guard clause (
last-if-guard
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run: