-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.py
153 lines (134 loc) · 5.28 KB
/
index.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wsgiref.handlers, cgi, logging, os ,time, urllib
from google.appengine.ext import webapp,db
from google.appengine.ext.webapp import template
from django.utils import simplejson
import search,skillsearch
class MainPage(webapp.RequestHandler):
def _get_results(self,detail):
results = {
'detail':detail,
'all_devils':search.sorted_devil_list,
'all_skills':skillsearch.skill_list,
}
if not detail:
results['index'] = True
return results
#デモニカもどき
if detail['name'] == u'デモニカもどき':
results['password_only'] = True
results['demonica_modoki'] = search.demonica_modoki_data
return results
#パスワード限定悪魔
if search.is_password_only(detail):
results['password_only'] = True
return results
#特殊合体時
special_result = search.search_special(detail)
if special_result:
results['special'] = special_result
return results
#狂神合体時
if search.search_kyoshin(detail):
results['kyoshin'] = True
return results
#精霊だった時
normal_results = search.search_element(detail)
if normal_results:
results['normals'] = normal_results
return results
#御霊だった時
normal_results = search.search_mitama(detail)
if normal_results:
results['normals'] = normal_results
return results
normal_results = search.search_converter(detail)
#コンバータ使用
if normal_results:
results['normals'] = normal_results
results['converter'] = True
return results
#普通の検索x
normal_results = search.search_normal(detail)
min_max = search.get_min_max(detail)
elements = search.search_element_up(detail)
results['normals'] = normal_results
results['min_max'] = min_max
results['elements'] = elements
return results
def set_reasonable(self,results):
reasonable = {'cost':results['detail']['cost'],
'details':[results['detail']],
}
if results.has_key('normals'):
for data in results.get('normals'):
if data.has_key('details'):
for details in data['details']:
cost_sum = details[0]['cost'] + details[1]['cost']
if reasonable['cost'] > cost_sum:
reasonable['cost'] = cost_sum
reasonable['details'] = details
if results.get('elements'):
for details in results.get('elements'):
cost_sum = details[0]['cost'] + details[1]['cost']
if reasonable['cost'] > cost_sum:
reasonable['cost'] = cost_sum
reasonable['details'] = details
if results.has_key('special'):
special = results.get('special')
cost_sum = special['cost_sum']
if reasonable['cost'] > cost_sum:
reasonable['cost'] = cost_sum
reasonable['details'] = special['data']
results['reasonable'] = reasonable
def get(self,name):
path = os.path.join(os.path.dirname(__file__), 'index.html')
detail = None
if name:
name = urllib.unquote_plus(name)
name = unicode(name,'utf-8')
logging.debug(name)
detail = search.detail_data.get(name)
if name and not detail:
self.response.out.write('404 Daemon or skill Not Found.')
self.response.set_status(404)
return
values = self._get_results(detail)
if not values.get('index'):
self.set_reasonable(values)
self.response.out.write(template.render(path, values))
def post(self,*name):
name = self.request.get("name")
if skillsearch.skill_data.has_key(name):
self.redirect('/skill/' + urllib.quote_plus(name.encode('utf-8')))
else:
self.redirect('/' + urllib.quote_plus(name.encode('utf-8')))
class SkillPage(webapp.RequestHandler):
def get(self,name):
path = os.path.join(os.path.dirname(__file__), 'skill_index.html')
if name:
values = {}
name = urllib.unquote_plus(name)
name = unicode(name,'utf-8')
logging.debug(name)
detail = skillsearch.search(name)
if not detail:
self.response.out.write('404 skill Not Found.')
self.response.set_status(404)
return
values['detail'] = detail
self.response.out.write(template.render(path, values))
else:
self.redirect('/' + urllib.quote_plus(name.encode('utf-8')))
def main():
application = webapp.WSGIApplication(
[
(r'/skill/(.*)',SkillPage),
(r'/(.*)',MainPage),
],
debug=True)
logging.getLogger().setLevel(logging.DEBUG)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()