Skip to main content

some helper functions from nic's gist

Project description

Helpers

various helpers from nic gist

full docs here https://thanakijwanavit.github.io/nicHelper/

from nicHelper.wrappers import add_method

Install

pip install nicHelper

How to use

method module

add method to a class

class A:
  pass

@add_method(A)
def printHello(self):
  print('hello')

A().printHello()
hello

This is equivalent to

class A:
  def printHello(self):
    print('hello')

Dict utilities

Pretty print a dict

print only the first 10 characters of dict key, works with deep nested dict

from nicHelper.dictUtil import printDict
printDict({'key':'sjfhdkljhafsdlkjhdfaslkjhkljfadshklhfa', 'nestedKey':{'nestedKey2':'938023840843', 'nested3':{'nested4':'hello'}}})
key : sjfhdkljha
nestedKey
 nestedKey2 : 9380238408
 nested3
  nested4 : hello

change all nested datetime object into timestamp for json compatibility

from nicHelper.dictUtil import filterDt
from datetime import datetime
filterDt({'time': {'time2':datetime.now()}, 'hello': 'world'})
{'time': {'time2': 1606887911.36901}, 'hello': 'world'}

Exception module

from nicHelper.exception import errorString
try:
  error
except:
  print(f'error is \n{errorString()}')

Image utils

from nicHelper.images import imageFromUrl, imageToS3, showImgS3, resizeImage
from s3bz.s3bz import S3
## test variables
key = 'testCat.png'
path = '/tmp/testCat.png'
bucket = 'villa-remove-bg-small-output'
url = 'https://sites.google.com/site/funnycatmeawww/_/rsrc/1422326075261/home/6997052-funny-cat.jpg?height=675&width=1200'

Resize images

resizeImage(url, 400)

load image from url

img = imageFromUrl(url)
type(img)

save Image to S3

imageToS3(img, bucket, key)
S3.exist(key,bucket)

display image from s3

## full test
showImgS3(bucket, key)

Secrets

from nicHelper.secrets import getSecret
secret = getSecret(name="removeBg", region='ap-southeast-1')

Shorten link with tenxor.sh

from nicHelper.shortenLink import shorten
shorten('https://www.youtube.com/watch?v=fp85zRg2cwg')

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nicHelper-0.0.15.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nicHelper-0.0.15-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file nicHelper-0.0.15.tar.gz.

File metadata

  • Download URL: nicHelper-0.0.15.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for nicHelper-0.0.15.tar.gz
Algorithm Hash digest
SHA256 a229ba7b648e8d9b1e28b9c0f6e5c5bed09d8e5848f0ddd5195de25be33f305e
MD5 b14b9f39c7cfbc7978d5ac83ce476acd
BLAKE2b-256 8ca8f860280f66a67e7b4270beb62d3fbacc8da15420530fa07c442dc413e572

See more details on using hashes here.

File details

Details for the file nicHelper-0.0.15-py3-none-any.whl.

File metadata

  • Download URL: nicHelper-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for nicHelper-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 66e9055d2232ab3533142a83d99a17483c645fd4ead42613039ad5c5b413d94a
MD5 beafa532677bb14fc3802a93908f5c00
BLAKE2b-256 14dc331eb08f92a32c5df99066aee729d0782c0b5ec21a12d3df90aec214fa91

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page