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

Commit

Permalink
Return the story IDs of the currently trending HN stories whenever ch…
Browse files Browse the repository at this point in the history
…arlesbot reads a sentence prefixed with `!hn`
  • Loading branch information
marvinpinto committed Mar 18, 2016
1 parent 5376927 commit 21523f5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions charlesbot_hello_world/helloworld.py
Expand Up @@ -3,6 +3,7 @@
from charlesbot.slack.slack_message import SlackMessage from charlesbot.slack.slack_message import SlackMessage
from charlesbot.util.parse import does_msg_contain_prefix from charlesbot.util.parse import does_msg_contain_prefix
import asyncio import asyncio
import aiohttp




class HelloWorld(BasePlugin): class HelloWorld(BasePlugin):
Expand Down Expand Up @@ -30,5 +31,19 @@ def process_message(self, message):
if not does_msg_contain_prefix("!hn", message.text): if not does_msg_contain_prefix("!hn", message.text):
return return


return_msg = "Hi there!" return_msg = yield from self.get_all_hn_top_stories()
yield from self.slack.send_channel_message(message.channel, return_msg) yield from self.slack.send_channel_message(message.channel, str(return_msg))

@asyncio.coroutine
def get_all_hn_top_stories(self):
hn_top_stories_url = "https://hacker-news.firebaseio.com/v0/topstories.json"
response = yield from aiohttp.get(hn_top_stories_url)
if not response.status == 200:
text = yield from response.text()
self.log.error("URL: %s" % url)
self.log.error("Response status code was %s" % str(response.status))
self.log.error(response.headers)
self.log.error(text)
response.close()
return []
return (yield from response.json())

0 comments on commit 21523f5

Please sign in to comment.