def analytics(short_url): info_fetch, counter_fetch, browser_fetch, platform_fetch = list_data( short_url) return render_template("data.html", host=shorty_host, info=info_fetch, counter=counter_fetch, browser=browser_fetch, platform=platform_fetch)
def retrieve_short_url(): """ Takes api input as short url and returns long_url with analytics such as total clicks , platform and browser clicks """ if request.method == 'GET': if 'custom' in request.args: token_string = request.args['custom'] conn = psycopg2.connect(host=host, user=user, password=passwrd, database=db) cursor = conn.cursor() check_row = "SELECT S_URL FROM WEB_URL WHERE S_URL = %s FOR UPDATE" cursor.execute(check_row, (token_string, )) check_fetch = cursor.fetchone() if check_fetch is None: data = jsonify({ 'error': 'Custom string given not available as shortened url.' }) return make_response(data, 200) else: info, counter, browser, platform = list_data(token_string) data = jsonify({ 'clicks': counter[0], 'custom': info[1], 'long_url': info[0], 'click_browser': { 'chrome': browser[0], 'firefox': browser[1], 'safari': browser[2], 'other_browser': browser[3] }, 'click_platform': { 'android': platform[0], 'ios': platform[1], 'windows': platform[2], 'linux': platform[3], 'mac': platform[4], 'other_platform': platform[5] }, 'tag': info[2] }) return make_response(data, 200) else: data = jsonify({ 'error': 'Follow the API format ', }) return make_response(data, 405) else: data = jsonify({'error': 'Invalid Method Used , Use GET .'}) return make_response(data, 405)
def analytics(short_url): access_control(request) info_fetch, counter_fetch, browser_fetch, platform_fetch = list_data( short_url) return render_template("data.html", host=shorty_host, info=info_fetch, counter=counter_fetch, browser=browser_fetch, platform=platform_fetch, token=token)
def analytics(short_url): access = False if not config.is_secure: access = True elif 'Auth' in request.headers: if request.headers['Auth'] == config.SECRET_KEY: access = True if not access: return redirect('http://basalam.com') info_fetch, counter_fetch, browser_fetch, platform_fetch, user_count = list_data( short_url) user_count = user_count if user_count else [0, 0] return render_template("data.html", host=shorty_host, info=info_fetch, counter=counter_fetch, browser=browser_fetch, platform=platform_fetch, users=user_count)