-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
227 lines (168 loc) · 7.56 KB
/
main.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
#!/usr/bin/env python
import os
import json
import urllib
from google.appengine.ext import ndb
import logging
import webapp2
import jinja2
import fixtures
from gameon import gameon
from gameon.gameon_utils import GameOnUtils
from ws import ws
FACEBOOK_APP_ID = "138831849632195"
FACEBOOK_APP_SECRET = "93986c9cdd240540f70efaea56a9e3f2"
config = {}
config['webapp2_extras.sessions'] = dict(secret_key='93986c9cdd240540f70efaea56a9e3f2')
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'])
class BaseHandler(webapp2.RequestHandler):
def render(self, view_name, extraParams={}):
noads = self.request.get('noads', False)
android_app = self.request.headers.get('HTTP_X_REQUESTED_WITH', False)
if android_app:
noads = True
template_values = {
'fixtures': fixtures,
'ws': ws,
'json': json,
'GameOnUtils': GameOnUtils,
# 'facebook_app_id': FACEBOOK_APP_ID,
# 'glogin_url': users.create_login_url(self.request.uri),
# 'glogout_url': users.create_logout_url(self.request.uri),
'noads': noads,
'url': self.request.uri,
'path': self.request.path,
'urlencode': urllib.quote_plus,
# 'num_levels': len(LEVELS)
}
template_values.update(extraParams)
template = JINJA_ENVIRONMENT.get_template(view_name)
self.response.write(template.render(template_values))
class MainHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', False)
self.render('templates/index.jinja2', {'noads': noads})
class TestsHandler(BaseHandler):
def get(self):
self.render('templates/tests.jinja2')
class FbHandler(BaseHandler):
def get(self):
# redirect to home
noads = self.request.get('noads', True)
self.render('templates/index.jinja2', {'noads': noads})
class ContactHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', True)
self.render('templates/contact.jinja2', {'noads': noads})
class AboutHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', True)
self.render('templates/about.jinja2', {'noads': noads})
class PrivacyHandler(BaseHandler):
def get(self):
if 'privacy-policy' in self.request.path:
self.redirect('/privacy', True)
noads = self.request.get('noads', True)
self.render('templates/privacy.jinja2', {'noads': noads})
class TermsHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', True)
self.render('templates/terms.jinja2', {'noads': noads})
class VersusHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', True)
self.render('templates/versus.jinja2', {'noads': noads})
class TimedHandler(BaseHandler):
def get(self):
# self.redirect('/', True)
noads = self.request.get('noads', True)
self.render('templates/index.jinja2', {'noads': noads})
class FriendsHandler(BaseHandler):
def get(self):
# self.redirect('/versus', True)
noads = self.request.get('noads', True)
self.render('templates/versus.jinja2', {'noads': noads})
class GameMultiplayerHandler(BaseHandler):
def get(self):
# redirect home
noads = self.request.get('noads', True)
self.render('templates/index.jinja2', {'noads': noads})
class GamesHandler(BaseHandler):
def get(self):
self.render('templates/index.jinja2', {'noads': True})
class LearnEnglishHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', True)
self.render('templates/learn-english.jinja2', {
'noads': noads,
"json": json,
'LEARN_ENGLISH_LEVELS': ((key, level) for key, level in fixtures.LEARN_ENGLISH_LEVELS.iteritems())
})
class EnglishLevelHandler(BaseHandler):
def get(self, urlkey):
noads = self.request.get('noads', False)
android_app = self.request.headers.get('HTTP_X_REQUESTED_WITH', False)
if android_app:
noads = True
if urlkey == 'undefined':
logging.error('learn english key is undefined??')
return self.redirect('/learn-english/girls-names')
self.render('templates/learn-english-level.jinja2', {
'noads': noads,
'level': fixtures.LEARN_ENGLISH_LEVELS[urlkey],
'urlkey': urlkey,
})
class CampaignHandler(BaseHandler):
def get(self):
noads = self.request.get('noads', True)
self.render('templates/campaign.jinja2', {'noads': noads})
class BuyHandler(BaseHandler):
def get(self):
# paymentAmount = "3.99"
# CURRENCYCODE = "USD"
# RETURNURL = "https://wordsmashing.appspot.com/buy"
# CANCELURL = "https://wordsmashing.appspot.com/buy"
self.render('templates/buy.jinja2')
class LevelHandler(BaseHandler):
def get(self, level):
level_num = int(level)
noads = self.request.get('noads', True)
self.render('templates/level.jinja2', {'noads': noads, 'level_num': level_num, 'level': fixtures.LEVELS[level_num - 1]})
class SitemapHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/xml'
template_values = {
'learnenglishlevels': fixtures.LEARN_ENGLISH_LEVELS,
}
template = JINJA_ENVIRONMENT.get_template('sitemap.xml')
self.response.write(template.render(template_values))
class SlashMurdererApp(webapp2.RequestHandler):
def get(self, url):
self.redirect(url)
app = ndb.toplevel(webapp2.WSGIApplication([
('/', MainHandler),
('(.*)/$', SlashMurdererApp),
('/privacy', PrivacyHandler),
('/privacy-policy', PrivacyHandler),
('/terms', TermsHandler),
('/facebook', FbHandler),
('/about', AboutHandler),
('/contact', ContactHandler),
('/versus', VersusHandler),
('/timed', TimedHandler),
('/multiplayer', FriendsHandler),
('/games-multiplayer', GameMultiplayerHandler),
('/games', GamesHandler),
('/learn-english', LearnEnglishHandler),
('/learn-english/(.*)', EnglishLevelHandler),
('/campaign', CampaignHandler),
# need js rendering
(r'/campaign/..*', MainHandler),
(r'/campaign/..*/..*', MainHandler),
(r'/versus/..*', MainHandler),
(r'/tests', TestsHandler),
('/buy', BuyHandler),
('/sitemap', SitemapHandler),
] + gameon.routes, debug=ws.debug, config=config))