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

Commit

Permalink
server.py --dry-run option.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdavis committed Jun 19, 2016
1 parent 672cd0e commit 21698c7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from flask import Flask, request, render_template
from wtforms import Form, StringField

Expand All @@ -16,12 +18,17 @@ def index():
form = AnalyzeForm(request.form)
results = {}
error = None
try:
results = {'friends': analyze_friends(form.user_id),
'followers': analyze_followers(form.user_id)}
except Exception as exc:
error = exc
if request.method == 'POST' and form.validate() and form.user_id.data:
if app.config['DRY_RUN']:
time.sleep(2)
results = {'friends': (150, 25, 200),
'followers': (200, 20, 250)}
else:
try:
results = {'friends': analyze_friends(form.user_id),
'followers': analyze_followers(form.user_id)}
except Exception as exc:
error = exc

return render_template('index.html',
form=form, results=results, error=error)
Expand All @@ -30,8 +37,10 @@ def index():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true')
parser.add_argument('--dry-run', action='store_true')
parser.add_argument('port', nargs=1, type=int)
args = parser.parse_args()
[port] = args.port

app.config['DRY_RUN'] = args.dry_run
app.run(port=port, debug=args.debug)

0 comments on commit 21698c7

Please sign in to comment.