From 7a7e3e211e36af06d00e0effbcc37ac59e152427 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Tue, 8 Jul 2014 20:00:23 +0200 Subject: nopremium.pl files added --- module/plugins/accounts/NoPremiumPl.py | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 module/plugins/accounts/NoPremiumPl.py (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py new file mode 100644 index 000000000..e44a6acff --- /dev/null +++ b/module/plugins/accounts/NoPremiumPl.py @@ -0,0 +1,102 @@ +# !/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +@author: Pawel W. +""" + +from datetime import datetime + +from module.plugins.Account import Account +from module.plugins.internal.SimpleHoster import parseHtmlForm +import re +from time import mktime, strptime +import module.lib.beaker.crypto as crypto + +try: + from json import loads +except ImportError: + from simplejson import loads + +class NoPremiumPl(Account): + __name__ = "NoPremiumPl" + __version__ = "0.01" + __type__ = "account" + __description__ = "NoPremium.pl account plugin" + __author_name__ = ("goddie") + __author_mail__ = ("dev@nopremium.pl") + + _api_url = "http://crypt.nopremium.pl" + + _api_query = { + "site": "nopremium", + "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: ret? + return + + premium = False + valid_untill = -1 + + is_premium = "expire" in result.keys() and result["expire"] is not None + + if is_premium: + + premium = True + valid_untill = mktime(datetime.fromtimestamp(int(result["expire"])).timetuple()) + + traffic_left = result["balance"] * 1024 + + return ({ + "validuntil": valid_untill, + "trafficleft": traffic_left, + "premium": premium + }) + + def login(self, user, data, req): + + self._usr = user + self._pwd = crypto.sha1(crypto.md5(data["password"]).hexdigest()).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 -- cgit v1.2.3 From 4a33d2e93055299e0108a23e0f2615e5cfd422f2 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Tue, 8 Jul 2014 20:12:15 +0200 Subject: to-do elaborate --- module/plugins/accounts/NoPremiumPl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index e44a6acff..7ba89b881 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -48,7 +48,7 @@ class NoPremiumPl(Account): try: result = loads(self.runAuthQuery()) except: - #todo: ret? + #todo: return or let it be thrown? return premium = False -- cgit v1.2.3 From ccf15e75c12ad1e8347fdff834f8c62e5e2ab617 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Tue, 8 Jul 2014 21:33:01 +0200 Subject: remove redundant author information --- module/plugins/accounts/NoPremiumPl.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 7ba89b881..8cfdbe1a7 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -1,10 +1,6 @@ # !/usr/bin/env python # -*- coding: utf-8 -*- -""" -@author: Pawel W. -""" - from datetime import datetime from module.plugins.Account import Account -- cgit v1.2.3 From e325412cd71ae329f3f0b7084e5989e6ffbdbd18 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 11:57:05 +0200 Subject: remove enviroment line --- module/plugins/accounts/NoPremiumPl.py | 1 - 1 file changed, 1 deletion(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 8cfdbe1a7..df9e94a42 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python # -*- coding: utf-8 -*- from datetime import datetime -- cgit v1.2.3 From 352301e4892d311d1a4cf6127f6bc70bc23eede3 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 12:02:59 +0200 Subject: remove blank lines and unused imports --- module/plugins/accounts/NoPremiumPl.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index df9e94a42..494b559c3 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -3,9 +3,7 @@ from datetime import datetime from module.plugins.Account import Account -from module.plugins.internal.SimpleHoster import parseHtmlForm -import re -from time import mktime, strptime +from time import mktime import module.lib.beaker.crypto as crypto try: @@ -13,6 +11,7 @@ try: except ImportError: from simplejson import loads + class NoPremiumPl(Account): __name__ = "NoPremiumPl" __version__ = "0.01" @@ -37,38 +36,31 @@ class NoPremiumPl(Account): _pwd = None def loadAccountInfo(self, name, req): - self._req = req - try: result = loads(self.runAuthQuery()) except: - #todo: return or let it be thrown? + # todo: return or let it be thrown? return premium = False valid_untill = -1 - is_premium = "expire" in result.keys() and result["expire"] is not None if is_premium: - premium = True valid_untill = mktime(datetime.fromtimestamp(int(result["expire"])).timetuple()) - traffic_left = result["balance"] * 1024 return ({ - "validuntil": valid_untill, - "trafficleft": traffic_left, - "premium": premium - }) + "validuntil": valid_untill, + "trafficleft": traffic_left, + "premium": premium + }) def login(self, user, data, req): - self._usr = user self._pwd = crypto.sha1(crypto.md5(data["password"]).hexdigest()).hexdigest() - self._req = req try: @@ -78,12 +70,10 @@ class NoPremiumPl(Account): 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 @@ -91,7 +81,6 @@ class NoPremiumPl(Account): return query def runAuthQuery(self): - data = self._req.load(self._api_url, post=self.createAuthQuery()) return data \ No newline at end of file -- cgit v1.2.3 From ce18793af9864acdf9e9c71b7324d923a53adaad Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 12:05:22 +0200 Subject: fix json loads, dumps on ImportError exception --- module/plugins/accounts/NoPremiumPl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 494b559c3..7b4140169 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -7,9 +7,10 @@ from time import mktime import module.lib.beaker.crypto as crypto try: - from json import loads + from json import loads, dumps except ImportError: - from simplejson import loads + from module.common.json_layer import json_loads as loads + from module.common.json_layer import json_dumps as dumps class NoPremiumPl(Account): -- cgit v1.2.3 From dfd5cb44138494b803f66559747cacc1260b5595 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 12:15:03 +0200 Subject: simplify json loads, replace crypto with hashlib --- module/plugins/accounts/NoPremiumPl.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 7b4140169..0f3b5286f 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -1,16 +1,12 @@ # -*- coding: utf-8 -*- from datetime import datetime +import hashlib from module.plugins.Account import Account from time import mktime -import module.lib.beaker.crypto as crypto -try: - from json import loads, dumps -except ImportError: - from module.common.json_layer import json_loads as loads - from module.common.json_layer import json_dumps as dumps +from module.common.json_layer import json_loads as loads class NoPremiumPl(Account): @@ -61,7 +57,7 @@ class NoPremiumPl(Account): def login(self, user, data, req): self._usr = user - self._pwd = crypto.sha1(crypto.md5(data["password"]).hexdigest()).hexdigest() + self._pwd = hashlib.sha1(hashlib.md5(data["password"]).hexdigest()).hexdigest() self._req = req try: -- cgit v1.2.3 From 0fc351436bfb4a94749899e34c46bf81a44c92c9 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 12:16:36 +0200 Subject: replace is_premium with direct expression --- module/plugins/accounts/NoPremiumPl.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 0f3b5286f..49c9b7653 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -42,9 +42,8 @@ class NoPremiumPl(Account): premium = False valid_untill = -1 - is_premium = "expire" in result.keys() and result["expire"] is not None - if is_premium: + if "expire" in result.keys() and result["expire"] is not None: premium = True valid_untill = mktime(datetime.fromtimestamp(int(result["expire"])).timetuple()) traffic_left = result["balance"] * 1024 -- cgit v1.2.3 From 1df1779ded75e863994449ba034ed31ab2018ddc Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 12:40:13 +0200 Subject: remove explicit "is not None" --- module/plugins/accounts/NoPremiumPl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 49c9b7653..5f70440ac 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -43,7 +43,7 @@ class NoPremiumPl(Account): premium = False valid_untill = -1 - if "expire" in result.keys() and result["expire"] is not None: + if "expire" in result.keys() and result["expire"]: premium = True valid_untill = mktime(datetime.fromtimestamp(int(result["expire"])).timetuple()) traffic_left = result["balance"] * 1024 -- cgit v1.2.3 From 0824528da43d0842c15ffa0d4fe132309ca592eb Mon Sep 17 00:00:00 2001 From: synweap15 Date: Wed, 9 Jul 2014 14:05:40 +0200 Subject: newline fix --- module/plugins/accounts/NoPremiumPl.py | 1 - 1 file changed, 1 deletion(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index 5f70440ac..bf1aec841 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -5,7 +5,6 @@ import hashlib from module.plugins.Account import Account from time import mktime - from module.common.json_layer import json_loads as loads -- cgit v1.2.3 From 168f175ce4765dec7e847c45d95e4babe20a7193 Mon Sep 17 00:00:00 2001 From: synweap15 Date: Mon, 3 Nov 2014 14:42:05 +0100 Subject: New __authors__ key, added __license__ --- module/plugins/accounts/NoPremiumPl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/accounts/NoPremiumPl.py') diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py index bf1aec841..f2223b7d9 100644 --- a/module/plugins/accounts/NoPremiumPl.py +++ b/module/plugins/accounts/NoPremiumPl.py @@ -13,8 +13,8 @@ class NoPremiumPl(Account): __version__ = "0.01" __type__ = "account" __description__ = "NoPremium.pl account plugin" - __author_name__ = ("goddie") - __author_mail__ = ("dev@nopremium.pl") + __license__ = "GPLv3" + __authors__ = [("goddie", "dev@nopremium.pl")] _api_url = "http://crypt.nopremium.pl" -- cgit v1.2.3