Entry 3367

chromium cookies

   

Submitted by sleepwalker on March 17, 2010 at 3:01 p.m.
Language: Python. Code size: 1.1 KB.

#!/usr/bin/python
""""Cookies-exporter
This script exports rows from Chromium cookies-db to Netscape cookies file format
Author: Artem [sleepwalker] Chistyakov
Bugs:
In this version script doesn't dynamically put information about secure cookies
"""
import sys
import sqlite3
import time,  calendar

if len(sys.argv) == 1:
    print 'Run syntax: %s <sitename>' % sys.argv[0]
    sys.exit()

USERNAME = 'lunatik'
DB_PATH = '/home/'+USERNAME+'/.config/chromium/Default/Cookies'
SITE_NAME = sys.argv[1]
EPOCH = calendar.timegm([1601, 1, 1, 0, 0, 0, 0, 1, 0])

conn = sqlite3.connect(DB_PATH)

c = conn.cursor()

try:
    c.execute("SELECT host_key, name, value, expires_utc, secure, httponly from cookies where host_key LIKE '%"+SITE_NAME+"%'")
except sqlite3.OperationalError:
    print 'Oops! It seems the database is locked. Sorry!' 
    sys.exit()

for row in c:
    expired = (row[3] / 1000000) + EPOCH 
    print '%(hostname)s\tTRUE\t/\tFALSE\t%(expired)d\t%(name)s\t%(value)s' % \
    {'hostname': row[0], "expired": expired,  "name":row[1],  "value":row[2]}
    
c.close()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).