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
Convert manufacturer.txt to python dictionary #33 #35
Conversation
bucciarellialessandro
commented
Nov 8, 2014
- first idea of implementation
I created this PR in order to discuss together on the approach to use. |
Great! I've taken a look at the python dictionary, there are a few improvements that can be done:
As a further improvement, I was thinking that it would be very handy and it would save us a lot of time in the future if the txt file could be downloaded directly from the internet with an http request, so we can avoid storing it in the repository. Do you think you can do it? Regarding how to call the code in the library, we could write a simple function in netengine.utils that takes a mac address (accepting both entire or partials) as input and returns the manufacturer name.
If you agree with me we can do these things in 3 separate steps, I can write the final function. |
I mostly agree with you on all points. As regards to dictionary lookup you're right, I think it would be awesome if we store in the dict the keys as "AABBCCDDFF" and make some operation on the string to be compared. So could be an idea of an operational workflow:
What do you think? :) |
key = pairs[0].strip('\t\n\r') | ||
value = pairs[1].strip('\t\n\r') | ||
dictionary[key] = value | ||
json_file = json.dumps(dictionary, indent = 4) |
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.
few suggestions:
indent=4 should be without spaces
also add here sort_keys=True
If the URL of the txt file is stable over time we can hardcode it in parser.py and let the script take care of downloading it and we can avoid storing it in the repository. The workflow you described is correct, although you can simplify by doing just 4 operations:
|
Why first point? Letters are valid char for a MAC address, aren't they? For example AA:AA:AA(:AA:AA:AA) |
Yes sorry strip anything that is not an alphanumeric character [a-zA-Z0-9] |
d981e63
to
147de92
Compare
MAC address is hexadecimal, so it would be better to strip anything that is not [a-fA-F0-9] |
@cl4u2 👍 for [a-fA-F0-9] |
Hi guys, We could have introduced a bug. |
import json | ||
|
||
|
||
|
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.
remove 1 line
c55ffe6
to
f8be554
Compare
f8be554
to
9e1c625
Compare
👍 |
Converted manufacturer.txt to python dictionary #33