-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add suggestions route and wiki api functionality #18
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
289cfc2
Add suggestions route and wiki api functionality
svineet c1ef6cc
Added ReCAPTCHA functionality
svineet c112c02
Change main method to GET instead of POST in SuggestionHandler (JSONP…
svineet 25adeff
Better error messages and edit token bug fix
svineet f27dbe0
Merge conflicts resolved
svineet 8388eb4
Merge conflict resolution
svineet 9e464b7
Remove redundant option
svineet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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['context'], | ||
data['word'], | ||
data['newWord']) | ||
|
||
return content |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kira-D: As you suggested, we should probably take this out. Adding it to the user page is safer.