kmisc 2.1.119__tar.gz → 2.1.120__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.119
3
+ Version: 2.1.120
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -3447,6 +3447,51 @@ def Upper(src,default='org'):
3447
3447
  if isinstance(src,str): return src.upper()
3448
3448
  if default in ['org',{'org'}]: return src
3449
3449
  return default
3450
+
3451
+ def web_capture(url,output_file,image_size='1920,1080',wait_time=3):
3452
+ if isinstance(image_size,str):
3453
+ if 'x' in image_size:
3454
+ image_size=image_size.split('x')
3455
+ elif ',' in image_size:
3456
+ image_size=image_size.split(',')
3457
+ if isinstance(image_size,(list,tuple)) and len(image_size) == 2:
3458
+ image_size=','.join([str(i) for i in image_size])
3459
+ else:
3460
+ #Set it to default image size
3461
+ image_size='1920,1080'
3462
+
3463
+ if Import('import selenium'):
3464
+ return False,'Can not install selenium package'
3465
+ else:
3466
+ # Configure Chrome options for headless mode
3467
+ from selenium.webdriver.chrome.options import Options
3468
+ chrome_options = Options()
3469
+ chrome_options.add_argument('--headless') # Run in headless mode
3470
+ chrome_options.add_argument('--no-sandbox')
3471
+ chrome_options.add_argument('--disable-dev-shm-usage')
3472
+ chrome_options.add_argument(f"--window-size={image_size}") # Set window size
3473
+ # Initialize the Chrome driver
3474
+ driver = selenium.webdriver.Chrome(options=chrome_options)
3475
+ rc=False,output_file
3476
+ try:
3477
+ # Navigate to the URL
3478
+ driver.get(url)
3479
+
3480
+ # Wait for the page to load
3481
+ time.sleep(wait_time)
3482
+
3483
+ # Capture screenshot
3484
+ driver.save_screenshot(output_file)
3485
+ #print(f"Screenshot saved to {output_file}")
3486
+ rc=True,output_file
3487
+ except Exception as e:
3488
+ #print(f"Error capturing screenshot: {str(e)}")
3489
+ rc=False,str(e)
3490
+ finally:
3491
+ # Close the browser
3492
+ driver.quit()
3493
+ return rc
3494
+
3450
3495
  ############################################
3451
3496
  #Temporary function map for replacement
3452
3497
  ############################################
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.119
3
+ Version: 2.1.120
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
File without changes
File without changes
File without changes
File without changes
File without changes