-
-
Save ExE-Boss/22baa3558972195d4edc3794d4f7ddb8 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3 | |
import os.path | |
import glob | |
import sqlite3 | |
import json | |
def main(): | |
styles_glob = os.path.expanduser('~/AppData/Roaming/Mozilla/Firefox/Profiles/*.default/stylish.sqlite'); | |
styles_path = glob.glob(styles_glob)[0]; | |
conn = sqlite3.connect(styles_path); | |
c = conn.cursor(); | |
styles = []; | |
for row in c.execute('SELECT * FROM styles'): | |
_id, url, updUrl, md5Url, name, code, enabled, origCode, idUrl, bg, origMd5 = row; | |
styles.append({ | |
'method': 'saveStyle', | |
'name': name, | |
'enabled': bool(enabled), | |
'sections': [{ | |
'code': code, | |
}], | |
'updateUrl': updUrl or None, | |
'md5Url': md5Url or None, | |
'url': url or None, | |
'originalMd5': origMd5 or None, | |
'id': _id, | |
}); | |
conn.close(); | |
with open('stylus.json', 'w') as stylus: | |
json.dump(styles, stylus); | |
if __name__ == '__main__': | |
main(); |
I've not used Python before. I tried installing it and putting export-from-stylish.py into the Lib folder, but beyond that, I just simply cannot figure out how to make this work. I search and search and search and keep getting "it's simple!" results but I can't seem to find anything with specific instructions on how to just run a module. Everything I try returns "invalid syntax". All I want is to convert stylish.sqlite to json. Can someone post instructions as to where to put the files and what commands to run in Python, for those of use who are completely new to it?
First of all, thanks for this script! Transferring all my styles over by hand (they're all self-created, so I can't "just reinstall them") would have been a real pain. :)
As for BlohoJo's previous comment, I guess it's been three months but maybe someone will benefit from a reply. It's not worth getting too deep into an answer here, since you'd basically just wind up recreating the Python beginner documentation, but basically what you need to do is:
- Download the above script anywhere. Doesn't really matter where; the script by default will write a file called
stylus.json
in the current directory, but if you were able to put the script in that directory then obviously you can write to it. - Edit the profile path (line 9 of the code). The above looks like it probably works for MS Windows systems; I changed it to
~/.mozilla/firefox/*.default/stylish.sqlite
for Ubuntu. I'm not familiar with OS X (sounds like that's what you've got, judging by your reference to a "Lib folder"), but you just need to find your profile directory and update that path accordingly. - Run
python export-from-stylish.py
and look for thestylus.json
file in your current directory.
If the above doesn't work, you're going to need some actual Python-centric troubleshooting and you should hit up a Python IRC channel or StackOverflow or something, because a GitHub comment thread isn't really the right place. :)
@BlohoJo @jbuttery This is the Windows fork, for the Linux version, see the original at https://gist.github.com/f1u77y/715f0dd03fc18039a6549de557370b97
Thank you.