Skip to content

Instantly share code, notes, and snippets.

View PFython's full-sized avatar
💭
Currently working with AI/ML/NLP projects

Peter F PFython

💭
Currently working with AI/ML/NLP projects
View GitHub Profile
@PFython
PFython / gist:77950bc4bb8af1d3d41ee6ef7797b813
Created September 30, 2019 23:02
Simple visual effects for python-elgato-streamdeck
def slideshow(cycles=3, interval=5):
#TODO: Make non blocking so that effect continues to cycle in parallel
for cycle in range(cycles):
for source in IMAGES:
image = create_full_deck_sized_image(deck, source)
for k in range(deck.key_count()):
key_image = crop_key_image_from_deck_sized_image(deck, image, k)
deck.set_key_image(k, key_image)
time.sleep(interval)
@PFython
PFython / gist.py
Last active December 20, 2023 20:12
WhatsApp Cloud API - barebones message sender
import requests
from cleverdict import CleverDict
from config import CONTACTS, ENDPOINT, HEADERS, TEST_MESSAGE, TEST_URL
class Whatsapp:
def __init__(self, contact="", content_type="", autosend=True, **kwargs):
"""
Prepare and optionally execute a request to the Whatsapp Cloud API for sending a message to a pre-approved or opted-in) Whatsapp contact.
@PFython
PFython / config_template.py
Last active May 27, 2022 18:43
Config Template for WhatsApp Cloud API
"""
Rename this file to config.py once completed.
Add config.py to .gitignore etc before including in Github or other repository.
"""
PHONE_ID = "111111111111111" # 15 digit numerical string
CONTACTS = [
"447919xxxxxx", # Up to five contact numbers
"447940xxxxxx", # Numerical strings starting with country code
"44208xxxxxxx", # No leading 0 between country code and area code
@PFython
PFython / instance_logger.py
Last active October 16, 2022 10:01
Create a logger for every instance of a class
"""
Create individual logs for every INSTANCE of a class
"""
from log2d import Log
class MyClass:
def __init__(self, name):
params = {"fmt": Log.presets["name_and_time"]}
self.log = Log.index.get(name) or Log(name, **params)
@PFython
PFython / class_logger.py
Last active October 16, 2022 10:03
Create a logger for every Class
"""
Create ONE log, shared by all instances of a CLASS
"""
from log2d import Log
class MyAbstractClass:
def __init__(self, name, *args, **kwargs):
params = {"fmt": Log.presets["name_and_time"]}
self.log = Log.index.get(name) or Log(name, **params)
@PFython
PFython / module_logger.py
Last active October 25, 2022 18:02
Create a logger for every Module
"""
Create one log file per module using __file__ for the main filename.
"""
from log2d import Log, Path
if __name__ == '__main__':
log = Log(Path(__file__).stem, to_file=True).logger
# TEST