Skip to content

Instantly share code, notes, and snippets.

View aahnik's full-sized avatar
🏠
something's happening!

Aahnik Daw aahnik

🏠
something's happening!
View GitHub Profile
@aahnik
aahnik / searchy.py
Created December 13, 2020 06:06
Search a substring in a list of strings;Python | Finding strings with given substring in list;search a query in a list of strings;re;list comprehension;filter;lambda;re.search
# search a query in a list of strings
import re
my_list = ['Horrible donkey', 'irritable monkey', 'international idiot']
search_for = 'd'
# list comprehension
@aahnik
aahnik / limited_length_dict.py
Created January 2, 2021 22:36
When you just want to keep the last n added values to a dictionary. Python
var = {}
count = 1
limit = 10
while True:
data = input('enter data ')
var.update({count:data})
@aahnik
aahnik / get_chat_info.py
Last active January 8, 2021 15:47
Telegram Chat info. Telethon. Python.
import asyncio
from settings import API_ID, API_HASH
from telethon import TelegramClient
from utils import _
async def get_chat_id(ref=None):
async with TelegramClient('tg_session', API_ID, API_HASH) as client:
if not ref:
ref = input('Enter link/phone/username/id to get chat info: ')
@aahnik
aahnik / #channel joiner.md
Last active October 22, 2022 19:54
Telethon , telegram , join telegram channels from a list

Here is an example of .env file you need to use:

Screenshot from 2021-01-15 17-21-41

Make sure to have telethon and python-dotenv installed.

@aahnik
aahnik / #get_session_string.md
Last active November 9, 2024 19:29
A python script to get Telegram session string after logging into user account. Using Telethon.

You must ensure that you have Telethon installed. Run pip install telethon to install.

[optional]

You can can create file called .env in the directory from which you are running the script.

.env

@aahnik
aahnik / #run_multi.md
Last active August 5, 2022 14:51
Run multiple bot telegram bot clients using gnu-screen (terminal-multiplexer). Supply bot tokens via bots.yml to this script. [telethon,telegram,bots.gnu-screen,screen,multiples]

First of all you make a bot whose multiple instances are to be run from the same server.

Suppose the bot is run by invoking main.py with the bot_name and token as command line arguments.

Syntax:

[PYTHON] [ENTRY_POINT] [bot_name] [token]

Example:

python main.py mysamplebot "173453434:42jhs894_13234jsjgasjs"

@aahnik
aahnik / locorg.py
Last active April 3, 2022 16:26
organize files of loconotion output https://github.com/leoncvlt/loconotion/issues/36
# MIT License
# Aahnik 2021
# a script to organize the files in loconotion output
# also updates html and css files
# unix (linux / mac) style file paths are used in the program,
# will fail inevitably if run on windows
# ditch windows
import logging
import os
@aahnik
aahnik / #poetry-docker.md
Last active May 26, 2021 04:11
Python package manager poetry, in a docker image. Base your docker image on this, to get poetry out of the box. https://hub.docker.com/r/aahnik/poetry-docker

How to use?

[warning] aahnik/poetry-docker is no longer maintained. Build and publish your own image

interactively

$ docker run -it aahnik/poetry-docker
# will open bash shell inside the container
# run poetry --version to check
@aahnik
aahnik / partize.py
Created May 1, 2021 15:56
Create part subfolders from a folder containing large no of files
# AAHNIK 2021
# ditch windows, may fail there
# for my personal use, i dont care to write a more detailed docs
import os
path = os.getcwd()
path = "/home/aahnik/Downloads/Telegram Desktop/dharmic_cause_ChatExport_2021-04-30/files"
@aahnik
aahnik / bot.py
Last active April 29, 2025 09:23
A simple button creator bot using python-telegram-bot #telegram #python
# pip install python-dotenv python-telegram-bot
# create a .env file with
# BOT_TOKEN=...
# in the same dir as of this script
import logging
from dotenv import load_dotenv
from telegram.ext.filters import Filters
from telegram import ParseMode
import os