Skip to content

Instantly share code, notes, and snippets.

@MaskRay
Last active November 13, 2016 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MaskRay/fae75a66f707d774b2335f61701221e8 to your computer and use it in GitHub Desktop.
Save MaskRay/fae75a66f707d774b2335f61701221e8 to your computer and use it in GitHub Desktop.
Import *.qq.com cookies from Firefox on VPS to local Chrome
#!/usr/bin/env python3
import os, sqlite3, sys, time
#wxuin wxsid webwx_data_ticket
if os.system('rsync -a linode-ca:/home/ray/.mozilla/firefox/5psswi97.default/cookies.sqlite /tmp/'):
sys.exit(1)
firefox = sqlite3.connect('/tmp/cookies.sqlite')
chrome = sqlite3.connect('/home/ray/.config/google-chrome/Default/Cookies')
ldap_epoch = -11644473600*1000000
now = time.time()
with chrome:
chrome.execute('delete from cookies where host_key like "%qq.com"')
c = firefox.cursor()
for row in c.execute('select * from moz_cookies where baseDomain = "qq.com" and name in ("wxuin","wxsid","webwx_data_ticket")'):
id, baseDomain, originAttributes, name, value, host, path, expiry, lastAccessed, creationTime, isSecure, isHttpOnly, appId, inBrowserElement = row
if now < expiry:
with chrome:
chrome.execute('insert into cookies values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', (
creationTime - ldap_epoch,
host,
name,
value,
path,
expiry*1000000 - ldap_epoch,
isSecure,
isHttpOnly,
lastAccessed - ldap_epoch,
1,
1,
1,
'',
0
))
# Firefox cookies
#CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, originAttributes TEXT NOT NULL DEFAULT '', name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, originAttributes))
# Chrome cookies
#CREATE TABLE cookies (creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY,host_key TEXT NOT NULL,name TEXT NOT NULL,value TEXT NOT NULL,path TEXT NOT NULL,expires_utc INTEGER NOT NULL,secure INTEGER NOT NULL,httponly INTEGER NOT NULL,last_access_utc INTEGER NOT NULL, has_expires INTEGER NOT NULL DEFAULT 1, persistent INTEGER NOT NULL DEFAULT 1,priority INTEGER NOT NULL DEFAULT 1,encrypted_value BLOB DEFAULT '', firstpartyonly INTEGER DEFAULT 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment