Permalink
Browse files

add the fill built app

1 parent 4dd1813 commit 707a1f2d8d75956ece05abb0f6d3a78763782185 @karan committed May 15, 2015
Showing with 47 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +12 −0 README.md
  3. +31 −5 app.py
  4. +3 −0 config.py.example
View
@@ -55,3 +55,4 @@ docs/_build/
# PyBuilder
target/
+config.py
View
@@ -1,2 +1,14 @@
# slack-overflow
+
A programmer's best friend, now in Slack.
+
+*Show example gif*
+
+## Installation
+
+- Setup Slack Slash Command.
+- Start using
+
+## Developing
+
+- Add a `config.py` file. http://stackapps.com/
View
36 app.py
@@ -1,19 +1,45 @@
+# -*- coding: utf-8 -*-
+
from flask import Flask, request, Response
+from stackexchange import Site, StackOverflow, Sort, DESC
+
+try:
+ import config
+except:
+ import sys
+ print 'No config.py file found. Exiting...'
+ sys.exit(0)
+
+
+MAX_QUESTIONS = 5
+
+
app = Flask(__name__)
+so = Site(StackOverflow, config.stackexchange['api_key'])
+
+
+def get_response_string(q):
+ q_data = q.json
+ check = ' :white_check_mark:' if q.json['is_answered'] else ''
+ return "|%d|%s <%s|%s> (%d answers)" % (q_data['score'], check, q.url,
+ q.title, q_data['answer_count'])
@app.route('/overflow', methods=['post'])
def overflow():
'''
Example:
- /overflow hello world
+ /overflow python list comprehension
'''
- user_id = request.values.get('user_id')
- user_name = request.values.get('user_name')
- channel_name = request.values.get('channel_name')
text = request.values.get('text')
- return Response(text, content_type='text/plain; charset=utf-8')
+ qs = so.search(intitle=text, sort=Sort.Votes, order=DESC)
+
+ resp_qs = ['Stack Overflow Top Questions for "%s"\n' % text]
+ for q in qs[:MAX_QUESTIONS]:
+ resp_qs.append(get_response_string(q))
+
+ return Response('\n'.join(resp_qs), content_type='text/plain; charset=utf-8')
@app.route('/')
View
@@ -0,0 +1,3 @@
+stackexchange = dict(
+ api_key = ''
+)

0 comments on commit 707a1f2

Please sign in to comment.