Created
October 19, 2012 18:18
-
-
Save dangra/3919769 to your computer and use it in GitHub Desktop.
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
diff --git a/scrapinghub.py b/scrapinghub.py | |
index 1754af7..b4c9bc6 100644 | |
--- a/scrapinghub.py | |
+++ b/scrapinghub.py | |
@@ -1,16 +1,15 @@ | |
-"""Scrapinghub API Client Library""" | |
+""" | |
+Scrapinghub API Client Library | |
+""" | |
import os | |
import json | |
import warnings | |
-import requests | |
from cStringIO import StringIO | |
-from requests.compat import urljoin | |
-from requests.models import urlencode | |
- | |
__all__ = ["APIError", "Connection"] | |
+__version__ = '1.0' | |
class Connection(object): | |
@@ -46,13 +45,14 @@ class Connection(object): | |
self.url = url | |
self.username_or_apikey = username_or_apikey | |
self.auth = (username_or_apikey, password) | |
- self._request_headers = {'User-Agent': 'python-scrapinghub/1.0'} | |
+ self._request_headers = {'User-Agent': 'python-scrapinghub/{0}'.format(__version__)} | |
def __repr__(self): | |
return "Connection(%r)" % self.username_or_apikey | |
def _build_url(self, method, format): | |
"""Returns full url for given method and format""" | |
+ from requests.compat import urljoin | |
# TODO: verify method's format support | |
try: | |
base_path = self.API_METHODS[method] | |
@@ -64,6 +64,7 @@ class Connection(object): | |
def _get(self, method, format, params=None, headers=None, raw=False): | |
"""Performs GET request""" | |
+ from requests.models import urlencode | |
url = self._build_url(method, format) | |
if params: | |
url = "{0}?{1}".format(url, urlencode(params, True)) | |
@@ -84,6 +85,7 @@ class Connection(object): | |
Raises APIError if json response have error status. | |
""" | |
+ import requests | |
if format not in ('json', 'jl'): | |
raise APIError("format must be either json or jl") | |
diff --git a/setup.py b/setup.py | |
index 62d6348..bb35af7 100644 | |
--- a/setup.py | |
+++ b/setup.py | |
@@ -1,10 +1,12 @@ | |
+from scrapinghub import __version__ | |
try: | |
from setuptools import setup | |
except ImportError: | |
from distutils.core import setup | |
+ | |
setup(name='scrapinghub', | |
- version='0.2', | |
+ version=__version__, | |
license='BSD', | |
description='Client interface for Scrapinghub API', | |
author='Scrapinghub', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment