Skip to content

Instantly share code, notes, and snippets.

View mthri's full-sized avatar
🦄

Amir Motahari mthri

🦄
View GitHub Profile
@mthri
mthri / divar_notifier.py
Created May 9, 2025 11:45
Divar to Telegram Notifier Bot
"""
Divar to Telegram Notifier Bot
This script monitors a filtered Divar page and sends newly posted items to a specified Telegram channel every 60 seconds.
Setup Instructions:
1. Create a Telegram bot using BotFather.
2. Add the bot to your Telegram group or channel.
3. Promote the bot as an admin in your channel so it can post messages.
4. Use @username_to_id_bot to get the numeric ID of your channel (e.g., -1001234567890).
@mthri
mthri / exception.py
Created November 9, 2024 11:15
Python Decorator for Exception Logging and Telegram Notifications
from functools import wraps
import logging
import time
import requests
logger = logging.getLogger(__name__)
TELEGRAM_NOTIFICATION_BOT = 'YOUR_TELEGRAM_NOTIFICATION_BOT'
TELEGRAM_NOTIFICATION_CHANNEL_ID = 'YOUR_TELEGRAM_NOTIFICATION_CHANNEL_ID'
@mthri
mthri / settings.py
Created September 24, 2024 11:48
print sql query in django
import os
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
'file': {
@mthri
mthri / prompt.MD
Created August 10, 2024 13:51
ChatGPT4o initial prompt

You are ChatGPT, a large language model trained by OpenAI, based on the GPT-4 architecture. Knowledge cutoff: 2023-10 Current date: 2024-07-29

Image input capabilities: Enabled Personality: v2

Tools

bio

@mthri
mthri / main.py
Created June 4, 2024 12:51
URL Extractor: Sniffing HTTP and HTTPS Traffic with Scapy
from scapy.all import sniff, IP, TCP, Raw
def extract_http_url(packet):
"""Extracts and prints HTTP URL from the packet"""
if packet.haslayer(Raw):
try:
http_payload = packet[Raw].load.decode('utf-8')
if "Host:" in http_payload:
headers = http_payload.split("\r\n")
@mthri
mthri / verify.py
Created May 12, 2024 11:39
Extracting and Verifying Telegram Web App Data in Python
import hashlib
import hmac
TELEGRAM_BOT_TOKEN = 'BOT_TOKEN
def extract_telegram_web_app_data(telegram_init_data: str) -> dict:
return dict(qc.split('=') for qc in telegram_init_data.split('&'))
def verify_telegram_web_app_data(telegram_init_data: str) -> bool:
@mthri
mthri / import_export.MD
Last active February 1, 2024 23:20
export and import from PostgreSQL with pg_dump

Export

pg_dump -h HOST -p PORT -U DBUSER -W -d DBNAME > bak.sql

Import

pg_dump -h HOST -p PORT -U DBUSER -W -d NEWDBNAME < bak.sql
or
@mthri
mthri / docker_command.MD
Created November 7, 2023 08:24
common docker command
sudo docker rmi
sudo docker rm
sudo docker ps -a
sudo docker exec -it CONTAINER_HASH /bin/sh
sudo docker logs CONTAINER_HASH
sudo docker run -d CONTAINER_NAME:VERSION
sudo docker build -t IMAGE_NAME:VERSION .
sudo docker compose up -d
sudo docker compose down
@mthri
mthri / bash.sh
Created February 12, 2023 11:05
bash command combination for make life easier
# search some word in all log file in current directory
ls | cut -d " " -f2 | xargs grep "WORD"
# see live last log in current directory
ls -ltrh | rev | cut -d' ' -f 1 | rev | tail -n1 | xargs tail -f
@mthri
mthri / ucs2_tools.py
Last active January 2, 2023 08:54
python3 UCS-2 decoder encoder | good for quectel gsm module
import binascii
def ucs2_decode(hex_string: str) -> str:
return binascii.unhexlify(hex_string).decode('utf-16-be')
def ucs2_encode(text: str) -> str:
encoded = text.encode('utf-16-be')
hexlify = binascii.hexlify(encoded)
return hexlify.decode().upper()