Back to Learning Tools

Automation & Bots

Termux से WhatsApp बॉट्स, Telegram बॉट्स, और ऑटोमेशन स्क्रिप्ट्स बनाएं

1. Python Automation Setup

Python और Automation Libraries इनस्टॉल करें

Installation:

$ pkg update && pkg upgrade
$ pkg install python
$ pip install pyautogui# GUI automation (needs VNC)
$ pip install selenium# Web automation
$ pip install schedule# Task scheduler
$ pip install requests# HTTP requests

Simple Automation Example:

import schedule import time def job(): print("Automation running...") schedule.every(10).seconds.do(job) while True: schedule.run_pending() time.sleep(1)

2. Telegram Bot

Telegram Bot बनाएं और Control करें

Step 1: Get Bot Token

1. Telegram में @BotFather खोजें
2. /newbot कमांड भेजें
3. Bot का नाम और Username दें
4. Token कॉपी करें

Step 2: Install Library

$ pip install pytelegrambotapi

Step 3: Bot Code

import telebot bot = telebot.TeleBot('YOUR_BOT_TOKEN') @bot.message_handler(commands=['start']) def send_welcome(message): bot.reply_to(message, "Hello! I'm a bot from Termux") @bot.message_handler(commands=['help']) def send_help(message): bot.reply_to(message, "Commands: /start, /help") bot.polling()

3. WhatsApp Bot

WhatsApp Bot बनाएं Node.js से

Setup whatsapp-web.js:

$ pkg install nodejs
$ mkdir wabot && cd wabot
$ npm init -y
$ npm install whatsapp-web.js qrcode-terminal

WhatsApp Bot Code:

const { Client } = require("whatsapp-web.js");

const client = new Client();

client.on("qr", (qr) => {
    console.log("Scan QR with WhatsApp:");
    console.log(qr);
});

client.on("ready", () => {
    console.log("Client is ready!");
});

client.on("message", msg => {
    if (msg.body === "!ping") {
        msg.reply("pong");
    }
});

client.initialize();

4. Web Scraping

Websites से Data Extract करें

Setup Libraries:

$ pip install beautifulsoup4 requests
$ pip install selenium# For JS sites

Simple Scraper:

import requests from bs4 import BeautifulSoup url = 'https://example.com' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') titles = soup.find_all('h1') for title in titles: print(title.text)

5. Task Scheduling

Automated Tasks को Schedule करें

Python Schedule Library:

import schedule import time def morning_task(): print("Good morning!") def night_task(): print("Good night!") # Every day at 8 AM schedule.every().day.at("08:00").do(morning_task) # Every day at 10 PM schedule.every().day.at("22:00").do(night_task) while True: schedule.run_pending() time.sleep(60)

Cron Jobs (Termux-Task):

$ pkg install termux-services
$ sv-enable termux-task
$ termux-task# Edit cron jobs

6. Auto Reply Bots

Messages का Auto Reply बनाएं

Telegram Auto Reply Bot:

import telebot

bot = telebot.TeleBot("YOUR_TOKEN")

@bot.message_handler(func=lambda message: True)
def echo_all(message):
    if message.text.lower() == "hello":
        bot.reply_to(message, "Hi! How can I help?")
    elif message.text.lower() == "time":
        from datetime import datetime
        bot.reply_to(message, f"Time: {datetime.now()}")
    else:
        bot.reply_to(message, "Send 'hello' or 'time'")

bot.polling()

⚠️ Important Notes

  • • सिर्फ Educational Purpose के लिए Use करें
  • • WhatsApp Bot के लिए Device को Online रखना पड़ता है
  • • Bot Token को Secure रखें
  • • Spam या Harassment के लिए न Use करें
  • • Platform की Terms का पालन करें