Skip to content

Commit

Permalink
fix ip show in base.html
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrela committed Jan 29, 2018
1 parent 2283d59 commit d331cf2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ __pycache__/
*.py[cod]
*$py.class

parser.py

# C extensions
*.so

Expand Down
Binary file modified app/parser.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<link href="/static/css/style.css" rel="stylesheet">
<link rel="shortcut icon" href="/static/logo.ico">
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create', 'UA-98994757-2', 'auto');ga('send', 'pageview');</script>
<script type="text/javascript" src="https://tajs.qq.com/stats?sId=65094144" charset="UTF-8"></script>


<body>
<!--头部-->
Expand Down Expand Up @@ -256,7 +258,7 @@ <h4>加入QQ群</h4>
window.location.href = "#" + $("#url_input").val();
var url = $("#url_input").val();
var host = $.url(url).attr('host');
ga('send', 'event', '183.62.134.100', 'prase', url);
ga('send', 'event', '{{ip}}', 'prase', url);
var hash = "{{hash_}}";
$("#url_submit_icon").attr("class", "fa fa-spinner fa-pulse fa-lg");
$("#url_submit_button").attr("disabled", "disabled");
Expand All @@ -282,7 +284,7 @@ <h4>加入QQ群</h4>
if (result.status == 'ok' && result.total != 0) {
var video_html = "<div class=\"panel panel-success\"><div class=\"panel-heading\"><h3 class=\"panel-title\">视频列表:</h3></div><ul class=\"list-group\">";
$.each(result.video, function(i) {
video_html += "<li class=\"list-group-item\"><p class=\"input-group\"><input type=\"text\" name=\"search\" id=\"video" + i + "\" class=\"form-control get-text\" value=\"" + result.video[i].url + "\"><span class=\"input-group-btn\"><a href=\"javascript:void(0);\" class=\"btn btn-info btnCopy\" data-clipboard-action=\"copy\" data-clipboard-target=\"#video" + i + "\" onclick=\"ga('send', 'event', '183.62.134.100', 'copy', '" + url + "');\"><span class=\"glyphicon glyphicon-duplicate\"></span></a><a href=\"" + result.video[i].url + "\" class=\"btn btn-primary get-dowmload\" download=\"title-time.mp4\" role=\"button\" title=\"下载\" onclick=\"ga('send', 'event', '183.62.134.100', 'download', '" + url + "');\"><span class=\"glyphicon glyphicon-save\"></span></a><a href=\"" + result.video[i].url + "\" class=\"btn btn-success\" role=\"button\" title=\"播放\" onclick=\"ga('send', 'event', '183.62.134.100', 'play', '" + url + "');\" data-toggle=\"lightbox\" data-title=\"\" data-type=\"video\" data-width=\"1024\"><span class=\"glyphicon glyphicon-play\"></span></a><a class=\"btn btn-default btn-warning hidden-xs\" title=\"扫码看视频\" onclick=\"ga('send', 'event', 'video', 'qrcode', '" + url + "');$.fancybox.open('<div id=\\\'qrcode\\\'></div>');$('#qrcode').qrcode({text:'" + result.video[i].url + "'});\"><span class=\"fa fa-qrcode\"></span></a></span></p><p class=\"get-desc\">简介:" + result.video[i].desc + "</p></li>";
video_html += "<li class=\"list-group-item\"><p class=\"input-group\"><input type=\"text\" name=\"search\" id=\"video" + i + "\" class=\"form-control get-text\" value=\"" + result.video[i].url + "\"><span class=\"input-group-btn\"><a href=\"javascript:void(0);\" class=\"btn btn-info btnCopy\" data-clipboard-action=\"copy\" data-clipboard-target=\"#video" + i + "\" onclick=\"ga('send', 'event', '{{ip}}', 'copy', '" + url + "');\"><span class=\"glyphicon glyphicon-duplicate\"></span></a><a href=\"" + result.video[i].url + "\" class=\"btn btn-primary get-dowmload\" download=\"title-time.mp4\" role=\"button\" title=\"下载\" onclick=\"ga('send', 'event', '{{ip}}', 'download', '" + url + "');\"><span class=\"glyphicon glyphicon-save\"></span></a><a href=\"" + result.video[i].url + "\" class=\"btn btn-success\" role=\"button\" title=\"播放\" onclick=\"ga('send', 'event', '{{ip}}', 'play', '" + url + "');\" data-toggle=\"lightbox\" data-title=\"\" data-type=\"video\" data-width=\"1024\"><span class=\"glyphicon glyphicon-play\"></span></a><a class=\"btn btn-default btn-warning hidden-xs\" title=\"扫码看视频\" onclick=\"ga('send', 'event', 'video', 'qrcode', '" + url + "');$.fancybox.open('<div id=\\\'qrcode\\\'></div>');$('#qrcode').qrcode({text:'" + result.video[i].url + "'});\"><span class=\"fa fa-qrcode\"></span></a></span></p><p class=\"get-desc\">简介:" + result.video[i].desc + "</p></li>";
});
video_html += "</ul></div>";
$("#video").html(video_html);
Expand Down
24 changes: 16 additions & 8 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-*- coding=utf-8 -*-
from app import app, db
from app.models import *
from flask import render_template, redirect, request, url_for, flash, session, jsonify, make_response,current_app
from flask import render_template, redirect, request, url_for, flash, session, jsonify, make_response, current_app
import sys
reload(sys)
sys.setdefaultencoding('utf8')
Expand Down Expand Up @@ -35,6 +35,15 @@
HOME = 'http://%s.tumblr.com/api/read?&num=50'


@app.before_request
def before_request():
global ip
try:
ip = request.headers['X-Forwarded-For'].split(',')[0]
except:
ip = request.remote_addr


def check(uid):
url = HOME % uid
try:
Expand Down Expand Up @@ -67,7 +76,8 @@ def form_trans():
def index():
hash_ = getmd5()
session['hash'] = hash_
return render_template('base.html', hash_=hash_)
global ip
return render_template('base.html', hash_=hash_, ip=ip)


@app.route('/api', methods=['POST'])
Expand All @@ -76,8 +86,8 @@ def api():
hash_ = request.form.get('hash')
captcha_code = request.form.get('captcha_code')
if captcha_code is not None:
print 'input code is :',captcha_code
print 'session code is :',session.get('CAPTCHA')
print 'input code is :', captcha_code
print 'session code is :', session.get('CAPTCHA')
if captcha_code.upper() == session.get('CAPTCHA'):
return jsonify({'captcha': 'pass'})
if hash_ != session.get('hash'):
Expand Down Expand Up @@ -156,21 +166,20 @@ def api():
# 2mm
else:
try:
video,title,picture=parser.main(url)
video, title, picture = parser.main(url)
retdata['status'] = 'ok'
retdata['total'] = 1
retdata['pages'] = 1
retdata['video'] = [
{'url': video, 'desc': title, 'thumb': picture}]
return jsonify(retdata)
except Exception,e:
except Exception, e:
print e
retdata['status'] = 'fail'
retdata['message'] = '解析网站不存在'
return jsonify(retdata)



@app.route('/captcha', methods=['GET'])
def captcha():
ic = ImageChar(fontColor=(100, 211, 90))
Expand All @@ -182,4 +191,3 @@ def captcha():
response = current_app.make_response(buf_str)
response.headers['Content-Type'] = 'image/jpeg'
return response

0 comments on commit d331cf2

Please sign in to comment.