From f1f4531ce644e6bb4dd2af71ca38586e864aa19e Mon Sep 17 00:00:00 2001 From: aeronaut Date: Sun, 9 Nov 2014 22:20:05 +0100 Subject: [Keep2shareCc] Account plugin --- module/plugins/accounts/Keep2shareCc.py | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 module/plugins/accounts/Keep2shareCc.py (limited to 'module/plugins/accounts/Keep2shareCc.py') diff --git a/module/plugins/accounts/Keep2shareCc.py b/module/plugins/accounts/Keep2shareCc.py new file mode 100644 index 000000000..fa0c9d2e7 --- /dev/null +++ b/module/plugins/accounts/Keep2shareCc.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +import re + +from time import gmtime, mktime, strptime + +from module.plugins.Account import Account + + +class Keep2shareCc(Account): + __name__ = "Keep2shareCC" + __type__ = "account" + __version__ = "0.01" + + __description__ = """Keep2share.cc account plugin""" + __license__ = "GPLv3" + __authors__ = [("aeronaut", "aeronaut@pianoguy.de")] + + + VALID_UNTIL_PATTERN = r'Premium expires: (.+?)' + TRAFFIC_LEFT_PATTERN = r'Available traffic \(today\):(.+?)' + + LOGIN_FAIL_PATTERN = r'Please fix the following input errors' + + + def loadAccountInfo(self, user, req): + validuntil = None + trafficleft = None + premium = None + + html = req.load("http://keep2share.cc/site/profile.html", decode=True) + + m = re.search(self.VALID_UNTIL_PATTERN, html) + if m: + expiredate = m.group(1).strip() + self.logDebug("Expire date: " + expiredate) + + try: + validuntil = mktime(strptime(expiredate, "%Y.%m.%d")) + + except Exception, e: + self.logError(str(e)) + + else: + if validuntil > mktime(gmtime()): + premium = True + else: + premium = False + validuntil = None + + m = re.search(self.TRAFFIC_LEFT_PATTERN, html) + if m: + try: + trafficleft = self.parseTraffic(m.group(1)) + + except Exception, e: + self.logError(str(e)) + + return {'validuntil': validuntil, 'trafficleft': trafficleft, 'premium': premium} + + + def login(self, user, data, req): + req.cj.setCookie(".keep2share.cc", "lang", "en") + + html = req.load("http://keep2share.cc/login.html", + post={'LoginForm[username]': user, 'LoginForm[password]': data["password"]}) + + if re.search(self.LOGIN_FAIL_PATTERN, html): + self.wrongPassword() -- cgit v1.2.3 From 0516e8553608950db9f4ca13138ee1c3557ddc16 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 22:55:25 +0100 Subject: [Keep2shareCc] Fix account __name__ --- module/plugins/accounts/Keep2shareCc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/accounts/Keep2shareCc.py') diff --git a/module/plugins/accounts/Keep2shareCc.py b/module/plugins/accounts/Keep2shareCc.py index fa0c9d2e7..22682e247 100644 --- a/module/plugins/accounts/Keep2shareCc.py +++ b/module/plugins/accounts/Keep2shareCc.py @@ -8,9 +8,9 @@ from module.plugins.Account import Account class Keep2shareCc(Account): - __name__ = "Keep2shareCC" + __name__ = "Keep2shareCc" __type__ = "account" - __version__ = "0.01" + __version__ = "0.02" __description__ = """Keep2share.cc account plugin""" __license__ = "GPLv3" @@ -63,7 +63,7 @@ class Keep2shareCc(Account): req.cj.setCookie(".keep2share.cc", "lang", "en") html = req.load("http://keep2share.cc/login.html", - post={'LoginForm[username]': user, 'LoginForm[password]': data["password"]}) + post={'LoginForm[username]': user, 'LoginForm[password]': data['password']}) if re.search(self.LOGIN_FAIL_PATTERN, html): self.wrongPassword() -- cgit v1.2.3 From c9e31d875d32de31e54959b82bc35eff2b3e0f3f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 10 Nov 2014 00:19:51 +0100 Subject: Code cosmetics --- module/plugins/accounts/Keep2shareCc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/accounts/Keep2shareCc.py') diff --git a/module/plugins/accounts/Keep2shareCc.py b/module/plugins/accounts/Keep2shareCc.py index 22682e247..de9b9b5d8 100644 --- a/module/plugins/accounts/Keep2shareCc.py +++ b/module/plugins/accounts/Keep2shareCc.py @@ -39,7 +39,7 @@ class Keep2shareCc(Account): validuntil = mktime(strptime(expiredate, "%Y.%m.%d")) except Exception, e: - self.logError(str(e)) + self.logError(e) else: if validuntil > mktime(gmtime()): @@ -54,7 +54,7 @@ class Keep2shareCc(Account): trafficleft = self.parseTraffic(m.group(1)) except Exception, e: - self.logError(str(e)) + self.logError(e) return {'validuntil': validuntil, 'trafficleft': trafficleft, 'premium': premium} -- cgit v1.2.3