From 14589e57e894552e25b9ae00075fc96c0632bd4b Mon Sep 17 00:00:00 2001 From: Date: Thu, 29 Mar 2018 23:26:12 +0800 Subject: [PATCH] add appid and user-agent to every request --- rarbgapi/rarbgapi.py | 19 ++++++++++++++++++- setup.py | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/rarbgapi/rarbgapi.py b/rarbgapi/rarbgapi.py index 947dd89..cccd701 100644 --- a/rarbgapi/rarbgapi.py +++ b/rarbgapi/rarbgapi.py @@ -1,5 +1,6 @@ import time import logging +import platform import requests @@ -74,15 +75,31 @@ class _RarbgAPIv2(object): https://torrentapi.org/apidocs_v2.txt ''' ENDPOINT = 'http://torrentapi.org/pubapi_v2.php' + APP_ID = 'rarbgapi' def __init__(self): super(_RarbgAPIv2, self).__init__() self._endpoint = self.ENDPOINT + def _get_user_agent(self): + return '{appid}/0.1.1 ({uname}) python {pyver}'.format( + appid=self.APP_ID, + uname='; '.join(platform.uname()), + pyver=platform.python_version()) + # pylint: disable=no-self-use def _requests(self, method, url, params=None): + if not params: + params = dict() + params.update({ + 'app_id': self.APP_ID + }) + + headers = { + 'user-agent': self._get_user_agent() + } sess = requests.Session() - req = requests.Request(method, url, params=params) + req = requests.Request(method, url, params=params, headers=headers) preq = req.prepare() resp = sess.send(preq) resp.raise_for_status() diff --git a/setup.py b/setup.py index 6e4013b..63f2888 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="RarbgAPI", - version="0.1", + version="0.1.1", author="verybada", author_email="verybada.lin@gmail.com", description=("A simple interface of RARBG.to"),