-
Notifications
You must be signed in to change notification settings - Fork 986
Upcoming programming contests added #218
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
'book', | ||
'bye', | ||
'coin', | ||
'cpcontest', | ||
'currency', | ||
'dice', | ||
'dictionary', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import requests | ||
from templates.text import TextTemplate | ||
from templates.button import ButtonTemplate | ||
|
||
|
||
def process(input, entities): | ||
output = {} | ||
try: | ||
|
||
r = requests.get('https://cpcontest-api.herokuapp.com/') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this your personal api? If yes, do you plan to maintain it (hosting, bug fixes, etc.)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is my personal API and I am maintaining it. If I could find any alternative API, which is very well maintained and serves the purpose, I will update it. |
||
data = r.json() | ||
|
||
buttons = ButtonTemplate() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F821 undefined name 'ButtonTemplate' |
||
|
||
# Number of results to be displayed | ||
num = 3 | ||
for contest in data['result']['upcoming_contests']: | ||
buttons.add_web_url(contest['Name'], contest['url']) | ||
num -= 1 | ||
if num == 0: | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A better way to do this would be to specify this number in the API call itself. |
||
|
||
output['input'] = input | ||
output['output'] = buttons.get_message() | ||
output['success'] = True | ||
except: | ||
error_message = 'There was some error while retrieving data.' | ||
output['error_msg'] = TextTemplate(error_message).get_message() | ||
output['success'] = False | ||
return output |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import modules | ||
|
||
|
||
def test_cpcontest(): | ||
assert('cpcontest' == modules.process_query('upcoming contests')[0]) | ||
assert('cpcontest' == modules.process_query('programming contests')[0]) | ||
assert('cpcontest' != modules.process_query('something random')[0]) |
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.
Let's think of a better name.
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.
"contest" would be too generalized, other names are too big such as "programmingcontest" or something like that. So, I abbreviated "competitive programming" to "cp" here. Do you have any suggestion?