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

Only append '.json' to output file name if it is not already present #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

beatboxchad
Copy link

@beatboxchad beatboxchad commented Jan 6, 2017

python wig.py www.beatboxchad.com -w ~/foo.json created a file named ~/foo.json.json. Now that's fixed.

@@ -97,7 +97,8 @@ def add_error(self, msg):

def write_file(self):
file_name = self.options['write_file']
with open(file_name+ '.json', 'w') as fh:
file_name = file_name if re.search(r'\.json\s*$', file_name) else file_name + '.json'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the line above could be simplified to

file_name = re.sub('(\.json)?\s*$', '', self.options['write_file']) + '.json'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hey, that's very elegant. I'm going to do that now. Thank you!

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