Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Timeout Variable for long requests #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions alchemyapi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2013 AlchemyAPI
# Copyright 2013 AlchemyAPI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -136,8 +136,11 @@ class AlchemyAPI:

s = requests.Session()

# Timeout for the request sent to api
timeout = None

def __init__(self):
"""
"""
Initializes the SDK so it can send requests to AlchemyAPI for analysis.
It loads the API key from api_key.txt and configures the endpoints.
"""
Expand Down Expand Up @@ -179,6 +182,12 @@ def __init__(self):
except Exception as e:
print(e)

def setTimeout(self,interval):
"""
Sets the timeout for the request parameter.
"""
self.timeout = interval

def entities(self, flavor, data, options={}):
"""
Extracts the entities for text, a URL or HTML.
Expand Down Expand Up @@ -302,7 +311,7 @@ def sentiment_targeted(self, flavor, data, target, options={}):
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.

Available Options:
showSourceText -> 0: disabled, 1: enabled
showSourceText -> 0: disabled, 1: enabled

OUTPUT:
The response, already converted from JSON to a Python object.
Expand Down Expand Up @@ -767,7 +776,7 @@ def __analyze(self, endpoint, params, post_data=bytearray()):

results = ""
try:
results = self.s.post(url=post_url, data=post_data)
results = self.s.post(url=post_url, data=post_data, timeout = self.timeout)
except Exception as e:
print(e)
return {'status': 'ERROR', 'statusInfo': 'network-error'}
Expand Down