cookies
This commit is contained in:
parent
cc365970a9
commit
c10c3a0beb
@ -290,21 +290,20 @@ async def update_cookies(
|
||||
cookie_data: CookieUpdate
|
||||
):
|
||||
try:
|
||||
# see if cookie file exists
|
||||
if not os.path.exists('cookies') and os.path.exists('cookies/tcg_cookies.json'):
|
||||
logger.info("Cannot find cookies")
|
||||
# Create cookies directory if it doesn't exist
|
||||
os.makedirs('cookies', exist_ok=True)
|
||||
|
||||
# Save cookies with timestamp
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
cookie_path = f'cookies/tcg_cookies.json'
|
||||
cookie_path = 'cookies/tcg_cookies.json'
|
||||
|
||||
# Save new cookies
|
||||
with open(cookie_path, 'w') as f:
|
||||
json.dump(cookie_data.cookies, f, indent=2)
|
||||
|
||||
# Update the "latest" cookies file
|
||||
with open('cookies/tcg_cookies_latest.json', 'w') as f:
|
||||
json.dump(cookie_data.cookies, f, indent=2)
|
||||
|
||||
return {"message": "Cookies updated successfully"}
|
||||
|
||||
except Exception as e:
|
||||
|
38
send_cookie.py
Normal file
38
send_cookie.py
Normal file
@ -0,0 +1,38 @@
|
||||
import browser_cookie3
|
||||
import requests
|
||||
import json
|
||||
|
||||
def send_tcg_cookies(api_url: str, browser_type='brave'):
|
||||
"""Get TCGPlayer cookies and send them to the API"""
|
||||
try:
|
||||
# Get cookies from browser
|
||||
cookie_getter = getattr(browser_cookie3, browser_type)
|
||||
cookie_jar = cookie_getter(domain_name='tcgplayer.com')
|
||||
|
||||
# Filter essential cookies
|
||||
cookies = {}
|
||||
for cookie in cookie_jar:
|
||||
if any(key in cookie.name.lower() for key in ['.aspnet', 'tcg', 'session']):
|
||||
cookies[cookie.name] = cookie.value
|
||||
|
||||
# Send to API
|
||||
headers = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{api_url}",
|
||||
headers=headers,
|
||||
json={'cookies': cookies}
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
print("Cookies updated successfully!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error updating cookies: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
API_URL = "http://192.168.1.41:8000/api/cookies" # Update with your API URL
|
||||
|
||||
send_tcg_cookies(API_URL)
|
Loading…
x
Reference in New Issue
Block a user