forked from hasgeek/hasjob
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functions and keys for accessing docspad.
- Loading branch information
1 parent
84369c8
commit 45945f1
Showing
3 changed files
with
46 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import requests | ||
from hasjob import app | ||
|
||
''' | ||
Returns the docId when the upload is successful. | ||
Input type is fileobject | ||
''' | ||
def upload(fileobject): | ||
resp = requests.post("http://apis.docspad.com/v1/upload.php", files={'doc':fileobject}, | ||
data={'key': app.config['DOCSPAD_CONSUMER_KEY']}) | ||
returned_vals = json.loads(resp.text) | ||
if 'error' in returned_vals: | ||
raise Exception(returned_vals['error']['msg']) | ||
else: | ||
return returned_vals['docId'] | ||
|
||
''' | ||
Returns the status (a dictionary of 'conversion_status' and 'file_status' received from Docspad for the given docId | ||
''' | ||
def get_status(docId): | ||
resp = requests.post("http://apis.docspad.com/v1/status.php", data={'key': app.config['DOCSPAD_CONSUMER_KEY'], | ||
'docId': docId}) | ||
returned_vals = json.loads(resp.text) | ||
if 'error' in returned_vals: | ||
raise Exception(returned_vals['error']['msg']) | ||
else: | ||
return returned_vals | ||
|
||
''' | ||
Returns the sessionId received from Docspad for the given docId | ||
''' | ||
def get_session(docId): | ||
resp = requests.post("http://apis.docspad.com/v1/session.php", data={'key': app.config['DOCSPAD_CONSUMER_KEY'], | ||
'docId':docId}) | ||
returned_vals = json.loads(resp.text) | ||
if 'error' in returned_vals: | ||
raise Exception(returned_vals['error']['msg']) | ||
else: | ||
return returned_vals['sessionId'] |
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
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