Skip to content

Instantly share code, notes, and snippets.

View naoyeye's full-sized avatar
🦾

J.Y Han naoyeye

🦾
View GitHub Profile
@naoyeye
naoyeye / 如何批量更新数据
Created August 14, 2012 09:10
web.py中如何批量更新mysql数据?
#controllers部分:
class media_describe:
@session.login_required
def POST(self):
f = web.input(image_title=[],image_describe=[],path={})
imageTitle = f.image_title
imageDescribe = f.image_describe
imagePath = f.path.split(',')
image.saveTitleDescribe(imagePath, imageTitle, imageDescribe) #更新数据库
import web
import mimetypes
class public:
def GET(self):
public_dir = 'public'
try:
file_name = web.ctx.path.split('/')[-1]
web.header('Content-type', mime_type(file_name))
return open(public_dir + web.ctx.path, 'rb').read()
server {
listen 80;
server_name 9y1p.com www.9y1p.com *.9y1p.com;
index index.html index.htm;
root /home/www/jiuyuyipin;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)?$
{
expires 30d;
access_log off;
@naoyeye
naoyeye / login.py
Created August 21, 2012 00:38
登录部分
def render_account(show='all',login_form=login_form()):
return view.base(view.account(show, login_form), user, site_name)
class login:
def GET(self):
return render_account(show='login_only')
def POST(self):
f = self.form()
if not f.validates(web.input(_unicode=False)):
@naoyeye
naoyeye / Awesome Screenshot
Created September 14, 2012 11:06
Awesome Screenshot > resouces > as-ff > lib > ui.js
function capture(option) {
var window = mediator.getMostRecentWindow("navigator:browser")
//为了在v2ex显示方便,这里加了个回车
.gBrowser.contentWindow;
var document = window.document;
var html = document.documentElement;
var w, h, x, y;
switch(option) {
case 'visible':
x = 0;
class post_image_delete:
@session.login_required
def POST(self, arg):
data = web.input()
path = data.path # 类似 '/static/upload/post_img/2012/11/9'
part_name = data.part_name # 类似 '201211981222_7a214d288112fe8ef99944aa7ce4d228'
homedir = os.getcwd()
imgPath = homedir + path
#上面组装的结果类似这样 : "/home/www/rhinocero" + "/static/upload/post_img/2012/11/9"
import os
homedir = os.getcwd()
part_name = '201211981222_7a214d288112fe8ef99944aa7ce4d228'
path = '/static/upload/post_img/2012/11/9'
imgPath = homedir + path
if os.path.isfile(imgPath + '/.DS_Store'):
os.remove(imgPath + '/.DS_Store')
class post_image_delete:
@session.login_required
def POST(self, arg):
data = web.input()
path = data.path
part_name = data.part_name
homedir = os.getcwd()
imgPath = homedir + path
if os.path.isfile(imgPath + '/.DS_Store'):
import web
import app.controllers
from config import view
def notfound():
return web.notfound(view.error())
urls = (
'/post/(\+?[1-9][0-9]*)', 'app.controllers.post.post_show', #正则匹配url 验证非零的正整数
)
#添加评论
class new_post_comment:
@session.login_required
def POST(self, pid):
data = web.input()
reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)' #正则匹配username
comment = data.postComment
comment = htmlquote(comment).strip().replace("\r\n", "<br/>") #内容过滤
usernames = re.findall(reg_regchar, comment) #得到username数组
nicknames = []