commit cf8521b315b8ca7330611b11e9cca169b53062dc Author: BitMaster Admin Date: Thu Jun 19 11:03:07 2025 +0000 Upload files to "/" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f205f89 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.12-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY bot.py . + +CMD ["python", "bot.py"] diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..4e6cb93 --- /dev/null +++ b/bot.py @@ -0,0 +1,77 @@ + +import requests +import re +import json +import os + +TELEGRAM_TOKEN = "your_token_here" +CHAT_ID = "your_chat_id_here" +TESLA_URL = "https://www.tesla.com/tr_TR/inventory/new/my?arrangeby=plh&zip=&range=0" +SEEN_VINS_FILE = "seen_vins.txt" + +def notify_telegram_with_button(message, button_text, button_url): + payload = { + "chat_id": CHAT_ID, + "text": message, + "parse_mode": "HTML", + "reply_markup": json.dumps({ + "inline_keyboard": [[{ + "text": button_text, + "url": button_url + }]] + }) + } + requests.post(f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage", data=payload) + +def load_seen_vins(): + if not os.path.exists(SEEN_VINS_FILE): + return set() + with open(SEEN_VINS_FILE, "r") as f: + return set(line.strip() for line in f.readlines()) + +def save_seen_vins(vins): + with open(SEEN_VINS_FILE, "w") as f: + f.writelines(f"{vin}\n" for vin in vins) + +def check_inventory(): + try: + response = requests.get(TESLA_URL) + if response.status_code != 200: + raise Exception("Tesla site response not 200") + + page_text = response.text + json_data_match = re.search(r'\"results\"\s*:\s*(\[\{.*?\}\])', page_text, re.DOTALL) + if not json_data_match: + raise Exception("Could not find inventory JSON") + + cars = json.loads(json_data_match.group(1)) + seen_vins = load_seen_vins() + new_seen = seen_vins.copy() + + for car in cars: + vin = car.get("vin") + if not vin or vin in seen_vins: + continue + + price = car.get("price", "N/A") + ext_color = car.get("paint", {}).get("value", "N/A") + int_color = car.get("interior", {}).get("value", "N/A") + order_link = f"https://www.tesla.com/tr_TR/my/order/{vin}" + + message = ( + f"🚨 YENΔ° ARAΓ‡ GELDΔ°!\n" + f"πŸ’° Fiyat: {price:,} TL\n" + f"🎨 Dış Renk: {ext_color.upper()}\n" + f"πŸͺ‘ Δ°Γ§ Renk: {int_color.upper()}\n" + f"πŸ”‘ VIN: {vin}" + ) + + notify_telegram_with_button(message, "πŸš— HEMEN SΔ°PARİŞ VER", order_link) + new_seen.add(vin) + + save_seen_vins(new_seen) + + except Exception as e: + print("Error:", e) + +check_inventory() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d1aded4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.9" + +services: + tesla-inventory-bot: + image: tesla-inventory-bot + container_name: tesla-inventory-bot + build: + context: . + dockerfile: Dockerfile + volumes: + - ./data:/app + restart: "no" diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..927ca7e --- /dev/null +++ b/install.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +REPO_URL="https://git.bitmaster.cc/BitMaster/tesla-bot.git" +CLONE_DIR="tesla-bot" +CRON_NAME="tesla-inventory-bot" + +GREEN="\e[32m" +RED="\e[31m" +YELLOW="\e[33m" +BLUE="\e[34m" +NC="\e[0m" + +function banner() { + echo -e "${BLUE}" + echo "==============================" + echo "πŸš— Tesla Inventory Bot Setup" + echo "==============================" + echo -e "${NC}" +} + +function menu() { + echo -e "${YELLOW}1. Install bot (clone + build)" + echo "2. Enable .log file logging" + echo "3. Setup new cronjob (every X min)" + echo "4. Show current cronjobs" + echo "5. Remove existing cronjob" + echo "6. Exit${NC}" + echo "" +} + +function set_telegram_credentials() { + cd "$CLONE_DIR" || exit 1 + echo -e "${YELLOW}πŸ“¨ Enter your Telegram bot token:${NC}" + read -rp "πŸ”‘ TELEGRAM_TOKEN: " token + echo -e "${YELLOW}πŸ‘₯ Enter your Telegram chat ID:${NC}" + read -rp "πŸ†” TELEGRAM_CHAT_ID: " chat_id + sed -i "s|^TELEGRAM_TOKEN = .*|TELEGRAM_TOKEN = \"$token\"|" bot.py + sed -i "s|^CHAT_ID = .*|CHAT_ID = \"$chat_id\"|" bot.py + echo -e "${GREEN}βœ… Credentials updated in bot.py${NC}" +} + +function clone_and_build() { + echo -e "${GREEN}πŸ“₯ Cloning repo...${NC}" + git clone "$REPO_URL" "$CLONE_DIR" + cd "$CLONE_DIR" || exit 1 + echo -e "${GREEN}πŸ”§ Building Docker image...${NC}" + docker compose build + set_telegram_credentials +} + +function enable_logging() { + cd "$CLONE_DIR" || exit 1 + sed -i '1s|^|exec > >(tee -a /app/bot.log) 2>&1\n|' bot.py + echo -e "${GREEN}πŸ“ Logging enabled.${NC}" +} + +function setup_cronjob() { + cd "$CLONE_DIR" || exit 1 + echo -e "${YELLOW}πŸ“† Every how many minutes should the bot run? (1-60)${NC}" + read -rp "πŸ•“ Interval: " interval + [[ "$interval" =~ ^[0-9]+$ ]] || return + cron_expr="*/$interval * * * *" + CMD="cd $(pwd) && docker compose run --rm $CRON_NAME >> ./data/cron.log 2>&1" + JOB="$cron_expr $CMD" + crontab -l 2>/dev/null | grep -v "$CRON_NAME" | crontab - + (crontab -l 2>/dev/null; echo "$JOB") | crontab - + echo -e "${GREEN}βœ… Cronjob installed.${NC}" +} + +function show_cronjobs() { + crontab -l | grep "$CRON_NAME" || echo -e "${RED}❌ No cronjobs found.${NC}" +} + +function remove_cronjob() { + crontab -l 2>/dev/null | grep -v "$CRON_NAME" | crontab - + echo -e "${GREEN}πŸ—‘οΈ Cronjob removed.${NC}" +} + +while true; do + clear + banner + menu + read -rp "$(echo -e "${YELLOW}πŸ‘‰ Choose [1-6]: ${NC}")" choice + case $choice in + 1) clone_and_build ;; + 2) enable_logging ;; + 3) setup_cronjob ;; + 4) show_cronjobs ;; + 5) remove_cronjob ;; + 6) echo -e "${RED}Exiting...${NC}"; exit 0 ;; + *) echo -e "${RED}❌ Invalid.${NC}" ;; + esac + read -rp "$(echo -e "${BLUE}πŸ” Press Enter to continue...${NC}")" +done diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests