mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
Refactor cookie handling and service structure
- Removed the old CookieResult model from pyfragment.core.models and created a new one in pyfragment.services.cookies.models. - Implemented get_cookies_from_browser function in pyfragment.services.cookies.service to extract cookies directly from supported browsers. - Updated imports across various modules to reflect the new structure and removed unused imports. - Cleaned up models in ads, anonymous_numbers, giveaways, marketplace, and purchases domains by removing unnecessary __all__ declarations. - Added new example scripts for cookie extraction and various purchase functionalities. - Consolidated constants into a new pyfragment.core.constants module for better organization.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
Example: extract Fragment cookies directly from your browser.
|
||||
|
||||
get_cookies_from_browser() reads the Fragment session cookies from a locally
|
||||
installed browser — no manual copy-paste required.
|
||||
|
||||
Supported browsers: arc, brave, chrome, chromium, chromium_based, edge,
|
||||
firefox, firefox_based, librewolf, opera, opera_gx,
|
||||
safari, vivaldi.
|
||||
|
||||
The returned CookieResult.cookies dict can be passed directly to FragmentClient.
|
||||
"""
|
||||
|
||||
from pyfragment import CookieError, get_cookies_from_browser
|
||||
|
||||
|
||||
def main() -> None:
|
||||
try:
|
||||
result = get_cookies_from_browser("chrome") # or "firefox", "edge", "brave", ...
|
||||
except CookieError as e:
|
||||
print(f"Could not read cookies: {e}")
|
||||
return
|
||||
|
||||
print(f"Cookies expire: {result.expires}")
|
||||
print(f"Keys found: {list(result.cookies.keys())}")
|
||||
|
||||
# Pass the extracted cookies directly to FragmentClient
|
||||
# async with FragmentClient(seed=SEED, api_key=API_KEY, cookies=result.cookies) as client:
|
||||
# ...
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user