-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b1583d
commit e06c2d5
Showing
5 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
target/ | ||
Cargo.lock | ||
Cargo.lock | ||
__pycache__ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from .rookiepy import firefox, brave, edge, chrome, chromium_based | ||
from typing import List, Any | ||
import http.cookiejar | ||
|
||
|
||
__all__ = [ | ||
"firefox", | ||
"brave", | ||
"edge", | ||
"chrome", | ||
"chromium_based", | ||
"to_dict", | ||
"to_cookiejar", | ||
"create_cookie" | ||
] | ||
|
||
def create_cookie(host, path, secure, expires, name, value, http_only): | ||
"""Shortcut function to create a cookie""" | ||
# HTTPOnly flag goes in _rest, if present (see https://github.com/python/cpython/pull/17471/files#r511187060) | ||
return http.cookiejar.Cookie(0, name, value, None, False, host, host.startswith('.'), host.startswith('.'), path, | ||
True, secure, expires, False, None, None, | ||
{'HTTPOnly': ''} if http_only else {}) | ||
|
||
|
||
def to_dict(cookies: List[Any]): | ||
return [ | ||
{'name': c.name, | ||
'host': c.host, | ||
'path': c.path, | ||
'secure': c.secure, | ||
'expires': c.expires, | ||
'value': c.value, | ||
'http_only': c.http_only, | ||
'same_site': c.same_site | ||
} | ||
for c in cookies | ||
] | ||
|
||
def to_cookiejar(cookies: List[Any]): | ||
cj = http.cookiejar.CookieJar() | ||
|
||
for cookie_obj in cookies: | ||
c = create_cookie( | ||
cookie_obj.host, | ||
cookie_obj.path, | ||
cookie_obj.secure, | ||
cookie_obj.expires, | ||
cookie_obj.name, | ||
cookie_obj.value, | ||
cookie_obj.http_only, | ||
|
||
) | ||
cj.set_cookie(c) | ||
return cj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import requests | ||
import re | ||
from rookiepy import brave, to_cookiejar | ||
import browser_cookie3 | ||
|
||
def extract_username(html): | ||
re_pattern = r'dashboard/ajax_context_list\?current_context=(.+)' | ||
match = re.search(re_pattern, html) | ||
if match: | ||
return match.group(1) | ||
return "" | ||
|
||
|
||
def main(): | ||
try: | ||
# Create a custom cookie store | ||
cookies = brave(["github.com"]) | ||
cj = to_cookiejar(cookies) | ||
|
||
headers = { | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", | ||
} | ||
response = requests.get("https://github.com/", cookies=cj, headers=headers) | ||
content = response.text | ||
username = extract_username(content) | ||
if not username: | ||
print("Not logged in to Github") | ||
else: | ||
print(f"Logged in to Github as {username}") | ||
|
||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use rookie; | ||
|
||
fn main() { | ||
let cookies = rookie::firefox(Some(vec!["google.com"])).unwrap(); | ||
let cookies = rookie::brave(Some(vec!["github.com"])).unwrap(); | ||
println!("{:?}", cookies); | ||
} |