Skip to content
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
34 changes: 33 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
sys.exit(0)


MAX_QUESTIONS = 5
MAX_QUESTIONS = 5 # Default number of questions


app = Flask(__name__)
Expand Down Expand Up @@ -60,6 +60,38 @@ def overflow():
content_type='text/plain; charset=utf-8')


@app.route('/overflow_dynamic', methods=['post'])
def overflow_dynamic():
data = request.get_json()
text = data.get('text')
num_questions = data.get('num_questions', MAX_QUESTIONS)

try:
num_questions = int(num_questions)
if num_questions <= 0:
raise ValueError("Number of questions must be greater than zero")
except ValueError:
return Response('Invalid number of questions. Must be a positive integer.',
content_type='text/plain; charset=utf-8')

try:
qs = so.search(intitle=text, sort=Sort.Votes, order=DESC)
except UnicodeEncodeError:
return Response(('Only English language is supported. '
'%s is not valid input.' % text),
content_type='text/plain; charset=utf-8')

resp_qs = ['Stack Overflow Top Questions for "%s"\n' % text]
resp_qs.extend(map(get_response_string, qs[:num_questions]))

if len(resp_qs) == 1:
resp_qs.append(('No questions found. Please try a broader search or '
'search directly on '
'<https://stackoverflow.com|StackOverflow>.'))

return Response('\n'.join(resp_qs),
content_type='text/plain; charset=utf-8')

@app.route('/')
def hello():
return redirect('https://github.com/karan/slack-overflow')
Expand Down
3 changes: 0 additions & 3 deletions config.py.example

This file was deleted.