Skip to content

Commit

Permalink
tests + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gotlium committed Nov 12, 2013
1 parent d3b6168 commit 54fad38
Show file tree
Hide file tree
Showing 25 changed files with 1,442 additions and 98 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: python
python:
- "2.6"
- "2.7"
before_install:
- export PIP_USE_MIRRORS=true
install:
- pip install -r requirements/tests.txt --use-mirrors
- pip install -r requirements/package.txt --use-mirrors
before_script:
- flake8 antigate
script:
- coverage run --branch --source=antigate test_cases.py
- coverage report --omit="test*"
branches:
only:
- master
- development
after_success: coveralls
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ruslan Askarov <[email protected]>
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include tox.ini
include requirements/*
recursive-exclude * .DS_Store
recursive-include antigate *.py
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
python test_cases.py
coverage:
export DJANGO_SETTINGS_MODULE=geoip.test_settings && \
coverage report --omit="antigate/test*"
sphinx:
cd docs && sphinx-build -b html -d .build/doctrees . .build/html
47 changes: 47 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Real-time captcha-to-text decodings
===================================

.. image:: https://api.travis-ci.org/gotlium/antigate.png?branch=master
:alt: Build Status
:target: https://travis-ci.org/gotlium/antigate
.. image:: https://coveralls.io/repos/gotlium/antigate/badge.png?branch=master
:target: https://coveralls.io/r/gotlium/antigate?branch=master
.. image:: https://pypip.in/v/antigate/badge.png
:alt: Current version on PyPi
:target: https://crate.io/packages/antigate/
.. image:: https://pypip.in/d/antigate/badge.png
:alt: Downloads from PyPi
:target: https://crate.io/packages/antigate/


Documentation available at `Read the Docs <http://antigate.readthedocs.org/>`_.


Installation:
-------------
Expand All @@ -21,13 +36,17 @@ Installation:
Usage:
------

.. code-block:: python
>>> from antigate import AntiGate
>>> print AntiGate('API-KEY', 'captcha.jpg')
If you wish to complain about a mismatch results, use ``abuse`` method.

**Example:**

.. code-block:: python
>>> from antigate import AntiGate
>>> gate = AntiGate('API-KEY', 'captcha.jpg')
>>> print gate
Expand All @@ -36,14 +55,22 @@ If you wish to complain about a mismatch results, use ``abuse`` method.
After all manipulations, you can get your balance:

.. code-block:: python
>>> print gate.balance()
Or get your statistics data:

.. code-block:: python
>>> print gate.stats()
Real time system load info:

.. code-block:: python
>>> print gate.load()
Expand All @@ -52,19 +79,26 @@ Customizing requests to API

Customize grab-lib preferences:

.. code-block:: python
>>> from antigate import AntiGate
>>> config = {'connect_timeout': 5, 'timeout': 60}
>>> gate = AntiGate('API-KEY', 'captcha.jpg', grab_config=config)
>>> print gate
Additional options for sending Captcha:

.. code-block:: python
>>> from antigate import AntiGate
>>> config = {'min_len': '3', 'max_len': '5', 'phrase': '2'}
>>> gate = AntiGate('API-KEY', 'captcha.jpg', send_config=config)
>>> print gate
Disable auto run and use methods manually:

.. code-block:: python
>>> from antigate import AntiGate
>>> gate = AntiGate('API-KEY', auto_run=False)
>>> captcha_id1 = gate.send('captcha1.jpg')
Expand All @@ -73,7 +107,20 @@ Disable auto run and use methods manually:
>>> print gate.get(captcha_id2)
Get results for multiple ids:

.. code-block:: python
>>> gate = AntiGate('API-KEY', auto_run=False)
>>> captcha_id1 = gate.send('captcha1.jpg')
>>> captcha_id2 = gate.send('captcha2.jpg')
>>> print gate.get_multi([captcha_id1, captcha_id2])
Compatibility:
-------------
* Python: 2.6, 2.7, 3.3


.. image:: https://d2weczhvl823v0.cloudfront.net/gotlium/antigate/trend.png
:alt: Bitdeli badge
:target: https://bitdeli.com/free
92 changes: 0 additions & 92 deletions antigate.py

This file was deleted.

14 changes: 10 additions & 4 deletions antigate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# -*- coding: utf-8 -*-

from urllib import urlencode
from logging import getLogger
from datetime import datetime

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
from xmltodict import parse
from sys import exc_info
from time import sleep

from grab import Grab, UploadFile
Expand All @@ -19,7 +24,6 @@ class AntiGateError(Exception):


class AntiGate(object):

def __init__(self, key, filename='', auto_run=True,
grab_config=None, send_config=None,
domain='antigate.com'):
Expand Down Expand Up @@ -94,7 +98,8 @@ def send(self, filename):
while True:
try:
return self._send(filename)
except AntiGateError, msg:
except AntiGateError:
msg = exc_info()[1]
self.logger.debug(msg)
if str(msg) != 'ERROR_NO_SLOT_AVAILABLE':
raise AntiGateError(msg)
Expand All @@ -111,7 +116,8 @@ def get(self, captcha_id=None):
while True:
try:
return self._get(captcha_id)
except AntiGateError, msg:
except AntiGateError:
msg = exc_info()[1]
self.logger.debug(msg)
if str(msg) == 'CAPCHA_NOT_READY':
sleep(5)
Expand Down
Binary file added captcha/123.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added captcha/456.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 54fad38

Please sign in to comment.