Last active
December 14, 2015 14:13
-
-
Save smant/3ee8c171440f1d221ab6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | |
import subprocess | |
import json | |
from gscapi.widgets.models import Widget | |
def main(): | |
qs = Widget.objects.all() | |
cnt, total, data = 0, qs.count(),{} | |
for w in qs: | |
_input = { | |
"type":w.type, | |
"layout":w.layout, | |
"style": w.style | |
} | |
pipe = subprocess.Popen(['node','convert.js'] , | |
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
pipe.stdin.write(json.dumps(_input)) | |
data[w.id] = json.loads(pipe.communicate()[0]) | |
pipe.stdin.close() | |
print "\t%s/%s" % (cnt, total) | |
cnt+=1 | |
json.dump(data, open('widget-styles.json','w')) | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | |
import subprocess | |
import json | |
from gscapi.widgets.models import Widget | |
def main(): | |
qs = Widget.objects.all() | |
cnt, cnt_not_found, total, data = 0, 0, qs.count(),{} | |
data = json.load(open('widget-styles.json')) | |
for w in qs: | |
new_style = data.get(str(w.id)) | |
if new_style is None: | |
cnt_not_found += 1 | |
print '%s not found'%w.id | |
continue | |
w.style = new_style['style'] | |
w.save(update_fields = ['style']) | |
cnt+=1 | |
print "\t%s/%s" % (cnt, total) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment