-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpyueditor.py
More file actions
137 lines (115 loc) · 4.84 KB
/
webpyueditor.py
File metadata and controls
137 lines (115 loc) · 4.84 KB
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
#coding=utf-8
import base64
import uuid
import urllib2
import os
import sys
sys.path.append("./lib/webpy")
import web
ueconfig_dir = 'static/upload'
ueconfig_url = '/' + ueconfig_dir
def listImage(rootDir, retlist):
print rootDir
for cfile in os.listdir(rootDir):
print "@@@@@@@@@@@@@@"
print cfile
path = os.path.join(rootDir, cfile)
if os.path.isdir(path):
listImage(path, retlist)
else:
if cfile.endswith('.gif') or cfile.endswith('.png') or cfile.endswith('.jpg') or cfile.endswith('.bmp'):
retlist.append('/static/upload/' + cfile)
def saveUploadFile(fileName, content):
fileName = fileName.replace('\\', '/') # replaces the windows-style slashes with linux ones.
fout = open(ueconfig_dir + '/' + fileName, 'wb') # creates the file where the uploaded file should be stored
fout.write(content) # writes the uploaded file to the newly created file.
fout.close() # closes the file, upload complete.
class Ue_ImageUp:
def GET(self):
reqData = web.input()
if 'fetch' in reqData:
web.header('Content-Type', 'text/javascript')
return 'updateSavePath(["upload"]);'
web.header("Content-Type", "text/html; charset=utf-8")
return ""
def POST(self):
postData = web.input(upfile={}, pictitle="")
web.debug(postData)
fileObj = postData.upfile
picTitle = postData.pictitle
fileName = fileObj.filename
newFileName = str(uuid.uuid1()) + ".png"
saveUploadFile(newFileName, fileObj.file.read())
return "{'url':'" + ueconfig_url + '/' + newFileName + "','title':'" + picTitle + "','original':'" + fileName + "','state':'" + "SUCCESS" + "'}"
class Ue_FileUp:
def GET(self):
web.header("Content-Type", "text/html; charset=utf-8")
return ""
def POST(self):
postData = web.input(upfile={})
fileObj = postData.upfile
fileName = postData.Filename
ext = '.' + fileName.split('.')[-1]
#web.py的static目录对中文文件名不支持,会404
newFileName = str(uuid.uuid1()) + ext
#fileNameFormat = postData.fileNameFormat
saveUploadFile(newFileName, fileObj.file.read())
return "{'url':'" + ueconfig_url + '/' + newFileName + "','fileType':'" + ext + "','original':'" + fileName + "','state':'" + "SUCCESS" + "'}"
class Ue_ScrawlUp:
def GET(self):
web.header("Content-Type", "text/html; charset=utf-8")
return ""
def POST(self):
reqData = web.input(upfile={})
if 'action' in reqData:
if reqData.action == 'tmpImg':
#上传背景
fileObj = reqData.upfile
fileName = fileObj.filename
saveUploadFile(fileName, fileObj.file.read())
return "<script>parent.ue_callback(" + ueconfig_url + '/' + fileName + "','" + "SUCCESS" + "')</script>"
else:
base64Content = reqData.content
fileName = str(uuid.uuid1()) + '.png'
saveUploadFile(fileName, base64.decodestring(base64Content))
return "{'url':'" + ueconfig_url + '/' + fileName + "',state:'" + "SUCCESS" + "'}"
class Ue_GetRemoteImage:
def GET(self):
web.header("Content-Type", "text/html; charset=utf-8")
return ""
def POST(self):
postData = web.input()
urls = postData.upfile
#urls = urls.replace('&','&')
urllist = urls.split("ue_separate_ue")
fileType = [".gif", ".png", ".jpg", ".jpeg", ".bmp"]
outlist = []
for fileurl in urllist:
if not fileurl.startswith('http'):
continue
ext = "." + fileurl.split('.')[-1]
web.debug(ext + "|" + fileurl)
if ext in fileType:
fileName = str(uuid.uuid1()) + ext
saveUploadFile(fileName, urllib2.urlopen(fileurl).read())
outlist.append(ueconfig_url + "/" + fileName)
outlist = "ue_separate_ue".join(outlist)
return "{'url':'" + outlist + "','tip':'远程图片抓取成功!','srcUrl':'" + urls + "'}"
class Ue_GetMovie:
def POST(self):
reqData = web.input()
skey = reqData.searchKey
vtype = reqData.videoType
surl = 'http://api.tudou.com/v3/gw?method=item.search&appKey=myKey&format=json&kw=' + skey + '&pageNo=1&pageSize=20&channelId=' + vtype + '&inDays=7&media=v&sort=s'
htmlContent = urllib2.urlopen(surl).read()
web.debug(htmlContent)
return htmlContent
class Ue_ImageManager:
def POST(self):
reqData = web.input()
if 'action' in reqData:
if reqData.action == 'get':
retfiles = []
listImage(ueconfig_dir, retfiles)
htmlContent = "ue_separate_ue".join(retfiles)
return htmlContent