coding utf-8 from google appengine api import images from google appen

 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
# -*- coding: utf-8 -*-
from google.appengine.api import images
from google.appengine.ext import db
from google.appengine.api import users
from vendor import web
from django.utils import simplejson
from models import *
import logging
import datetime, hashlib
urls = (
'/', 'index',
'/gen', 'gen',
#'/add', 'add',
'/(.*)', 'redirect',
)
render = web.template.render('templates', base='base')
class index:
def GET(self):
return render.index()
class redirect:
def GET(self, uu):
try:
ur = db.Query(Url).filter('shorturl = ', uu).get()
except:
logging.error('Невозможно получить данные по запросу: ' + uu)
if ur:
return web.seeother(ur.url)
else:
return web.seeother('/')
class gen:
def POST(self):
i = web.input()
short = hashlib.md5(i.url).hexdigest()
sh = Url(url=i.url, \
shorturl=short[:5])
sh.put()
str = []
str.append(short[:5])
return short[:5]
def GET(self):
return web.seeother('/')
app = web.application(urls, globals())
main = app.cgirun()