Skip to content

Instantly share code, notes, and snippets.

@TheHanna
Last active June 23, 2016 13:11
Show Gist options
  • Save TheHanna/b5af15dc3cb63020cdb179228fefd358 to your computer and use it in GitHub Desktop.
Save TheHanna/b5af15dc3cb63020cdb179228fefd358 to your computer and use it in GitHub Desktop.
Flask by Example - Part 5
# just including the /resuluts/<job_key> route
@app.route('/results/<job_key>', methods=['GET'])
def get_results(job_key):
job = Job.fetch(job_key, connection=conn)
if job.is_finished:
result = Result.query.filter_by(id=job.result).first()
results = sorted(
result.result_no_stop_words.items(),
key=operator.itemgetter(1),
reverse=True
)[:10]
return jsonify(results);
else:
return 'Nay!', 202
<!DOCTYPE html>
<html ng-app="WordcountApp">
<head>
<title>Wordcount</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<style media="screen">
.container {
max-width: 1000px;
}
</style>
</head>
<body ng-controller="WordcountController">
<div class="container">
<div class="row">
<div class="col-sm-6">
<h1>Wordcount 3000</h1>
<form role="form" ng-submit="getResults()">
<div class="form-group">
<input type="text" ng-model="url" name="url" class="form-control" id="url-box" placeholder="Enter URL..." autofocus required />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<div class="col-sm-6">
<h2>Frequencies</h2>
<div id="results">
<table class="table table-striped">
<thead>
<tr>
<th>Word</th>
<th>Count</th>
</tr>
</thead>
<tbody>
{% raw %}
<tr ng-repeat="(key, val) in wordcounts">
<td>{{ val[0] }}</td>
<td>{{ val[1] }}</td>
</tr>
{% endraw %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="../static/main.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment