Skip to content

Commit 9e4c4b1

Browse files
committed
Release 1.1.2
Added new function (uploadbase64)
1 parent f7a3e39 commit 9e4c4b1

File tree

11 files changed

+1732
-370
lines changed

11 files changed

+1732
-370
lines changed

.idea/PyDocParser.iml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
### Release V1.1.2 (1/14/20)
4+
5+
### Added:
6+
* `uploadbase64()`
7+
38
### Release V1.1 (7/12/19)
49

510
#### Added:

docs/PyDocParser Documentation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Parser.**upload(*file*, *parser*)**
3636

3737
This function is used to upload a file to docparser. The `file` argument is the filename to open and send to the parser. (Note: the file must be accessible to the python script that is being executed.) The `parser` argument is the name of the parser to send the data to. After uploading, the function returns the document ID number.
3838

39+
Parser.**uploadbase64(*file_base64*, *parser*, *filename*)***
40+
41+
This function does the same thing as the `Parser.upload()` function, however, this function accepts a file already encoded as **base64**. The `file_base64` argument is the file encoded as base64. he `parser` argument is the name of the parser to send the data to. Since no file object is being passed through, a `filename` must be passed through so the parser has a way of naming the file. After uploading, the function returns the document ID number.
42+
3943
Parser.**upload_id(*file*, *parser_id*)**
4044

4145
This function is used to upload a file to docparser. The `file` argument is the filename to open and send to the parser. (Note: the file must be accessible to the python script that is being executed.) The `parser_id` argument is the id of the parser to send the data to. After uploading, the function returns the document ID number.

docs/changelog.html

Lines changed: 1664 additions & 338 deletions
Large diffs are not rendered by default.

docs/docs.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,14 @@ <h2><a name="functions" class="md-header-anchor"></a><span>Functions</span></h2>
16791679
</p>
16801680
<p><span>This function is used to upload a file to docparser. The </span><code>file</code><span> argument is the filename to open and send to the parser. (Note: the file must be accessible to the python script that is being executed.) The </span><code>parser</code><span> argument is the name of the parser to send the data to. After uploading, the function returns the document ID number.</span>
16811681
</p>
1682+
1683+
<p>
1684+
<span>Parser.</span><strong><span>uploadbase64(</span><em><span>file_base64</span></em><span>, </span><em><span>parser</span></em>
1685+
<span>, </span> <em><span>filename</span></em> <span>)</span></strong>
1686+
</p>
1687+
<p><span>This function does the same thing as the </span> <code>Parser.upload()</code> <span>function, however, this function accepts a file already encoded as <em>base64</em>. The </span><code>file_base64</code><span> argument is the file encoded as base64. he </span><code>parser</code><span> argument is the name of the parser to send the data to. Since no file object is being passed through, a </span><code>filename</code><span> must be passed through so the parser has a way of naming the file. After uploading, the function returns the document ID number.</span>
1688+
</p>
1689+
16821690
<p>
16831691
<span>Parser.</span><strong><span>upload_id(</span><em><span>file</span></em><span>, </span><em><span>parser_id</span></em><span>)</span></strong>
16841692
</p>

docs/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,8 +2172,11 @@ <h2><a name="unofficial-python-client-for-the-docparser-api" class="md-header-an
21722172
href='https://github.com/tman540/PyDocParser/blob/master/LICENSE.md'><span>MIT License</span></a><span>.</span>
21732173
</p><br><h4><a name="changelog" class="md-header-anchor"></a><span>Changelog</span></h4>
21742174
<p><span>V1.0 (7/11/19) Initial release</span></p>
2175-
<p><span><a href="changelog.html">V1.1 (7/12/19) Bug Fixes + New Functions</a></span></p><br><h4><a name="to-do"
2176-
class="md-header-anchor"></a><span>To-Do</span></h4>
2175+
<p><span><a href="changelog.html">V1.1 (7/12/19) Bug Fixes + New Functions</a></span></p>
2176+
<p><span><a href="changelog.html">V1.1.2 (1/14/10) New Function</a></span></p>
2177+
<br>
2178+
<h4><a name="to-do"
2179+
class="md-header-anchor"></a><span>To-Do</span></h4>
21772180
<ul>
21782181
<li class='md-task-list-item task-list-item task-list-not-done'><input type='checkbox' disabled='disabled'/>
21792182
<p><span>Change function names to more closely resemble those in the PHP/Node/AJAX clients</span></p></li>

pydocparser/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ def get_parsers(self, *verbose) -> dict or list:
8888
parsers.append(item["label"])
8989
return parsers
9090

91+
def uploadbase64(self, file_base64, parser, filename) -> str or None:
92+
"""
93+
Upload a file to docparser (already in base64 format)
94+
:param file_base64: The name of the file to upload
95+
:type file_base64: str
96+
:param parser: The name of the parser to send the file to
97+
:type parser: str
98+
:param filename: Filename of the file
99+
:type filename: str
100+
:return: The file id if the upload was successful, otherwise None
101+
"""
102+
payload = {
103+
"file_content": file_base64,
104+
"file_name": filename
105+
}
106+
107+
parser_id = self.find_parser_id(parser)
108+
result = requests.post("https://api.docparser.com/v1/document/upload/{}".format(parser_id),
109+
auth=self.AUTH, data=payload)
110+
success = self.check_request(result)
111+
if success:
112+
result_loaded = loads(result.text)
113+
return result_loaded["id"]
114+
else:
115+
return None
116+
91117
def upload(self, file, parser) -> str or None:
92118
"""
93119
Upload a file to docparser

0 commit comments

Comments
 (0)