def counters_update(): if request.method == 'GET': id = request.args.get('id', '') counter = SocialCounter.get(SocialCounter.id == id) form = SocialCounterForm(None, counter) else: id = request.form.get('id') counter = SocialCounter.get(SocialCounter.id == id) form = SocialCounterForm(request.form) form.validate() # urls = request.form.get('urls') # urls_stripped = "\n".join([line.rstrip() for line in urls.splitlines() if line.strip()]) if form.errors: pass else: now = datetime.datetime.utcnow() counter.name = request.form.get('name') counter.runnable = request.form.get('runnable') counter.gspread_link = request.form.get('gspread_link') # counter.urls = urls_stripped counter.urls = None # or obtained from gspread? counter.updated_at = now counter.save() new_counter = False form = SocialCounterForm(None, counter) flash('Social counter was updated') return redirect(url_for('counters.counters_list')) return render_template('counter.html', current_user=current_user, form=form, new_counter=False, id=id)
def counters_summary(): id = request.args.get('id', None) if id is None: flash('Error: id is missing for Social counter summary page!') return redirect(url_for('counters.counters_list')) sc = SocialCounter.get(SocialCounter.id == id) counters = SocialCount.select().where( SocialCount.name == sc.name).order_by(SocialCount.timestamp.desc()) return render_template('counters_summary.html', current_user=current_user, counters=counters, id=id)
def count_now(): # gspread columns, does the name matter? no, just the proper number of columns for the results: # url, tweets, google_plusses, fb_total, fb_shares, fb_likes, fb_comments, fb_clicks id = request.args.get('id', None) if id is None: flash('Error: id is missing, but is required to run a Social counter!') return redirect(url_for('counters.counters_list')) sc = SocialCounter.get(SocialCounter.id == id) if sc.is_runnable(): # processed = SocialCount.fetch_counters(sc.name, sc.urls) processed = SocialCount.fetch_counters(sc) flash("Social counts updated for: '%s'" % sc.name) return redirect(url_for('counters.counters_list'))