diff --git a/README.md b/README.md index fa91acb..c73803c 100644 --- a/README.md +++ b/README.md @@ -1,80 +1,89 @@ -## Post XML files to a server port +# XML_postToREST + +XML_postToREST is a Python program for posting DOIs metadata in XML format to DataCite REST API
-### Step 1 +## Getting Started + +`xml_post_parser.py` is the program you will call to do the task + +It will call two python classes: +* `class_xml_encode.py`: encode XML files to JSON envelope + +* `class_json_post.py`: post JSON envelopes to server port +
-Check the `"xml_post_parser_config.json"` file for the configurations of the codes +## Usage + +Check the configuration file `xml_post_parser_config.json` and start configure your program:
+ **Important fields** -`"server_port"`: +``` +"server_port": the location you want to post your files to -`"bearer_auth_key"`: +"bearer_auth_key": your Bearer Auth key to access DataCite REST API -`"prefix"`: +"prefix": namespace of the DOIs you are using -`"schema_url"`: +"schema_url": schema for the DOIs +``` -
**Folder names** -`"xml_folder"`: +``` +"xml_folder": the directory for your input XML files -`"json_folder"`: +"json_folder": the directory for your JSON envelopes to be stored at -`"processed_xml_folder"`: +"processed_xml_folder": the directory for your processed XML files -`"posted_json_folder"`: +"posted_json_folder": the directory for your successfully posted JSON envelopes -`"post_failed_folder"`: +"post_failed_folder": the directory for your JSON envelopes that failed to post +```
+---------------------------------------- -### Step 2 - -
- -From the config file, use the value of `"xml_folder"` as the name to create a folder in the same directory +Then from the config file, use the value of `"xml_folder"` as the name to create a folder in the same directory Store your xml files to be posted to the folder
-### Step 3 - -
- -Run the python script +Last, run `xml_post_parser.py` -```python +``` python python xml_post_parser.py ``` -The XML files will now begin to be encoded into JSON files and then posted to the server port +XML files will begin to be encoded into JSON files and then posted to the server port **Successfully posted** files will be stored at `"posted_json_folder"` @@ -82,24 +91,12 @@ The XML files will now begin to be encoded into JSON files and then posted to th
-## Additional files +## Additional file for testing -
- -`clear_folders.py`: +`tests/test_server.py`: -empty all folders after posting (except `"xml_src"`) - -
- -`test_server.py`: - -construct a dummy server using port 5000 in localhost - -you can view the posted json files on http://localhost:5000/data - -run `test_server.py` in one terminal and `xml_post_parser.py` in another +construct a dummy server at http://localhost:5000 +you can post data to http://localhost:5000 and view the posted data on http://localhost:5000/data ***Remember to change "server_port" in the config file to http://localhost:5000/*** - diff --git a/json_post.py b/class_json_post.py similarity index 100% rename from json_post.py rename to class_json_post.py diff --git a/xml_encode.py b/class_xml_encode.py similarity index 100% rename from xml_encode.py rename to class_xml_encode.py diff --git a/clear_folders.py b/clear_folders.py deleted file mode 100644 index 3f79f65..0000000 --- a/clear_folders.py +++ /dev/null @@ -1,18 +0,0 @@ -import os -import json - -# load folders to be cleared -CONFIG_FILE = './xml_post_parser_config.json' -with open(CONFIG_FILE, "rb") as config_f: - config = json.load(config_f) - -clear_folders = [config["json_folder"], config["processed_xml_folder"], config["posted_json_folder"], config["post_failed_folder"]] - -for folder in clear_folders: - for filename in os.listdir(folder): - file_path = os.path.join(folder, filename) - try: - if os.path.isfile(file_path) or os.path.islink(file_path): - os.unlink(file_path) - except Exception as e: - print("Failed to delete %s. Reason: %s" % (file_path, e)) diff --git a/test_server.py b/tests/test_server.py similarity index 100% rename from test_server.py rename to tests/test_server.py diff --git a/xml_post_parser.py b/xml_post_parser.py index e2e5bb8..8120164 100644 --- a/xml_post_parser.py +++ b/xml_post_parser.py @@ -1,5 +1,5 @@ -import xml_encode -import json_post +import class_xml_encode as xml_encode +import class_json_post as json_post from os import listdir from os.path import isfile, join import os