kmisc 2.1.118__py3-none-any.whl → 2.1.120__py3-none-any.whl
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.
- kmisc/__init__.py +82 -24
- {kmisc-2.1.118.dist-info → kmisc-2.1.120.dist-info}/METADATA +1 -1
- kmisc-2.1.120.dist-info/RECORD +6 -0
- kmisc-2.1.118.dist-info/RECORD +0 -6
- {kmisc-2.1.118.dist-info → kmisc-2.1.120.dist-info}/LICENSE +0 -0
- {kmisc-2.1.118.dist-info → kmisc-2.1.120.dist-info}/WHEEL +0 -0
- {kmisc-2.1.118.dist-info → kmisc-2.1.120.dist-info}/top_level.txt +0 -0
kmisc/__init__.py
CHANGED
@@ -1973,30 +1973,35 @@ def XML2Dict(root,path=[],sub=0,ignore_value=['\n']):
|
|
1973
1973
|
root=tree.getroot()
|
1974
1974
|
except:
|
1975
1975
|
return False
|
1976
|
+
def ignore(a,b):
|
1977
|
+
if isinstance(b,tuple) and a not in b:
|
1978
|
+
return True
|
1979
|
+
elif isinstance(b,set) and a in b:
|
1980
|
+
return True
|
1981
|
+
elif not isinstance(b,(tuple,set)) and b != '*' and a != b:
|
1982
|
+
return True
|
1983
|
+
return False
|
1976
1984
|
|
1977
1985
|
attr_root=root.attrib
|
1978
1986
|
root_tag=attr_root.get('name',root.tag)
|
1979
|
-
|
1987
|
+
#Current Path (root)
|
1988
|
+
if path and len(path) > sub:
|
1989
|
+
if ignore(root_tag,path[sub]): return {}
|
1990
|
+
out={root_tag:{}}
|
1991
|
+
for i in attr_root:
|
1992
|
+
if path and len(path) > sub+1:
|
1993
|
+
if ignore(i,path[sub+1]): continue
|
1994
|
+
out[root_tag][i]=attr_root[i]
|
1980
1995
|
d_root=out[root_tag]
|
1981
|
-
new_sub=sub+1
|
1982
1996
|
for x in root:
|
1983
1997
|
if isinstance(x,str): continue
|
1984
|
-
|
1985
|
-
if len(path) <= sub: continue
|
1986
|
-
if isinstance(path[sub],tuple): #tuple then choose only same key
|
1987
|
-
if root_tag not in path[sub]:
|
1988
|
-
continue
|
1989
|
-
elif isinstance(path[sub],set): #set then ignore the choosed names, but others are ok
|
1990
|
-
if root_tag in path[sub]:
|
1991
|
-
continue
|
1992
|
-
else:
|
1993
|
-
if path[sub] != '*' and root_tag != path[sub]:
|
1994
|
-
continue
|
1995
|
-
|
1998
|
+
#Sub Path
|
1996
1999
|
# for <Subtitle> ... </Subtitle>
|
1997
2000
|
# for <Text> ... </Text>
|
1998
2001
|
attr_x=x.attrib
|
1999
2002
|
x_tag=attr_x.get('name',attr_x.get('id',x.tag)) #<tag name=xxx id=xxx> ... </tag>
|
2003
|
+
if path and len(path) > sub+1:
|
2004
|
+
if ignore(x_tag,path[sub+1]): continue
|
2000
2005
|
#Special Tag
|
2001
2006
|
if x_tag == 'Subtitle': #Subtitle
|
2002
2007
|
if x_tag not in d_root:
|
@@ -2025,18 +2030,26 @@ def XML2Dict(root,path=[],sub=0,ignore_value=['\n']):
|
|
2025
2030
|
continue
|
2026
2031
|
d_root[x_tag][-1]['data']=x_data
|
2027
2032
|
else: #Normal case
|
2028
|
-
|
2033
|
+
#Sub's sub
|
2034
|
+
#d_root[x_tag]=attr_x # {...}
|
2035
|
+
d_root[x_tag]={}
|
2036
|
+
for i in attr_x:
|
2037
|
+
if path and len(path) > sub+1:
|
2038
|
+
if ignore(i,path[sub+1]): continue
|
2039
|
+
d_root[x_tag][i]=attr_x[i]
|
2040
|
+
|
2029
2041
|
x_data=x.text # <>text</> put at "data" key's value
|
2030
2042
|
sub_data=XML2Dict(x,path=path,sub=sub+1,ignore_value=ignore_value)
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2043
|
+
if len(sub_data) == 1:
|
2044
|
+
sub_key=next(iter(sub_data))
|
2045
|
+
if sub_data[sub_key]:
|
2046
|
+
for i in sub_data[sub_key]:
|
2047
|
+
d_root[x_tag][i]=sub_data[sub_key][i]
|
2048
|
+
if isinstance(x_data,str):
|
2049
|
+
_x_=x_data.strip()
|
2050
|
+
if _x_ == '\n' or not _x_ or _x_ in ignore_value:
|
2051
|
+
continue
|
2052
|
+
d_root[x_tag]['data']=x_data
|
2040
2053
|
return out
|
2041
2054
|
|
2042
2055
|
def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None,find_all=False):
|
@@ -3434,6 +3447,51 @@ def Upper(src,default='org'):
|
|
3434
3447
|
if isinstance(src,str): return src.upper()
|
3435
3448
|
if default in ['org',{'org'}]: return src
|
3436
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
|
+
|
3437
3495
|
############################################
|
3438
3496
|
#Temporary function map for replacement
|
3439
3497
|
############################################
|
@@ -0,0 +1,6 @@
|
|
1
|
+
kmisc/__init__.py,sha256=Qohn7dgINzBWEjZdl2wfKfd8BA1hlRU3aJqTrZODRok,146663
|
2
|
+
kmisc-2.1.120.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
|
3
|
+
kmisc-2.1.120.dist-info/METADATA,sha256=hdsc0wTLXtmnsiy-gE1iHYnABkJwT1fy3oGbH44tbm8,5523
|
4
|
+
kmisc-2.1.120.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
5
|
+
kmisc-2.1.120.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
|
6
|
+
kmisc-2.1.120.dist-info/RECORD,,
|
kmisc-2.1.118.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
kmisc/__init__.py,sha256=wybypc4DfANjjg3IalmsLEIsoVfPHjSqFszB838i_GQ,144575
|
2
|
-
kmisc-2.1.118.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
|
3
|
-
kmisc-2.1.118.dist-info/METADATA,sha256=Vw_j4-z3QigzXLGwtKYvzJIs9ltdup9fVKz8xrQIvic,5523
|
4
|
-
kmisc-2.1.118.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
5
|
-
kmisc-2.1.118.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
|
6
|
-
kmisc-2.1.118.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|