Skip to content

Instantly share code, notes, and snippets.

@ahmedlahrizi
Created August 22, 2023 10:55
Show Gist options
  • Save ahmedlahrizi/aa5e7648f1f4ca1c8794e94c1d618aee to your computer and use it in GitHub Desktop.
Save ahmedlahrizi/aa5e7648f1f4ca1c8794e94c1d618aee to your computer and use it in GitHub Desktop.
from sys import argv
import json
import dateparser
if len(argv) != 3:
print("Usage: python ns_cookies.py {Cookies in json format} {Output file}")
with open(argv[1], "r") as db:
s = json.load(db)
with open(argv[2], "w") as r:
for json_cookie in s:
epoch_time = dateparser.parse(json_cookie["ExpireDate"], languages=["en"])
epoch_time = str(max(0, int(epoch_time.timestamp())))
netscape_cookie = [json_cookie["Host"],
"TRUE" if json_cookie["Host"][0] == "." else "FALSE",
json_cookie["Path"],
"TRUE" if json_cookie["IsSecure"] == True else "FALSE",
epoch_time,
json_cookie["KeyName"],
json_cookie["Value"]]
r.write("\t".join(netscape_cookie) + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment