Skip to content

Instantly share code, notes, and snippets.

@lacek
Created April 11, 2019 09:24
Show Gist options
  • Save lacek/00086bf570e2fcb4c65a662e4264bc21 to your computer and use it in GitHub Desktop.
Save lacek/00086bf570e2fcb4c65a662e4264bc21 to your computer and use it in GitHub Desktop.
Converts cookie JSON exported from EditThisCookie to formats for wget/curl
#!/usr/bin/env python2.7
from __future__ import print_function
import argparse
import json
import sys
parser = argparse.ArgumentParser(
description='Converts cookie JSON exported from EditThisCookie to formats for wget/curl')
parser.add_argument('-f', '--format', choices=('netscape', 'curl',),
default='netscape', help='Output format')
parser.add_argument('input', type=argparse.FileType('r'),
help='Input JSON exported from EditThisCookie')
parser.add_argument('output', type=argparse.FileType('w'), default='-', nargs='?',
help='Output cookies txt')
args = parser.parse_args()
for item in json.load(args.input):
domain = item['domain']
if args.format == 'curl':
domain = ('#HttpOnly_' if item['httpOnly'] else '') + domain
print(domain,
'TRUE' if item['hostOnly'] else 'FALSE',
item['path'],
'TRUE' if item['secure'] else 'FALSE',
int(item['expirationDate']) if 'expirationDate' in item else 0,
item['name'],
item['value'],
sep='\t', file=args.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment