kmisc 2.1.122__tar.gz → 2.1.123__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.122
3
+ Version: 2.1.123
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -3453,7 +3453,7 @@ def Upper(src,default='org'):
3453
3453
  if default in ['org',{'org'}]: return src
3454
3454
  return default
3455
3455
 
3456
- def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certificate_error=False,username=None,password=None,auth_fields={'auth':{'type':'name','name':('username','password')},'submit':{'type':'submit','name':None}},next_do={},gpu=False,live_capture=0,capture_method='file',find_string=None,found_space='\n',log=None,ocr_enhance=False,daemon=False,backup=False):
3456
+ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certificate_error=False,username=None,password=None,auth_fields={'auth':{'type':'name','name':('username','password')},'submit':{'type':'submit','name':None}},next_do={},gpu=False,live_capture=0,capture_method='file',capture_type='png',video_file=None,find_string=None,found_space='\n',log=None,ocr_enhance=False,daemon=False,backup=False):
3457
3457
  #auth_fields.submit.type : name : login button with name
3458
3458
  # : id : login button with id
3459
3459
  # : submit : submit button without name or id
@@ -3463,6 +3463,8 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3463
3463
  #auth_fields.auth.name : (usernane,password) : username/password field string for name or id
3464
3464
  #next_do : put data and click submit
3465
3465
 
3466
+ _url=url.split('/')
3467
+ url=WEB().url_join(*_url[1:],method=_url[0])
3466
3468
  if isinstance(image_size,str):
3467
3469
  if 'x' in image_size:
3468
3470
  image_size=image_size.split('x')
@@ -3475,8 +3477,9 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3475
3477
  if isinstance(image_size,(list,tuple)) and len(image_size) == 2:
3476
3478
  image_size=','.join([str(i) for i in image_size])
3477
3479
  else:
3478
- #Set it to default image size
3479
- image_size='1920,1080'
3480
+ if not IsIn(image_size,[None,'full','fullscreen','full_screen','auto']):
3481
+ #Set it to default image size
3482
+ image_size='1920,1080'
3480
3483
 
3481
3484
  if Import('import selenium'):
3482
3485
  return False,'Can not install selenium package'
@@ -3484,6 +3487,8 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3484
3487
  if backup:
3485
3488
  Import('filecmp')
3486
3489
  Import('shutil')
3490
+ if capture_type in ['mov','mp4']:
3491
+ Import('cv2',install_name='opencv-python')
3487
3492
 
3488
3493
  ocr=None
3489
3494
  if capture_method != 'file':
@@ -3497,7 +3502,9 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3497
3502
  chrome_options.add_argument('--headless') # Run in headless mode
3498
3503
  chrome_options.add_argument('--no-sandbox')
3499
3504
  chrome_options.add_argument('--disable-dev-shm-usage')
3500
- chrome_options.add_argument(f"--window-size={image_size}") # Set window size
3505
+
3506
+ if image_size.lower() not in ['full','fullscreen','full_screen','auto']:
3507
+ chrome_options.add_argument(f"--window-size={image_size}") # Set window size
3501
3508
  if not gpu:
3502
3509
  chrome_options.add_argument("--disable-gpu")
3503
3510
  if ignore_certificate_error:
@@ -3505,6 +3512,8 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3505
3512
  chrome_options.add_argument('--allow-insecure-localhost') # gnore-certificate-errors
3506
3513
  # Initialize the Chrome driver
3507
3514
  driver = selenium.webdriver.Chrome(options=chrome_options)
3515
+ if image_size.lower() in ['full','fullscreen','full_screen','auto']:
3516
+ driver.maximize_window()
3508
3517
  rc=False,output_file
3509
3518
  try:
3510
3519
  # Navigate to the URL
@@ -3559,7 +3568,7 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3559
3568
  next_do_button = driver.find_element(By.XPATH, "//button[@type='submit']")
3560
3569
  next_do_button.click()
3561
3570
 
3562
- def _capture_(live_capture,driver,output_file,wait_time,capture_method,backup,ocr,log,find_string,daemon):
3571
+ def _capture_(live_capture,driver,output_file,wait_time,capture_method,backup,ocr,log,find_string,daemon,video_file):
3563
3572
  def wait_body(driver,timeout=10):
3564
3573
  #wait until get screen data
3565
3574
  try:
@@ -3578,23 +3587,37 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3578
3587
  time.sleep(timeout)
3579
3588
 
3580
3589
  live_capture=Int(live_capture)
3581
- wait_time=Int(wait_time,10)
3590
+ if not isinstance(wait_time,(int,float)):
3591
+ wait_time=Int(wait_time,10)
3582
3592
  backup_idx=0
3583
3593
  if backup:
3584
3594
  backup=Int(backup,2)
3585
3595
  if isinstance(live_capture,int) and live_capture > wait_time*2:
3596
+ #Keep capture
3586
3597
  Time=TIME()
3598
+ if capture_type in ['mov','mp4']:
3599
+ frame_rate=1/wait_time
3600
+ window_size = driver.get_window_size()
3601
+ width = window_size['width']
3602
+ height = window_size['height']
3603
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for MP4
3604
+ video_writer = cv2.VideoWriter(video_file, fourcc, frame_rate, (width, height))
3587
3605
  while True:
3588
3606
  if Time.Out(live_capture):
3589
3607
  driver.quit()
3590
- return False
3608
+ if capture_type in ['mov','mp4']:
3609
+ video_writer.release()
3610
+ return True
3611
+ else:
3612
+ #Do something, but not return until timeout. So return False
3613
+ return False
3591
3614
  # Capture screenshot
