def stats_handler(path): link = db.get_link(path) hits = db.get_hits(path) if link is None: return abort(404) day_labels = list() day_data = list() num_hits = len(hits) if num_hits: dates = (hit['timestamp'].date() for hit in hits) date_counter = collections.Counter(dates) current_date = min(date_counter) while current_date <= max(date_counter): day_labels.append(str(current_date)) day_data.append(date_counter[current_date]) current_date += datetime.timedelta(days=1) return render_template('stats.html', short_url=path_to_url(path), url=link['url'], num_hits=num_hits, day_labels=day_labels, day_data=day_data)
def link_handler(path): link = db.get_link(path) if link is None: return abort(404) db.hit_link( path, referrer=request.referrer, browser=request.user_agent.browser, platform=request.user_agent.platform, version=request.user_agent.version ) return redirect(link['url'], 301)