-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.py
61 lines (55 loc) · 1.62 KB
/
index.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
import sys
import os,glob
import uuid
import zipfile
import shutil
path="./"
os.chdir(path)
shutil.rmtree('dist')
os.mkdir('dist')
for filename in os.listdir("./30-seconds-of-code/snippets"):
file = open("./30-seconds-of-code/snippets/"+filename,'r',-1,"UTF-8")
i=1
title=''
keyword=''
codeline=0
titleline=3
content=''
end=0
uuidstr=str(uuid.uuid1())
for line in file.readlines():
if i==1:
keyword=line.replace("### ",'')
if keyword=="anagrams\n":
titleline=5
if i==titleline:
title=line
if line=='```js\n' and codeline==0 and end==0:
codeline=i
if line=='```\n' and end==0 :
end=1
if end==0 and i>codeline and codeline>0:
content+=line.replace('\n','\\n')
i+=1
output = open('./dist/'+keyword.replace("\n","")+'['+uuidstr+'].json', 'w+')
output.write('{\n')
output.write(' "alfredsnippet" : {\n' )
output.write(' "keyword" : "' + keyword.replace("\n","") + '",\n')
output.write(' "dontautoexpand" : true,\n' )
output.write(' "name" : "' + title.replace("\n","") + '",\n')
output.write(' "snippet": "' + content.replace("\n","").replace('"','\\"')+ '",\n')
output.write(' "uid": "' + uuidstr+ '"\n')
output.write(' }\n');
output.write('}\n');
output.close( )
z = zipfile.ZipFile("3sc.alfredsnippets", 'w')
z.write("./icon.png")
path2="./dist"
os.chdir(path2)
testdir='.'
for d in os.listdir():
z.write(testdir+os.sep+d)
z.close()