Skip to content

Instantly share code, notes, and snippets.

@victorhaggqvist
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorhaggqvist/9b709cdb19b162a09ca0 to your computer and use it in GitHub Desktop.
Save victorhaggqvist/9b709cdb19b162a09ca0 to your computer and use it in GitHub Desktop.
*.txt
*.css
.idea
#!/usr/bin/env python
# coding: utf-8
import urllib2 as urllib
import re
import difflib
import sys
__author__ = 'Victor Häggqvist'
def get_bootstrap(version):
print 'Downloading CSS..'
latest = urllib.Request('https://raw.githubusercontent.com/twbs/bootstrap/'+version+'/dist/css/bootstrap.css')
css = open('bootstrap.css', 'w')
css.write(urllib.urlopen(latest).read())
css.close()
print 'Got CSS'
def get_completion_from_master():
print 'Downloading completions..'
latest = urllib.Request('https://raw.githubusercontent.com/victorhaggqvist/Sublime-Better-Completion/master/sublime-completions/API-completions-twitter-bootstrap3.sublime-settings')
completion = open('completion.txt', 'w')
completion.write(urllib.urlopen(latest).read())
completion.close()
print 'Got completion'
def read_selectors():
fcss = open('bootstrap.css')
css = fcss.read()
match = re.findall(r'[\n||\s](\.[a-z]{1}[a-z0-9-]+)', css)
final = list(set(match))
final.sort()
# print final
fselectors = open('selectors.txt', 'w')
for line in final:
fselectors.write(line+'\n')
def read_completion():
fcom = open('completion.txt')
com = fcom.read()
match = re.findall(r'"([a-z]{1}[a-z0-9-]+)\\t', com)
final = list(set(match))
final.sort()
# print final
fscom = open('foo.txt', 'w')
for line in final:
fscom.write('.'+line+'\n')
def make_diff():
bs = open('selectors.txt','r')
com = open('foo.txt','r')
diff = difflib.ndiff(com.read().splitlines(), bs.read().splitlines())
print 'Diff of Bootstrap CSS vs Completion patterns'
print '''
Help
+ means is in bootstrap but not completion, should be added
- means no longer in bootstrap, should be removed
'''
print '\n'.join(x for x in diff if (x.startswith('- ') or x.startswith('+ ')))
def new_stuff():
bs = open('selectors.txt','r')
com = open('foo.txt','r')
diff = difflib.ndiff(com.read().splitlines(), bs.read().splitlines())
print '\n'.join('[ "'+x[3:]+'\\tBootstrapClass", "'+x[3:]+'" ],' for x in diff if x.startswith('+ '))
def main():
if len(sys.argv)<2:
print "Usage: bsdiff.py [bootstrap version]"
exit(0)
bootstrap_version = 'v'+sys.argv[1]
get_bootstrap(bootstrap_version)
get_completion_from_master()
read_selectors()
read_completion()
make_diff()
new_stuff()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment