Skip to content

Instantly share code, notes, and snippets.

View ohld's full-sized avatar

Daniil Okhlopkov ohld

View GitHub Profile
@ohld
ohld / telegram_watch_stories.py
Created August 16, 2023 13:08
Watch million telegram stories for free with python and telethon
"""
t.me/danokhlopkov
x.com/danokhlopkov
github.com/danokhlopkov
Strategy:
1. get chats / groups you're in
2. iterate over participants and find ones with stories
3. watch them
@ohld
ohld / twitter_usernames_gr_1m_followers.csv
Created June 12, 2023 15:51
Twitter Usernames with more than 1 million subscribers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"username"
"aussiegrit"
"mfbeltrones"
"buffalobills"
"aeexpo"
"puma"
"indiatoday"
"ystk_yrk"
"franco_esca"
"houstontexans"
@ohld
ohld / okhlopkov.sh
Created April 29, 2023 20:11
Dokku Postgres Upgrade 11 to latest w/ PostGIS
dokku postgres:export DB | gzip -9 > DB.sql.gz
docker pull postgis/postgis:latest
export POSTGRES_IMAGE="postgis/postgis"
export POSTGRES_IMAGE_VERSION="latest"
dokku postgres:create DB
gunzip DB.sql.gz | dokku postgres:import DB
@ohld
ohld / amplitude.py
Created August 9, 2021 15:00
How to send Amplitude events with Python
import json
import requests
AMPLITUDE_API_KEY = "your-secret-amplitude-key"
AMPLITUDE_ENDPOINT = "https://api.amplitude.com/2/httpapi"
amp_event = {
"user_id": 123123123, # unique user identifier
"event_type": event_name, # the name of event
"platform": 'Telegram', # useless if you have only Telegram users
@ohld
ohld / .env
Created April 14, 2021 10:51
Airflow env vars list to setup Email notifications with Gmail SMTP
AIRFLOW__SMTP__SMTP_HOST=smtp.gmail.com
AIRFLOW__SMTP__SMTP_SSL=true
AIRFLOW__SMTP__SMTP_PORT=465
AIRFLOW__SMTP__SMTP_USER=
AIRFLOW__SMTP__SMTP_PASSWORD=
AIRFLOW__SMTP__SMTP_MAIL_FROM=
# more env vars: https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#smtp
@ohld
ohld / prettify_url.py
Created February 4, 2021 12:03
Transform any URL to a standard form (useful for joining tables)
# Want to join your data based on URLs (links)?
# You need to convert all urls to one format.
# E.g. remove www., remove https://, remove url params
# This is how I do it:
def prettify(url):
if not url or not isinstance(url, str):
return None # not sure that this is the best approach
url = url.lower().strip()
@ohld
ohld / bash
Created February 3, 2021 13:43
Deploy & Run Metabase in production using Dokku (with Postgres & https)
# Create Dokku app
dokku apps:create metabase
# Pull Metabase instance from Docker
docker pull metabase/metabase
# Create and link production Postgres
dokku postgres:create metabase
dokku postgres:link metabase metabase
@ohld
ohld / update_metabase.sh
Created August 20, 2020 13:34
How to update Metabase if it is deployed via Dokku (Docker) and you migrated from default H2 (in my case to Postgres)
# Make sure you migrated from default H2 db to production-ready (like Postgres)
# because otherwise you'll loose data (dashboards, graphs, users)
docker pull metabase/metabase:latest
docker tag metabase/metabase:latest dokku/lu-metabase:latest
dokku tags:deploy lu-metabase
@ohld
ohld / country_code_to_emoji.py
Last active May 19, 2021 14:52
3-Letter Country codes to emoji dictionary. Convert country codes ISO-3166 Alpha-3 to emoji
COUNTRY_3_EMOJI_DICT = {
"IND": "🇮🇳",
"NGA": "🇳🇬",
"KEN": "🇰🇪",
"ITA": "🇮🇹",
"USA": "🇺🇸",
"CUB": "🇨🇺",
"GBR": "🇬🇧",
"ZAF": "🇿🇦",
"POL": "🇵🇱",
@ohld
ohld / send_file_from_memory.py
Created April 26, 2020 12:59
How to send a CSV file with Telegram bot from memory (buffer, StringIO, BytesIO)
import csv, io
test_data = [[1, 2, 3], ["please", "follow", "me"]]
# csv module can write data in io.StringIO buffer only
s = io.StringIO()
csv.writer(s).writerows(test_data)
s.seek(0)
# python-telegram-bot library can send files only from io.BytesIO buffer