Skip to content

Commit

Permalink
feat(python): add netscape format
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed May 6, 2024
1 parent 0b05ef2 commit f0ea5a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bindings/python/rookiepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
opera_gx,
librewolf,
load,
any_browser
any_browser,
version
)

__all__ = [
Expand Down Expand Up @@ -120,4 +121,23 @@ def to_cookiejar(cookies: CookieList) -> http.cookiejar.CookieJar:
cj.set_cookie(c)
return cj

def to_netscape(cookies: CookieList) -> http.cookiejar.CookieJar:
"""
Convert a list of dictionaries representing cookies to a netscape compatible string.
:param cookies: A list of dictionaries representing cookies
:return: A string containing the converted cookies
"""
data = f"""\
# Netscape HTTP Cookie File
# Generated by Rookie {version()}
# Edit at your own risk.\n"""

for cookie in cookies:
subdomain = "TRUE"
https_only = "FALSE"
data += f"{cookie.domain}\t{subdomain}\t{cookie.path}\t{https_only}\t{cookie.expires if cookie.expires else 0}\t{cookie.name}\t{cookie.value}\n"

return data


9 changes: 9 additions & 0 deletions bindings/python/rookiepy/rookiepy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ from sys import platform

CookieList = List[Dict[str, Any]]

def version() -> str:
"""
Get rookie version
:return: rookie version
"""
...


def firefox(domains: Optional[List[str]] = None) -> CookieList:
"""
Extract Cookies from Firefox
Expand Down

0 comments on commit f0ea5a3

Please sign in to comment.