Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'book',
'bye',
'coin',
'cpcontest',
Copy link
Owner

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.

Copy link
Author

@torquecoder torquecoder Jun 28, 2017

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?

'currency',
'dice',
'dictionary',
Expand Down
30 changes: 30 additions & 0 deletions modules/src/cpcontest.py
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/')
Copy link
Owner

Choose a reason for hiding this comment

The 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.)?

Copy link
Author

Choose a reason for hiding this comment

The 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()

Choose a reason for hiding this comment

The 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
Copy link
Owner

Choose a reason for hiding this comment

The 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
7 changes: 7 additions & 0 deletions modules/tests/test_cpcontest.py
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])