-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (59 loc) · 1.9 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
import os,json,time,re
import project,getassets,projectInfo
import shutil
def getProjectData(url):
if 'http' not in url:
url='http://world.xiaomawang.com/community/main/compose/'+url
pdata=projectInfo.getProps(url)
return pdata
def gethtml(project):
command='node index.js %s'%project
#print(command)
with os.popen(command) as nodejs:
result= nodejs.read().replace('\n', '')
return result
def getAssets(str1,path):
li = re.findall('"md5ext":(.*?),"', str1)
#print(li)
li=list(set(li))
for i in li:
i=i.replace('"','')
i=i.replace('}','')
i=i.replace(']','')
i=i[:36]
#print('Downloading assests %s (%s/%s)'%( i,li.index(i),len(li) ))
files=getassets.download(i)
with open(path+'/'+i,"wb") as file:
file.write(files)
def createProject(url):
if 'http' not in url:
url='http://world.xiaomawang.com/community/main/compose/'+url
projectObj=project.getProjectJson(url)
path='tmp/'+projectObj['name']
try:
if os.path.exists(path):
f = open('./statics/'+path+'/output.html',encoding = "utf-8")
html=f.read()
f.close()
html=html.replace('\n','')
return '/tmp/'+projectObj['name']+'/output.html'
except:
pass
try:
os.mkdir(path)
except Exception as e:
print(e)
with open(path+'/project.json',"w") as file:
file.write(projectObj['data'])
getAssets(projectObj['data'],'./'+path)
makeProject(path)
gethtml('./statics/'+path)
f = open('./statics/'+path+'/output.html',encoding = "utf-8")
html=f.read()
f.close()
html=html.replace('\n','')
return '/tmp/'+projectObj['name']+'/output.html'
def makeProject(path):
shutil.make_archive('./statics/'+path+'/project.sb3', 'zip', path)
if __name__ == '__main__':
createProject(input('>'))