Upload files to "/"
This commit is contained in:
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@@ -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"]
|
||||
77
bot.py
Normal file
77
bot.py
Normal file
@@ -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"🚨 <b>YENİ ARAÇ GELDİ!</b>\n"
|
||||
f"<b>💰 Fiyat:</b> {price:,} TL\n"
|
||||
f"<b>🎨 Dış Renk:</b> {ext_color.upper()}\n"
|
||||
f"<b>🪑 İç Renk:</b> {int_color.upper()}\n"
|
||||
f"<b>🔑 VIN:</b> {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()
|
||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -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"
|
||||
94
install.sh
Normal file
94
install.sh
Normal file
@@ -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
|
||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
requests
|
||||
Reference in New Issue
Block a user