Sourcery Starbot ⭐ refactored dannywade/devnet-expert#2
Sourcery Starbot ⭐ refactored dannywade/devnet-expert#2SourceryAI wants to merge 1 commit intodannywade:mainfrom
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.
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)
|
|
||
| add_static_route_url = f"{BASE_URL}/ietf-routing:routing/routing-instance=default/routing-protocols/routing-protocol=static,1/static-routes/ipv4" | ||
|
|
There was a problem hiding this comment.
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.
Function VLANService.cb_create refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting)
| def get(): | ||
| """ Action for read-only tasks and gathering information. """ | ||
| click.echo("Getting information...") | ||
| pass |
There was a problem hiding this comment.
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.
Found the following improvement in Function devices:
|
|
There was a problem hiding this comment.
Found the following improvement in Function devices:
|
|
There was a problem hiding this comment.
Found the following improvement in Function clients:
| click.echo(ctx.obj) # prints entire context object that's passed in | ||
| click.echo(ctx.parent.obj) # prints entire context object of parent (cli) | ||
| 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.
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.
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.
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
mainbranch, then run: