Revision: 5480 Author: btongminh Date: 2008-05-31 10:14:01 +0000 (Sat, 31 May 2008)
Log Message: ----------- Add optional API login. Add wpSkipCookieCheck to regular login.
Modified Paths: -------------- trunk/pywikipedia/config.py trunk/pywikipedia/login.py
Modified: trunk/pywikipedia/config.py =================================================================== --- trunk/pywikipedia/config.py 2008-05-31 09:20:52 UTC (rev 5479) +++ trunk/pywikipedia/config.py 2008-05-31 10:14:01 UTC (rev 5480) @@ -69,6 +69,9 @@ # By default you are asked for a password on the terminal. password_file = None
+# Login using the API. This is less likely to break. +use_api_login = False + # Get the names of all known families, and initialize # with empty dictionaries import wikipediatools as _wt
Modified: trunk/pywikipedia/login.py =================================================================== --- trunk/pywikipedia/login.py 2008-05-31 09:20:52 UTC (rev 5479) +++ trunk/pywikipedia/login.py 2008-05-31 10:14:01 UTC (rev 5480) @@ -106,17 +106,27 @@
Returns cookie data if succesful, None otherwise. """ - predata = { - "wpName": self.username.encode(self.site.encoding()), - "wpPassword": self.password, - "wpDomain": self.site.family.ldapDomain, # VistaPrint fix - "wpLoginattempt": "Aanmelden & Inschrijven", # dutch button label seems to work for all wikis - "wpRemember": str(int(bool(remember))) - } - if captchaId: - predata["wpCaptchaId"] = captchaId - predata["wpCaptchaWord"] = captchaAnswer - address = self.site.login_address() + if config.use_api_login: + predata = { + 'action': 'login', + 'lgname': self.username.encode(self.site.encoding()), + 'lgpassword': self.password, + 'lgdomain': self.site.family.ldapDomain, + } + address = self.site.api_address() + else: + predata = { + "wpName": self.username.encode(self.site.encoding()), + "wpPassword": self.password, + "wpDomain": self.site.family.ldapDomain, # VistaPrint fix + "wpLoginattempt": "Aanmelden & Inschrijven", # dutch button label seems to work for all wikis + "wpRemember": str(int(bool(remember))), + "wpSkipCookieCheck": '1' + } + if captchaId: + predata["wpCaptchaId"] = captchaId + predata["wpCaptchaWord"] = captchaAnswer + address = self.site.login_address()
if self.site.hostname() in config.authenticate.keys(): headers = { @@ -140,18 +150,13 @@ n += 1 L.append(m.group(1))
+ got_token = False log_data = [] for Ldata in L: - if (re.match('.*_session=.*', Ldata)): - log_data.append(Ldata) - elif (re.match('.*UserID=.*', Ldata)): - log_data.append(Ldata) - elif (re.match('.*UserName=.*', Ldata)): - log_data.append(Ldata) - elif (re.match('.*Token=.*', Ldata)): - log_data.append(Ldata) - - if len(log_data) == 4: + if 'Token=' in Ldata: + got_token = True + + if got_token: return "\n".join(L) elif not captchaAnswer: captchaR = re.compile('<input type="hidden" name="wpCaptchaId" id="wpCaptchaId" value="(?P<id>\d+)" />')