Skip to content
This repository has been archived by the owner on Jun 21, 2021. It is now read-only.

Commit

Permalink
Added Captcha Handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
psibi committed Jan 7, 2013
1 parent 3df174a commit 46363c7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mwuppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from yaml import load, dump
import re
import getpass
from StringIO import StringIO
from PIL import Image
import requests

MODE_REGEX = re.compile(r'page:\s?(\S*)', re.I)

Expand Down Expand Up @@ -46,7 +49,17 @@ def save_page(page, text, summary):
if not api.is_authenticated:
ensure_logged_in()

print api.post(action="edit", title=page, text=text, summary=summary, token=tokens['edittoken'])
result = api.post(action="edit", title=page, text=text, summary=summary, token=tokens['edittoken'])
print result
if 'captcha' in result['edit']:
captcha_url = result['edit']['captcha']['url']
url = "https://en.wikipedia.org" + captcha_url
response = requests.get(url)
i = Image.open(StringIO(response.content))
i.show()
captcha_id = result['edit']['captcha']['id']
captcha_word = raw_input("Enter Captcha Word: ")
print api.post(action="edit", title=page, text=text, summary=summary, token=tokens['edittoken'],captchaid=captcha_id,captchaword=captcha_word)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Sync code files with a Mediawiki installation")
Expand Down

0 comments on commit 46363c7

Please sign in to comment.