3592
3615
  if log:
3593
- if log in ['screen','log','print',print]:
3616
+ if IsIn(log,['screen','log','print',print]):
3594
3617
  printf(Dot(),direct=True)
3595
3618
  else:
3596
3619
  printf(Dot(),log=log,direct=True)
3597
- if backup:
3620
+ if backup and capture_type not in ['mov','mp4']:
3598
3621
  save_file='{}.{}'.format(output_file,backup_idx%backup)
3599
3622
  else:
3600
3623
  save_file=output_file
@@ -3602,43 +3625,82 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certif
3602
3625
  wait_body(driver,timeout=wait_time)
3603
3626
  #capture
3604
3627
  driver.save_screenshot(save_file)
3605
- if backup:
3606
- if backup == 2:
3607
- comp_a=f'{output_file}.0'
3608
- comp_b=f'{output_file}.1'
3609
- if os.path.isfile(comp_a) and os.path.isfile(comp_b):
3610
- if filecmp.cmp(comp_a,comp_b):
3611
- if log:
3612
- if log in ['screen','log','print',print]:
3613
- printf(Dot(),direct=True)
3614
- else:
3615
- printf(Dot(),log=log,direct=True)
3616
- time.sleep(wait_time)
3617
- backup_idx+=1
3618
- continue
3619
- shutil.copy2(save_file,output_file)
3620
- if IsIn(capture_method,['log','screen','text']):
3621
- found_words=ocr.Text(image_file=save_file)
3622
- found_strings=found_space.join(found_words)
3623
- printf(found_strings,log=log,mode='d' if log else 's')
3624
- if find_string:
3625
- if find_string in found_strings:
3626
- driver.quit()
3627
- return True
3628
+ if capture_type in ['mov','mp4']:
3629
+ #Make a video file
3630
+ frame = cv2.imread(save_file)
3631
+ frame = cv2.resize(frame, (width, height))
3632
+ video_writer.write(frame)
3633
+ else:
3634
+ #do something with picture file
3635
+ if backup:
3636
+ if backup == 2:
3637
+ comp_a=f'{output_file}.0'
3638
+ comp_b=f'{output_file}.1'
3639
+ if os.path.isfile(comp_a) and os.path.isfile(comp_b):
3640
+ if filecmp.cmp(comp_a,comp_b):
3641
+ if log:
3642
+ if IsIn(log,['screen','log','print',print]):
3643
+ printf(Dot(),direct=True)
3644
+ else:
3645
+ printf(Dot(),log=log,direct=True)
3646
+ time.sleep(wait_time)
3647
+ backup_idx+=1
3648
+ continue
3649
+ shutil.copy2(save_file,output_file)
3650
+ if IsIn(capture_method,['log','screen','text']):
3651
+ found_words=ocr.Text(image_file=save_file)
3652
+ found_strings=found_space.join(found_words)
3653
+ if IsIn(log,['screen','log','print',print,None]):
3654
+ printf(found_strings,mode='s')
3655
+ else:
3656
+ printf(found_strings,log=log,mode='d')
3657
+ if find_string:
3658
+ if find_string in found_strings:
3659
+ #Find exit string, So True, So True, So True, So True
3660
+ driver.quit()
3661
+ return True
3662
+ backup_idx+=1
3663
+ #capture interval
3628
3664
  time.sleep(wait_time)
3629
- backup_idx+=1
3630
3665
  else:
3666
+ #Single capture
3631
3667
  #wait
3632
- wait_body(driver,timeout=wait_time)
3668
+ #wait_body(driver,timeout=wait_time)
3669
+ time.sleep(wait_time)
3633
3670
  #capture
3634
3671
  driver.save_screenshot(output_file)
3635
- driver.quit()
3672
+ if IsIn(capture_method,['log','screen','text']):
3673
+ found_words=ocr.Text(image_file=output_file)
3674
+ found_strings=found_space.join(found_words)
3675
+ if IsIn(log,['screen','log','print',print,None]):
3676
+ printf(found_strings,mode='s')
3677
+ else:
3678
+ printf(found_strings,log=log,mode='d')
3679
+ if find_string:
3680
+ if find_string in found_strings:
3681
+ driver.quit()
3682
+ return True
3683
+ driver.quit()
3684
+ if IsIn(capture_method,['text']):
3685
+ return found_strings
3686
+ return True
3687
+
3688
+ ##
3689
+ if IsIn(capture_type,['mov','mp4']):
3690
+ if not video_file:
3691
+ video_file='{}.mp4'.format('.'.join(output_file.split('.')[:-1]))
3692
+
3693
+ #Background running
3636
3694
  if daemon:
3637
- t=kThread(target=_capture_, args=(live_capture,driver,output_file,wait_time,capture_method,backup,ocr,log,find_string,daemon))
3695
+ t=kThread(target=_capture_, args=(live_capture,driver,output_file,wait_time,capture_method,backup,ocr,log,find_string,daemon,video_file))
3638
3696
  return t
3639
3697
  else:
3640
- _capture_(live_capture,driver,output_file,wait_time,capture_method,backup,ocr,log,find_string,daemon)
3641
- return True,output_file
3698
+ #Single process running
3699
+ rc=_capture_(live_capture,driver,output_file,wait_time,capture_method,backup,ocr,log,find_string,daemon,video_file)
3700
+ if IsIn(capture_type,['mov','mp4']):
3701
+ return rc,video_file
3702
+ else:
3703
+ return rc,output_file
3642
3704
 
3643
3705
  except Exception as e:
3644
3706
  #print(f"Error capturing screenshot: {str(e)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.122
3
+ Version: 2.1.123
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