-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinner_views.py
373 lines (329 loc) · 12.4 KB
/
inner_views.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# coding=utf-8
import datetime
import json
import random
from DjangoCaptcha import Captcha
from django.contrib import auth
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import get_template
from dateutil.relativedelta import relativedelta
from searcher.models import Bid, UserFilter, DimensionChoice
__author__ = 'pony'
def user_auth(request, username, password, code):
user = auth.authenticate(username=username, password=password)
_code = code
ca = Captcha(request)
if user is None:
a = 2
elif not user.is_active:
a = 3
elif _code is not None and not ca.check(_code):
a = 4
else:
auth.login(request, user)
a = 1
return a
def refresh_header(request, a):
if a == 1:
t = get_template('header.html')
content_html = t.render(RequestContext(request))
payload = {
'content_html': content_html,
'success': True
}
return HttpResponse(json.dumps(payload), content_type="application/json")
else:
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(a)
return HttpResponse(response)
def combination_bid(amount, ctype):
# date1 = datetime.datetime.now()
global a
if None == amount:
if ctype == 1:
a = Bid.objects.filter(income_rate__lte=8)
elif ctype == 2:
a = Bid.objects.filter(income_rate__lte=15, income_rate__gte=8)
elif ctype == 3:
a = Bid.objects.filter(income_rate__gte=15)
else:
if ctype == 1:
a = Bid.objects.filter(amount__lte=amount, income_rate__lte=8)
elif ctype == 2:
a = Bid.objects.filter(amount__lte=amount, income_rate__lte=15, income_rate__gte=8)
elif ctype == 3:
a = Bid.objects.filter(amount__lte=amount, income_rate__gte=15)
if len(a) >= 2:
aa = random.sample(a, 2)
cid = []
term = []
for t in aa:
cid.append(str(t.id))
try:
int(t.term)
except:
t.term = 0
if t.term != int(t.term):
term.append(round(t.term, 2))
else:
term.append(int(t.term))
c = {'ids': '&'.join(cid)}
tmax = max(term)
tmin = min(term)
if tmax == tmin:
c.update({'term': str(tmax)})
else:
c.update({'term': str(tmin) + '-' + str(tmax)})
# print(c)
# p = re.compile(r'0*()$')
# print p.sub(r'\1', str(aa[0].term))
# c.update({'term1': aa[0].term, 'term2': aa[1].term})
c.update(dict(income_rate=(aa[0].income_rate + aa[1].income_rate) / 2))
if ctype == 1:
c.update({'name': '天天搜贷 保守型'})
elif ctype == 2:
c.update({'name': '天天搜贷 稳健型'})
elif ctype == 3:
c.update({'name': '天天搜贷 激进型'})
c.update({'amount': (aa[0].amount + aa[1].amount)})
if aa[0].ten_thousand_revenue and aa[1].ten_thousand_revenue:
ten_thousand_revenue = aa[0].ten_thousand_revenue + aa[1].ten_thousand_revenue
else:
ten_thousand_revenue = aa[0].income_rate / 12 * aa[0].term * 10000 + aa[1].income_rate / 12 * aa[
1].term * 10000
c.update({'thousandincome': ten_thousand_revenue})
else:
c = None
# date2 = datetime.datetime.now()
# print(u'组合耗时' + str(ctype) + str((date2 - date1).seconds) + u'秒')
return c
def fil_yield(results, cal_type, value1, value2):
if cal_type == 1:
return results.filter(income_rate__lte=value1)
elif cal_type == 2:
return results.filter(income_rate=value1)
elif cal_type == 3:
return results.filter(income_rate__gte=value1)
elif cal_type == 4:
return results.filter(income_rate__gte=value1, income_rate__lte=value2)
elif cal_type == 0:
return results
def fil_time(results, cal_type, value1, value2):
if cal_type == 1:
return results.filter(term__lte=value1)
elif cal_type == 2:
return results.filter(term=value1)
elif cal_type == 3:
return results.filter(term__gte=value1)
elif cal_type == 4:
return results.filter(term__gte=value1, term__lte=value2)
elif cal_type == 0:
return results
def fil_lz(results, cal_type, value1, value2):
if cal_type == 0:
return results
elif cal_type == 2:
if value1 == 1:
return results.filter(transfer_claim='Y')
else:
return results.filter(transfer_claim='N')
def fil_capital(results, cal_type, value1, value2):
if cal_type == 0:
return results
elif cal_type == 1:
return results.filter(platform__capital__lte=value1)
elif cal_type == 3:
return results.filter(platform__capital__gte=value1)
elif cal_type == 4:
return results.filter(platform__capital__gte=value1, platform__capital__lte=value2)
def fil_online(results, cal_type, value1, value2):
if cal_type == 0:
return results
elif cal_type == 1:
return results.filter(platform__online_time__gte=datetime.date.today() + relativedelta(months=-int(value1)))
elif cal_type == 3:
return results.filter(platform__online_time__lte=datetime.date.today() + relativedelta(months=-int(value1)))
elif cal_type == 4:
return results.filter(platform__online_time__lte=datetime.date.today() + relativedelta(months=-int(value1)),
platform__online_time__gte=datetime.date.today() + relativedelta(months=-int(value2)))
def fil_type(results, cal_type, choice_name):
if cal_type == 0:
return results
elif cal_type == 2:
return results.filter(type=choice_name)
def fil_background(results, cal_type, choice_name):
if cal_type == 0:
return results
elif cal_type == 2:
return results.filter(platform__background=choice_name)
def get_user_filter(user):
f_l = []
f_list = UserFilter.objects.filter(user=user)
if len(f_list) > 0:
for f in f_list:
k = str(f.choices)
a = map(int, k.split(','))
filters = DimensionChoice.objects.filter(id__in=a)
f_l.append({'id': f.id, 'name': f.name, 'choices': k, 'filters': filters})
return f_l
def data_filter(data, filters): # queryset
results = data
for f in filters:
if f.dimension.id == 1:
results = fil_yield(results, f.cal_type, f.choice_value1, f.choice_value2)
elif f.dimension.id == 2:
results = fil_time(results, f.cal_type, f.choice_value1, f.choice_value2)
elif f.dimension.id == 3:
results = fil_lz(results, f.cal_type, f.choice_value1, f.choice_value2)
elif f.dimension.id == 4:
results = fil_capital(results, f.cal_type, f.choice_value1, f.choice_value2)
elif f.dimension.id == 5:
results = fil_online(results, f.cal_type, f.choice_value1, f.choice_value2)
elif f.dimension.id == 6:
results = fil_type(results, f.cal_type, f.choice_name)
elif f.dimension.id == 7:
results = fil_background(results, f.cal_type, f.choice_name)
return results
def index_loading(amount, params, page):
c_bs = combination_bid(amount, 1)
c_wj = combination_bid(amount, 2)
c_jj = combination_bid(amount, 3)
c_result = [c_bs, c_wj, c_jj]
dimensions = DimensionChoice.objects.all()
if None == amount:
results = Bid.objects.all().order_by("random_rank")
else:
results = Bid.objects.filter(amount__gte=amount).order_by("random_rank")
if params is not None:
a = params.split(',')
filters = DimensionChoice.objects.filter(id__in=a)
results = data_filter(results, filters)
# random.shuffle(results)
# results = results.order_by('?')
ppp = Paginator(results, 5)
last_page = ppp.page_range[len(ppp.page_range) - 1]
try:
results = ppp.page(page)
except (EmptyPage, InvalidPage):
results = ppp.page(ppp.num_pages)
page_set = get_pageset(last_page, results.number)
index_parts = {'dimensions': dimensions, 'results': results, 'c_result': c_result, 'last_page': last_page,
'page_set': page_set}
return index_parts
def index_loading_rank(amount, params, page,rank):
c_bs = combination_bid(amount, 1)
c_wj = combination_bid(amount, 2)
c_jj = combination_bid(amount, 3)
c_result = [c_bs, c_wj, c_jj]
dimensions = DimensionChoice.objects.all()
if None == amount:
results = Bid.objects.all().order_by("random_rank").order_by("%s"%rank)
else:
results = Bid.objects.filter(amount__gte=amount).order_by("random_rank")
if params is not None:
a = params.split(',')
filters = DimensionChoice.objects.filter(id__in=a)
results = data_filter(results, filters)
# random.shuffle(results)
# results = results.order_by('?')
ppp = Paginator(results, 6)
last_page = ppp.page_range[len(ppp.page_range) - 1]
try:
results = ppp.page(page)
except (EmptyPage, InvalidPage):
results = ppp.page(ppp.num_pages)
page_set = get_pageset(last_page, results.number)
index_parts = {'dimensions': dimensions, 'results': results, 'c_result': c_result, 'last_page': last_page,
'page_set': page_set}
return index_parts
def index_loading_m(amount, params, page):
c_bs = combination_bid(amount, 1)
c_wj = combination_bid(amount, 2)
c_jj = combination_bid(amount, 3)
c_result = [c_bs, c_wj, c_jj]
dimensions = DimensionChoice.objects.all()
if None == amount:
results = Bid.objects.all().order_by("random_rank")
else:
results = Bid.objects.filter(amount__gte=amount).order_by("random_rank")
if params is not None:
a = params.split(',')
filters = DimensionChoice.objects.filter(id__in=a)
results = data_filter(results, filters)
# random.shuffle(results)
# results = results.order_by('?')
ppp = Paginator(results, 3)
last_page = ppp.page_range[len(ppp.page_range) - 1]
try:
results = ppp.page(page)
except (EmptyPage, InvalidPage):
results = ppp.page(ppp.num_pages)
page_set = get_pageset(last_page, results.number)
index_parts = {'dimensions': dimensions, 'results': results, 'c_result': c_result, 'last_page': last_page,
'page_set': page_set}
return index_parts
def get_pageset(last_page, pagenum):
page_set = []
if pagenum <= 3:
start = 0
end = 6
elif pagenum > last_page - 3:
start = last_page - 4
end = last_page + 1
else:
start = pagenum - 2
end = pagenum + 3
for i in range(start, end, 1):
if i <= 0:
pass
elif i > last_page:
break
else:
page_set.append(i)
return page_set
def result_sort(data, sorttype, sortorder):
if sorttype == u'1' and sortorder == u'1':
o_string = "income_rate"
elif sorttype == u'1' and sortorder == u'2':
o_string = "-income_rate"
elif sorttype == u'2' and sortorder == u'1':
o_string = "term"
elif sorttype == u'2' and sortorder == u'2':
o_string = "-term"
else:
o_string = None
if o_string:
data = data.order_by(o_string)
return data
import re
def send_flow_all(phone):
p = re.compile('^13[4-9][0-9]{8}|^15[0,1,2,7,8,9][0-9]{8}|^18[2,7,8][0-9]{8}|^147[0-9]{8}|^178[0-9]{8}')
if p.match(phone):
send_flow(phone, 70)
print phone ,'移动'
else:
send_flow(phone, 50)
import urllib2,urllib,hashlib
def send_flow(phone, package):
m = { 'account' : 'shcidajr', 'mobile' : phone,'package' : package,}
params = ''
for k in sorted(m.keys()):
if len(params) > 0:
params += "&"
params += (k + "=" + str(m[k]))
params = params + '&key=' +'fba13724adac4b0b862fab34b7dca288'
print params
m = hashlib.md5()
m.update(params)
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)
url_charge = r'http://www.llt400.com:8080/api.aspx?action=charge&v=1.1&account=shcidajr&mobile=%s&package=%s&sign=%s'%(phone,package,m.hexdigest())
request = urllib2.Request(
url = url_charge,
headers= {'Content-Type':'text/xml'},
data = ''
)
print opener.open(request).read()