simplex 1.2.34__tar.gz → 1.2.35__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of simplex might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simplex
3
- Version: 1.2.34
3
+ Version: 1.2.35
4
4
  Summary: Official Python SDK for Simplex API
5
5
  Home-page: https://simplex.sh
6
6
  Author: Simplex Labs, Inc.
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="simplex",
5
- version="1.2.34",
5
+ version="1.2.35",
6
6
  packages=find_packages(),
7
7
  package_data={
8
8
  "simplex": ["browser_agent/dom/*.js"], # Include JS files in the dom directory
@@ -63,13 +63,14 @@ def login(website, proxies):
63
63
  website = 'https://' + website
64
64
 
65
65
  animated_print(f"[SIMPLEX] Creating login session for {website}")
66
- login_session_url = simplex.create_login_session(website, proxies=proxies)
67
-
68
- if login_session_url:
69
- animated_print("[SIMPLEX] Opening login page in your browser")
70
- webbrowser.open_new_tab(login_session_url)
66
+
67
+ fileName = simplex.create_login_session(website, proxies=proxies)
68
+
69
+ if fileName:
70
+ animated_print(f"[SIMPLEX] Login session created and saved to {fileName}")
71
71
  else:
72
- print(f"{Fore.YELLOW}[SIMPLEX] Warning: No login URL returned from the server{Style.RESET_ALL}")
72
+ print(f"{Fore.YELLOW}[SIMPLEX] Warning: Session data could not be saved{Style.RESET_ALL}")
73
+
73
74
  except Exception as e:
74
75
  raise click.ClickException(str(e))
75
76
 
@@ -1,10 +1,12 @@
1
1
  import requests
2
2
  import atexit
3
3
  from typing import Optional
4
- BASE_URL = "https://api.simplex.sh"
5
-
4
+ from playwright.sync_api import sync_playwright
5
+ import os
6
6
  import json
7
7
 
8
+ BASE_URL = "https://api.simplex.sh"
9
+
8
10
  class Playwright:
9
11
  def __init__(self, simplex_instance):
10
12
  self.simplex = simplex_instance
@@ -380,20 +382,81 @@ class Simplex:
380
382
  else:
381
383
  raise ValueError(f"Failed to wait: {response.json()['error']}")
382
384
 
383
- def create_login_session(self, url: str, proxies: Optional[bool] = True):
384
- response = requests.post(
385
- f"{BASE_URL}/create_login_session",
386
- headers={
387
- 'x-api-key': self.api_key
388
- },
389
- data={'url': url, 'proxies': proxies}
390
- )
391
- if 'succeeded' not in response.json():
392
- raise ValueError(f"It looks like the create_login_session action failed to return a response. Did you set your api_key when creating the Simplex class?")
393
- if response.json()["succeeded"]:
394
- return response.json()["login_session_url"]
395
- else:
396
- raise ValueError(f"Failed to create login session: {response.json()['error']}")
385
+ def create_login_session(self, url: str, save_directory: Optional[str] = None, proxies: Optional[bool] = True):
386
+ def get_website_name(url: str) -> str:
387
+ """Extract website name from URL"""
388
+ from urllib.parse import urlparse
389
+ netloc = urlparse(url).netloc
390
+ # Remove www. if present
391
+ if netloc.startswith('www.'):
392
+ netloc = netloc[4:]
393
+ return netloc.replace(".", "_")
394
+
395
+ with sync_playwright() as p:
396
+ browser = p.chromium.launch_persistent_context(
397
+ user_data_dir="",
398
+ channel="chrome",
399
+ headless=False,
400
+ args=[
401
+ '--disable-blink-features=AutomationControlled',
402
+ '--disable-automation',
403
+ ],
404
+ ignore_default_args=['--enable-automation']
405
+ )
406
+
407
+ # Close the default about:blank page
408
+ if len(browser.pages) > 0:
409
+ browser.pages[0].close()
410
+
411
+ # Create main page for login
412
+ main_page = browser.new_page()
413
+ main_page.goto(url)
414
+
415
+ # Create control page
416
+ control_page = browser.new_page()
417
+ control_page.set_content("""
418
+ <html>
419
+ <body style="display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f5f5f5;">
420
+ <button id="capture-btn" style="
421
+ padding: 20px 40px;
422
+ font-size: 18px;
423
+ cursor: pointer;
424
+ background-color: #2196F3;
425
+ color: white;
426
+ border: none;
427
+ border-radius: 5px;
428
+ box-shadow: 0 2px 4px rgba(0,0,0,0.2);
429
+ ">Click here when logged in to capture session</button>
430
+ </body>
431
+ </html>
432
+ """)
433
+
434
+ # Wait for button click using Playwright's wait_for_event
435
+ control_page.wait_for_selector('#capture-btn')
436
+ control_page.evaluate("""
437
+ () => {
438
+ return new Promise((resolve) => {
439
+ document.getElementById('capture-btn').onclick = () => {
440
+ resolve(true);
441
+ }
442
+ });
443
+ }
444
+ """)
445
+
446
+ storage = browser.storage_state()
447
+ if save_directory:
448
+ filename = os.path.join(save_directory, get_website_name(url) + "_session_data.json")
449
+ else:
450
+ filename = get_website_name(url) + "_session_data.json"
451
+
452
+ with open(filename, 'w') as f:
453
+ json.dump(storage, f, indent=2)
454
+
455
+ print(f"Session data saved to '{filename}'")
456
+
457
+ browser.close()
458
+
459
+ return filename
397
460
 
398
461
  def restore_login_session(self, session_data: str, cdp_url: str = None):
399
462
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simplex
3
- Version: 1.2.34
3
+ Version: 1.2.35
4
4
  Summary: Official Python SDK for Simplex API
5
5
  Home-page: https://simplex.sh
6
6
  Author: Simplex Labs, Inc.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes