-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
190 lines (163 loc) · 5.24 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from flask import Flask, render_template, request, Response, redirect
from pymongo import MongoClient
from flask_cors import CORS
from werkzeug.routing import BaseConverter
import re
import time
import json
import base64
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
app = Flask(__name__)
app.url_map.converters['reg'] = RegexConverter
CORS(app)
db = MongoClient('mongodb://entry:120903@syver.xyz:27017', connect=False).chuangji
HEX62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get/', methods=['POST'])
def get():
package = request.form
urlCheck = 's.click.taobao.com' in package['url']
detailCheck = package['detailURL'] is not None
nameCheck = '白菜池' in package['name']
if request.method == 'POST':
if urlCheck and detailCheck and nameCheck:
try:
url_id = db.shurl.find_one({
'url': package['url']
})['id']
except:
db.counter.update({
'name': 'counter'
},
{
'$inc': {
'id': 1
}
})
item_id = db.counter.find_one({
'name': 'counter'
})['id']
db.shurl.save({
'id': item_id,
'url': package['url'],
'detail_url': package['detailURL']
})
url_id = db.shurl.find_one({
'url': package['url']
})['id']
url_id = int(url_id)
code = ''
if url_id >= 62:
while url_id >= 62:
index = url_id % 62
code = HEX62[index] + code
url_id = url_id // 62
code = HEX62[url_id] + code
return Response('http://baicaichi.com/url/' + code)
else:
return Response(None)
# # 直接跳转解决方案(已完成)
# @app.route('/url/<reg("[0-9a-zA-Z]+"):code>')
# def goto(code):
# return render_template('url.html', code=base64.b64encode(code.encode(encoding='utf-8')).decode('utf-8'))
#
#
# @app.route('/item/<reg("[0-9a-zA-Z]+"):code>')
# def opentb(code):
# url_id = 0
#
# for i in code:
# key = HEX62.find(i)
# if key >= 0:
# url_id = url_id * 62 + key
#
# try:
# url = db.shurl.find_one({
# 'id': url_id
# })['url']
# time.sleep(2)
# return redirect(url)
# except:
# return Response('找不到页面地址,可能页面已过期')
#
#
# @app.route('/read/', methods=['POST'])
# def read():
# if request.method == 'POST':
# userAgent = str(request.user_agent)
# code = json.loads(request.data)['code']
#
# if 'Weibo' in userAgent:
# url = 'tbopen://m.taobao.com/tbopen/index.html?action=ali.open.nav&module=h5&bootImage=0&h5Url=' + code
# else:
# url = 'http://baicaichi.com/item/' + code
#
# return Response(url)
# 直接跳转解决方案2
@app.route('/url/<reg("[0-9a-zA-Z]+"):code>')
def goto(code):
return render_template('url.html', code=base64.b64encode(code.encode(encoding='utf-8')).decode('utf-8'))
@app.route('/read/', methods=['POST'])
def read():
if request.method == 'POST':
userAgent = str(request.user_agent)
code = json.loads(request.data)['code']
url_id = 0
for i in code:
key = HEX62.find(i)
if key >= 0:
url_id = url_id * 62 + key
try:
url = db.shurl.find_one({
'id': url_id
})['url']
time.sleep(1)
if 'Weibo' in userAgent:
url = 'tbopen://m.taobao.com/tbopen/index.html?action=ali.open.nav&module=h5&bootImage=0&h5Url=' + url
return Response(url)
except:
return Response('找不到页面地址,可能页面已过期')
# # 淘口令解决方案
# @app.route('/url/<reg("[0-9a-zA-Z]+"):code>')
# def goto(code):
# return render_template('url.html', code=base64.b64encode(code.encode(encoding='utf-8')).decode('utf-8'))
#
#
# @app.route('/item/<reg("[0-9a-zA-Z]+"):code>')
# def opentb(code):
# url_id = 0
#
# for i in code:
# key = HEX62.find(i)
# if key >= 0:
# url_id = url_id * 62 + key
#
# try:
# pkg = db.shurl.find_one({
# 'id': url_id
# })
# url = pkg['url']
# tkl = pkg['tkl']
# return render_template('tkl.html', tkl=tkl, url=url)
# except:
# return Response('找不到页面地址,可能页面已过期')
#
#
# @app.route('/read/', methods=['POST'])
# def read():
# if request.method == 'POST':
# userAgent = str(request.user_agent)
# url = json.loads(request.data)['url']
#
# # if re.match('iPhone', userAgent, re.I):
# if 'iPhone' in userAgent:
# return Response('true')
# else:
# return Response(url)
if __name__ == '__main__':
app.run(host='0.0.0.0')