-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
31 lines (28 loc) · 1.05 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
import webapp2
import re
class MainPage(webapp2.RequestHandler):
def get(self, **kwargs):
self.response.out.write(open('index.html').read())
class ArticlePage(webapp2.RequestHandler):
def get(self, **kwargs):
bots = '|'.join([
'Googlebot',
'bingbot',
'msnbot',
'facebookexternalhit',
'Facebot',
'Twitterbot',
'Google-Structured-Data-Testing-Tool'
])
if re.search(bots, self.request.headers.get('User-Agent'), re.I):
self.response.out.write(open('data/articles/' + kwargs['article_id'] + '.html').read())
else:
self.response.out.write(open('index.html').read())
app = webapp2.WSGIApplication([
webapp2.Route('/', handler=MainPage),
webapp2.Route('/index.html', handler=MainPage),
webapp2.Route('/<page>/<category>', handler=MainPage),
webapp2.Route('/<page>/<category>/', handler=MainPage),
webapp2.Route('/<page>/<category>/<article_id>', handler=ArticlePage),
webapp2.Route('/<page>/<category>/<article_id>/', handler=ArticlePage),
], debug=True)