11/28/2021

python, simple mkdir and remove folder

import os
#remove folder
os.system('rm -rf ./folder1/folder2/')
#make folder
os.system('mkdir -pv ./folder1/folder2/')

 

Thank you.

www.marearts.com

πŸ™‡πŸ»‍♂️

print pdf from html, python code

#pip install weasyprint
from weasyprint import HTML
#read html
HTML_path = './sample.html'
#convert html2pdf with coordinate
pdf = HTML(HTML_path).write_pdf()
#save pdf
open('sample_weasyprint.pdf', 'wb').write(pdf)

 

Thank you.

www.marearts.com


python polygon list to rectangle

 refer to below code:

--

def returnRect(ploygon):
x_list = []
y_list = []
for v in polygon:
x_list.append(v[0])
y_list.append(v[1])

left = min(x_list)
right = max(x_list)
top = min(y_list)
bottom = max(y_list)
return left, top, right, bottom

polygon = [[776.1818181818181, 221.2121212121212], [895.8787878787879, 219.6969696969697], [892.8484848484848, 198.48484848484847], [879.2121212121211, 146.96969696969697], [795.8787878787879, 150.0], [779.2121212121211, 160.6060606060606]]
x1,y1,x2,y2 = returnRect(polygon)
print(x1,y1,x2,y2)

--


Thank you.

www.marearts.com


11/12/2021

compute_class_weight() takes 1 positional argument but 3 were given

put a explicit parameter name like:

from sklearn.utils import class_weight
class_weights=class_weight.compute_class_weight(class_weight='balanced',classes=np.unique(y),y=y)


Thank you.

www.marearts.com


11/01/2021

.local/lib/python3.8/site-packages/kaggle/api/kaggle_api_extended.py", line 164, in authenticate raise IOError('Could not find {}. Make sure it\'s located in'

If you are using Linux:

1. pip install kaggle
2. cd ~/.kaggle
3. homepage www.kaggle.com -> Your Account -> Create New API token
4. mv ~/Downloads/kaggle.json ./
5. chmod 600 ./kaggle.json

Thank you πŸ™‡πŸ»‍♂️

10/17/2021

install awscli for linux (python)


Try to do these command


>pip install awscli --upgrade --user

>sudo apt install awscli



Thank you.

www.marearts.com

10/13/2021

Get file list in s3 bucket folder (example python code)

 refer to source code

..

import boto3
import botocore

ACCESS_KEY = '**'
SECRET_KEY = '**'

s3_client = boto3.client(
's3',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
region_name = 'eu-west-1'
)

bucket_name = '***'
folder_name = '***'

#check folder exist
try:
result = s3_client.list_objects_v2(Bucket=bucket_name, Prefix=folder_name )
for o in result['Contents']:
print(o['Key']) #file list in folder
except botocore.exceptions.ClientError as e:
print('no folder exist')

..


Thank you 

www.marearts.com