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:
bohd4nx
2026-06-16 01:19:33 +03:00
parent 9f11ccb3ee
commit dc9661134d
51 changed files with 178 additions and 234 deletions
+33
View File
@@ -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()