diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-27 14:37:29 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-27 14:37:29 +0100 |
commit | fd8d1bd2b86db4be1c9b7200a50982f80c0c5e58 (patch) | |
tree | df95fad760db41a2618db3aafe32b72e39983c85 /module/plugins/accounts | |
parent | [ShareonlineBiz] Fix account wrong password recognition (diff) | |
parent | New __authors__ key, added __license__ (diff) | |
download | pyload-fd8d1bd2b86db4be1c9b7200a50982f80c0c5e58.tar.xz |
Merge pull request #682 from synweap15/rapideo
MultihosterRapideo.pl
Diffstat (limited to 'module/plugins/accounts')
-rw-r--r-- | module/plugins/accounts/RapideoPl.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/module/plugins/accounts/RapideoPl.py b/module/plugins/accounts/RapideoPl.py new file mode 100644 index 000000000..438ce7ad3 --- /dev/null +++ b/module/plugins/accounts/RapideoPl.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- + +from datetime import datetime +import hashlib + +from module.plugins.Account import Account +from time import mktime +from module.common.json_layer import json_loads as loads + + +class RapideoPl(Account): + __name__ = "RapideoPl" + __version__ = "0.01" + __type__ = "account" + __description__ = "Rapideo.pl account plugin" + __license__ = "GPLv3" + __authors__ = [("goddie", "dev@rapideo.pl")] + + _api_url = "http://enc.rapideo.pl" + + _api_query = { + "site": "newrd", + "username": "", + "password": "", + "output": "json", + "loc": "1", + "info": "1" + } + + _req = None + _usr = None + _pwd = None + + def loadAccountInfo(self, name, req): + self._req = req + try: + result = loads(self.runAuthQuery()) + except: + # todo: return or let it be thrown? + return + + premium = False + valid_untill = -1 + if "expire" in result.keys() and result["expire"]: + premium = True + valid_untill = mktime(datetime.fromtimestamp(int(result["expire"])).timetuple()) + + traffic_left = result["balance"] + + return ({ + "validuntil": valid_untill, + "trafficleft": traffic_left, + "premium": premium + }) + + def login(self, user, data, req): + self._usr = user + self._pwd = hashlib.md5(data["password"]).hexdigest() + self._req = req + try: + response = loads(self.runAuthQuery()) + except: + self.wrongPassword() + + if "errno" in response.keys(): + self.wrongPassword() + data['usr'] = self._usr + data['pwd'] = self._pwd + + def createAuthQuery(self): + query = self._api_query + query["username"] = self._usr + query["password"] = self._pwd + + return query + + def runAuthQuery(self): + data = self._req.load(self._api_url, post=self.createAuthQuery()) + + return data
\ No newline at end of file |