Skip to content

Commit 8ec6b8d

Browse files
committed
add: simple json generator in python
1 parent 1845247 commit 8ec6b8d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ python:
33
- "3.3"
44

55
#run tests
6-
script: python -m unittest
6+
#script: python -m unittest

source/json-generator.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import fnmatch
5+
from json import dumps, load
6+
7+
def writeJson(data, filename):
8+
try:
9+
jsondata = dumps(data, indent=2, skipkeys=True, sort_keys=True)
10+
fd = open(filename, 'w')
11+
fd.write(jsondata)
12+
fd.close()
13+
except:
14+
print 'ERROR writing', filename
15+
pass
16+
17+
def getDir(path, ext):
18+
matches = []
19+
for root, dirnames, filenames in os.walk(path):
20+
for filename in fnmatch.filter(filenames, ext):
21+
matches.append(os.path.join(root, filename))
22+
return matches
23+
24+
25+
result = []
26+
for file in getDir('../snippets/', '*.sublime-snippet'):
27+
line = open(file)
28+
content = line.read()
29+
trigger = content.split('<tabTrigger>')[1].split('</tabTrigger>')[0]
30+
description = content.split('<description>')[1].split('</description>')[0]
31+
32+
result.append({'trigger':trigger, 'description':description})
33+
34+
writeJson(result, "../snippets.json")
35+

0 commit comments

Comments
 (0)