-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
travis: py3.2 doesn't seem to support tornado>4.3
so use tornado 4.3 when python 3.2, otherwise newest tornado
- Loading branch information
Showing
5 changed files
with
262 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Recaptcha test</title> | ||
|
||
<script src='https://www.google.com/recaptcha/api.js'></script> | ||
</head> | ||
<body> | ||
<form action="http://localhost:2737/suggest" method="get"> | ||
<span>Language pair</span> | ||
<input type="text" name="langpair" placeholder='eng|esp'> | ||
<br> | ||
<span>Context</span> | ||
<input type="text" name='context' placeholder='context'> | ||
<br> | ||
<span>word</span> | ||
<input type="text" name='word' placeholder='word'> | ||
<br> | ||
<span>newword</span> | ||
<input type="text" name='newWord' placeholder='newWord'> | ||
|
||
|
||
<div class="g-recaptcha" data-sitekey="6LedqOgSAAAAAKEbYmAXZTTahn8H08JuO0b2BmE3"></div> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
import json | ||
|
||
WIKI_API_URL = 'http://wiki.apertium.org/w/api.php' | ||
|
||
|
||
# Apertium Wiki utility functions | ||
def wikiLogin(s, loginName, password): | ||
try: | ||
payload = {'action': 'login', 'format': 'json', 'lgname': loginName, 'lgpassword': password} | ||
authResult = s.post(WIKI_API_URL, params=payload) | ||
authToken = json.loads(authResult.text)['login']['token'] | ||
logging.debug('Auth token: {}'.format(authToken)) | ||
|
||
payload = {'action': 'login', 'format': 'json', 'lgname': loginName, 'lgpassword': password, 'lgtoken': authToken} | ||
authResult = s.post(WIKI_API_URL, params=payload) | ||
if not json.loads(authResult.text)['login']['result'] == 'Success': | ||
logging.critical('Failed to login as {}: {}'.format(loginName, json.loads(authResult.text)['login']['result'])) | ||
else: | ||
logging.info('Login as {} succeeded'.format(loginName)) | ||
return authToken | ||
except Exception as e: | ||
logging.critical('Failed to login: {}'.format(e)) | ||
|
||
|
||
def wikiGetPage(s, pageTitle): | ||
payload = { | ||
'action': 'query', | ||
'format': 'json', | ||
'titles': pageTitle, | ||
'prop': 'revisions', | ||
'rvprop': 'content' | ||
} | ||
viewResult = s.get(WIKI_API_URL, params=payload) | ||
jsonResult = json.loads(viewResult.text) | ||
|
||
if 'missing' not in list(jsonResult['query']['pages'].values())[0]: | ||
return list(jsonResult['query']['pages'].values())[0]['revisions'][0]['*'] | ||
|
||
|
||
def wikiEditPage(s, pageTitle, pageContents, editToken): | ||
payload = { | ||
'action': 'edit', | ||
'format': 'json', | ||
'title': pageTitle, | ||
'text': pageContents, | ||
'bot': 'True', | ||
'contentmodel': 'wikitext', | ||
'token': editToken | ||
} | ||
editResult = s.post(WIKI_API_URL, data=payload) | ||
jsonResult = json.loads(editResult.text) | ||
return jsonResult | ||
|
||
|
||
def wikiGetToken(s, tokenType, props): | ||
try: | ||
payload = { | ||
'action': 'query', | ||
'format': 'json', | ||
'prop': props, | ||
'intoken': tokenType, | ||
'titles': 'Main Page' | ||
} | ||
tokenResult = s.get(WIKI_API_URL, params=payload) | ||
token = json.loads(tokenResult.text)['query']['pages']['1']['%stoken' % tokenType] | ||
logging.debug('%s token: %s' % (tokenType, token)) | ||
return token | ||
except Exception as e: | ||
logging.error('Failed to obtain %s token: %s' % (tokenType, e)) | ||
|
||
|
||
def wikiAddText(content, data): | ||
if not content: | ||
content = '' | ||
|
||
src, dst = data['langpair'].split('|') | ||
content += '\n* {{suggest|%s|%s|%s|%s|%s}}' % (src, dst, | ||
data['word'], | ||
data['newWord'], | ||
data['context'],) | ||
|
||
return content |