-
Notifications
You must be signed in to change notification settings - Fork 31
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
fix issue#21 #22
fix issue#21 #22
Conversation
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.
Thanks a lot for this PR! I had overlooked this, but now added some comments. While I was testing this, I already made the required changes myself, so there's no need to address them anymore. Will merge now. Thanks again!
''' | ||
|
||
data_dict = {} | ||
for field_name in transitfeed.Agency._FIELD_NAMES: |
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.
This variable is protected, we should not access it directly. I'll change this before merging.
@@ -298,5 +293,34 @@ def load_config(file): | |||
|
|||
return config; | |||
|
|||
def load_agency(config): |
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.
Just a German style nitpick for the future ;) PEP8 requires two blank lines between methods.
@@ -298,5 +293,34 @@ def load_config(file): | |||
|
|||
return config; | |||
|
|||
def load_agency(config): | |||
''' |
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.
Great you are adding documentation already! Docstrings should be made with double quotes "
btw.
data_dict[field_name] = field_value | ||
|
||
except KeyError: | ||
sys.stderr.write("key '"+field_name+"' was not found on the config file.") |
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.
I think it should be "in the config file".
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.
Sometime later, we should maybe distinguish here between required and optional fields or does the validation already print warnings for that?
if field_value is not None and field_value != "": | ||
data_dict[field_name] = field_value | ||
|
||
except KeyError: |
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.
I think it would be better to check if field_name is in config["agency"]
rather than catching KeyError
s.
timezone=config['agency']['agency_timezone'], | ||
agency_id=config['agency']['agency_id'] | ||
) | ||
agency = load_agency(config) |
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.
This will break the script, because the agency is never added to the schedule object. Did you test this?
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.
You are right, I'm sorry. I thought I tested but obviously I make a mistake.
if not agency.Validate(): | ||
sys.stderr.write("Agency data has errors") | ||
# later, an error handling based on a exception here could be added. | ||
#raise AttributeError('Agency data on config file in not valid.') |
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.
Maybe we should distinguish here between required and optional fields. Do you know how the validation behaves? Maybe it prints warnings already?
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.
The validate method returns a boolean and have a mechanism to handle problems. I think the method "load_agency" could be improved to be less naive.
Maybe could be more simple, just invoke the Agency constructor like this: agency = transitfeed.Agency(field_dict=config["agency"]) there is no more need of the load_agency method. |
No description provided.