Skip to content
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

Closed
wants to merge 1 commit into from
Closed

fix issue#21 #22

wants to merge 1 commit into from

Conversation

jamescr
Copy link
Collaborator

@jamescr jamescr commented Sep 19, 2016

No description provided.

Copy link
Owner

@grote grote left a 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:
Copy link
Owner

@grote grote Sep 25, 2016

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):
Copy link
Owner

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):
'''
Copy link
Owner

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.")
Copy link
Owner

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".

Copy link
Owner

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:
Copy link
Owner

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 KeyErrors.

timezone=config['agency']['agency_timezone'],
agency_id=config['agency']['agency_id']
)
agency = load_agency(config)
Copy link
Owner

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?

Copy link
Collaborator Author

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.')
Copy link
Owner

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?

Copy link
Collaborator Author

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.

grote pushed a commit that referenced this pull request Sep 25, 2016
@grote grote closed this Sep 25, 2016
@jamescr
Copy link
Collaborator Author

jamescr commented Oct 1, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants