-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new script so you can do xml filename required... from the cl…
…i instead of xml filename required...
- Loading branch information
1 parent
c0baaa7
commit 002e82b
Showing
3 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,3 +103,5 @@ venv.bak/ | |
# mypy | ||
.mypy_cache/ | ||
|
||
# IDEs | ||
.idea |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
|
||
import xmltojson | ||
|
||
def main(): | ||
|
||
if not len(sys.argv) > 1: | ||
print('xml filename required...') | ||
sys.exit(1) | ||
|
||
xml_filename = sys.argv[1] | ||
|
||
option_version = ['v', '-v', '--v', 'version', '-version', '--version'] | ||
option_file = ['f', '-f', '--f', 'file', '-file', '--file'] | ||
|
||
if xmltojson._lists_share_element(sys.argv, option_version): | ||
xmltojson._usage() | ||
sys.exit() | ||
|
||
if not os.path.exists(xml_filename): | ||
print('File not found...') | ||
sys.exit(1) | ||
|
||
# Create filename for json output file | ||
json_filename = xmltojson._tr_xml_to_json_extension(xml_filename) | ||
|
||
# Grab xml from file | ||
xml_string = xmltojson._read_xml_file(xml_filename) | ||
|
||
# Translate xml to json from the string we got | ||
json_obj = xmltojson.parse(xml_string) | ||
|
||
# Create json output file | ||
if xmltojson._lists_share_element(sys.argv, option_file): | ||
xmltojson._write_output_file(json_filename, json_obj) | ||
else: | ||
print(json_obj) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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