-
Solved: Python Telegram Bot Hangs
I’ve upgraded my Telegram game bot Word Squad to use the latest V21 Python Telegram Bot(PTB) framework, from a distant V13 which I built this bot with 2 years ago. Along the way I upgraded a few components too, such as Python 3.9 –> 3.12, redis 6 –> 7, etc. After I made all the…
-
Coloured Diff With Python
TL; DR: my simple Python code to output a result of text comparison in git-diff style Here’s the code snippet in Python. 🙂
-
An Admin-Only Python Decorator for Telegram Bots
TL; DR: Here’s a Python Decorator I wrote for Telegram Bots so certain commands can only be used by group admins.
-
How to Serve QR Images from Memory with Django
TL; DR: I used SpooledTemporaryFile with FileResponse to server generated QR images directly from memory, no disk IO involved. Please see my code sample with notes: 🙂
-
Caching in Python with Redis + @Decorator
TL;DR: Here’s a simple Python decorator I wrote which can cache function results with Redis. Prerequisites The Python Decorator What’s a decorator in Python? Here’s a very easy-to-understand explanation just for the question. Below is my code of the decorator with notes: Done 🙂
-
A Simple RabbitMQ Consumer with Python
Here’s a very simple RabbitMQ consumer in Python, deployed in a Kubernetes cluster. I used this to act as a consumer for testing purposes. First the Python code: The above code can be saved as a ConfigMap in the cluster: Then the Kubernetes manifest: At last this can be simply deployed with 🙂
-
How to Easily Enable Webhook Mode for Python Telegram Bots
I created a Telegram bot(@wordsquad_bot) using python-telegram-bot framework. There are 2 modes to run the bot: Since my bot has got almost all features and run stably for a while, I decided to setup webhook for it. I came across a few articles and did a bit of troubleshooting myself so here’s probably the easiest…
-
AWS Lambda with Single CloudFormation Template
This is just a quick snippet of CloudFormation template to deploy a Python 3.7 Lambda function embedded in the template. The source code inside ZipFile can contain up to 4KB. # CloudFormation templateAWSTemplateFormatVersion: 2010-09-09Resources: LambdaCode: Type: AWS::Lambda::Function DependsOn: – LambdaRole – LambdaPolicy Properties: Code: ZipFile: | import boto3 def handler(event, context): … Role: !GetAtt LambdaRole.Arn…