def edit(): user = users[session['user']] if request.method == 'GET': form = query_form(user.queries, user.mensae) results = mensa.search_many(user.queries, user.mensae) return render_template('edit.html', user=session['user'], form=form, form_action=url_for('edit'), results=results) else: form = QueryForm(request.form) q = form.queries.entries user.queries = [x.data for x in q if x.data] user.mensae = form.mensae.data return redirect(url_for('edit'))
def search(mensae=MENSA_NAMES, query=None): if request.method == 'POST': form = QueryForm(request.form) q = [x.data for x in form.queries if x.data] or None return redirect(url_for('search', mensae=form.mensae.data, query=q)) results = mensa.search_many(query, mensae) form = query_form(query, mensae) if not results: msg = 'No results' if query: msg += ' for ' msg += ', '.join('"{}"'.format(q) for q in query) flash(msg, 'warn') results = mensa.overview(mensae) return render_template('results.html', form=form, form_action=url_for('search'), mensae=mensae, results=results)
def search_json(mensae=mensa.MENSA_NAMES, query=None): results = mensa.search_many(query, mensae) return jsonify(**results)
#!/usr/bin/env python # to be run as a cron job to send out notifications from mensanotify import mensa, users from mensanotify.email import send_results if __name__ == '__main__': for k, v in users.items(): results = mensa.search_many(v.queries, v.mensae) if results: send_results(k, results)