-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Tes3awy/refactor
Refactor
- Loading branch information
Showing
10 changed files
with
138 additions
and
187 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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 |
---|---|---|
@@ -1,29 +1,25 @@ | ||
#!usr/bin/env python3 | ||
|
||
import csv | ||
from typing import AnyStr, List | ||
from typing import AnyStr, Dict, List | ||
|
||
|
||
def read_subnets(file_path: AnyStr = "subnets.csv") -> List[List]: | ||
def read_subnets(file_path: AnyStr = "subnets.csv") -> List[Dict[AnyStr, AnyStr]]: | ||
"""Reads CSV subnets file | ||
Args: | ||
file_path (AnyStr, optional): Path to subnets CSV file. Defaults to "subnets.csv". | ||
Parameters | ||
---------- | ||
file_path : AnyStr, optional | ||
Name of a CSV file, by default "subnets.csv" | ||
Returns: | ||
List[List]: Subnets in CIDR notation representation | ||
Returns | ||
------- | ||
List[Dict[AnyStr, AnyStr]] | ||
Subnets in CIDR Notation | ||
""" | ||
|
||
# Define an empty list to hold all subnets | ||
subnets = [] | ||
|
||
# Read subnets CSV file | ||
with open(file=file_path, mode="r") as csvfile: | ||
next(csvfile) # Skip header line | ||
csv_data = csv.reader( | ||
csvfile, delimiter="\n", dialect="excel", doublequote=True | ||
) | ||
for subnet in csv_data: | ||
subnets.append(subnet[0]) | ||
|
||
return subnets | ||
csv_data = csv.DictReader(f=csvfile, fieldnames={"cidr"}) | ||
return [cidr for cidr in csv_data] |
Oops, something went wrong.