import requests import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import time from google.oauth2 import service_account from googleapiclient.discovery import build import base64 from Google import Create_Service url ="https://cloud.vast.ai/api/v0/bundles/?q=%7B%22disk_space%22%3A%7B%22gte%22%3A16.336194011315104%7D%2C%22show_incompatible%22%3A%7B%22eq%22%3Atrue%7D%2C%22reliability2%22%3A%7B%22gte%22%3A0.8846748789619375%7D%2C%22duration%22%3A%7B%22gte%22%3A8862.880832140607%7D%2C%22verified%22%3A%7B%22eq%22%3Atrue%7D%2C%22rentable%22%3A%7B%22eq%22%3Atrue%7D%2C%22dph_total%22%3A%7B%22lte%22%3A20.000000000000004%7D%2C%22num_gpus%22%3A%7B%22gte%22%3A1%2C%22lte%22%3A1%7D%2C%22gpu_ram%22%3A%7B%22gte%22%3A70239.74564077858%2C%22lte%22%3A205674.01375904563%7D%2C%22sort_option%22%3A%7B%220%22%3A%5B%22dph_total%22%2C%22asc%22%5D%2C%221%22%3A%5B%22total_flops%22%2C%22asc%22%5D%7D%2C%22gpu_name%22%3A%7B%22in%22%3A%5B%22Pro%20V620%22%2C%22RX%206900%20XT%22%2C%22RX%206800%20XT%22%2C%22RX%206800%22%2C%22RX%207900%20XTX%22%2C%22RX%207900%20GRE%22%2C%22RX%207900%20XT%22%2C%22RX%207900%20XTX%22%2C%22RX%207700%20XT%22%2C%22RX%207600%22%2C%22Pro%20W7900%22%2C%22Pro%20W7800%22%2C%22Radeon%20VII%22%2C%22Radeon%20Pro%20VII%22%2C%22InstinctMI250X%22%2C%22InstinctMI210%22%2C%22InstinctMI100%22%2C%22GH200%20SXM%22%2C%22H100%20PCIE%22%2C%22H100%20SXM%22%2C%22H100%20NVL%22%2C%22A100%20PCIE%22%2C%22A800%20PCIE%22%2C%22A100%20SXM4%22%2C%22A100X%22%2C%22A100%20SXM%22%2C%22RTX%204090%22%2C%22RTX%204090D%22%2C%22RTX%204080S%22%2C%22RTX%204080%22%2C%22RTX%204070S%20Ti%22%2C%22RTX%204070S%22%2C%22RTX%204070%20Ti%22%2C%22RTX%204070%22%2C%22RTX%204060%20Ti%22%2C%22RTX%204060%22%2C%22RTX%203090%20Ti%22%2C%22RTX%203090%22%2C%22RTX%203080%20Ti%22%2C%22RTX%203080%22%2C%22RTX%203070%20Ti%22%2C%22RTX%203070%22%2C%22RTX%203070%20laptop%22%2C%22RTX%203060%20Ti%22%2C%22RTX%203060%22%2C%22RTX%203060%20laptop%22%2C%22RTX%203050%22%2C%22RTX%202080%20Ti%22%2C%22RTX%202080S%22%2C%22RTX%202080%22%2C%22RTX%202070S%22%2C%22RTX%202070%22%2C%22RTX%202060S%22%2C%22RTX%202060%22%2C%22RTX%206000Ada%22%2C%22RTX%205000Ada%22%2C%22RTX%204500Ada%22%2C%22RTX%204000Ada%22%2C%22RTX%20A6000%22%2C%22RTX%20A5000%22%2C%22RTX%20A4500%22%2C%22RTX%20A4000%22%2C%22RTX%20A2000%22%2C%22Titan%20V%22%2C%22Titan%20X%22%2C%22Titan%20Xp%22%2C%22Titan%20RTX%22%2C%22A40%22%2C%22A30%22%2C%22A16%22%2C%22A10g%22%2C%22A10%22%2C%22L40S%22%2C%22L40%22%2C%22L4%22%2C%22Tesla%20K80%22%2C%22Tesla%20P100%22%2C%22Tesla%20P40%22%2C%22Tesla%20P4%22%2C%22Tesla%20V100%22%2C%22GTX%201660%20Ti%22%2C%22GTX%201660%20S%22%2C%22GTX%201660%22%2C%22GTX%201650%20S%22%2C%22GTX%201650%22%2C%22GTX%201080%20Ti%22%2C%22GTX%201080%22%2C%22GTX%201070%20Ti%22%2C%22GTX%201070%22%2C%22GTX%201060%206GB%22%2C%22GTX%201050%20Ti%22%2C%22GTX%201050%22%2C%22GTX%20980%20Ti%22%2C%22GTX%20980%22%2C%22GTX%20970%22%2C%22GTX%20960%22%2C%22GTX%20750%20Ti%22%2C%22GTX%20750%22%2C%22Q%20RTX%208000%22%2C%22Q%20RTX%206000%22%2C%22Q%20RTX%205000%22%2C%22Q%20RTX%204000%22%2C%22P104-100%22%2C%22P106-100%22%2C%22GP100%22%2C%22Quadro%20P6000%22%2C%22Quadro%20P5000%22%2C%22Quadro%20P4000%22%2C%22Quadro%20P2000%22%5D%7D%2C%22order%22%3A%5B%5B%22dph_total%22%2C%22asc%22%5D%2C%5B%22total_flops%22%2C%22asc%22%5D%5D%2C%22allocated_storage%22%3A16.336194011315104%2C%22limit%22%3A64%2C%22extra_ids%22%3A%5B%5D%2C%22type%22%3A%22ask%22%7D" def send_email(subject, body): sender_email = "startup2402@gmail.com" receiver_email = "namkuner@gmail.com" password = "hycw jsiw klia djbs" # Thiết lập nội dung email msg = MIMEMultipart() msg['From'] = sender_email msg['To'] = receiver_email msg['Subject'] = subject # Thêm nội dung vào email msg.attach(MIMEText(body, 'plain')) # Gửi email qua SMTP server try: with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server: server.login(sender_email, password) server.sendmail(sender_email, receiver_email, msg.as_string()) print("Email sent successfully.") except Exception as e: print(f"Failed to send email: {e}") def send_email_via_gmail_api(subject, body, receiver_email): CLIENT_SECRET_FILE = 'client_secret.json' API_NAME = 'gmail' API_VERSION = 'v1' SCOPES = ['https://mail.google.com/'] service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) emailMsg = body mimeMessage = MIMEMultipart() mimeMessage['to'] = receiver_email mimeMessage['subject'] = subject mimeMessage.attach(MIMEText(emailMsg, 'plain')) raw_string = base64.urlsafe_b64encode(mimeMessage.as_bytes()).decode() message = service.users().messages().send(userId='me', body={'raw': raw_string}).execute() print(message) def check_url_for_value(url, target_value): try: response = requests.get(url) response.raise_for_status() data = response.json() # Giả sử dữ liệu nhận được là JSON machine = [ i["machine_id"]for i in data['offers']] print(machine) # Kiểm tra nếu giá trị mong muốn có trong dữ liệu for i in range(len(target_value)): for j in range(len(machine)): if machine[j] == target_value[i]: send_email_via_gmail_api("Có Máy VAST AI", f"Nhanh lẹ lên vô chiếm máy {target_value[i]}!!!","namkuner@gmail.com") break except Exception as e: print(f"Failed to fetch data from URL: {e}") def run_monitoring(): target_value = [27828,11611,28244] while True: check_url_for_value(url, target_value) time.sleep(120) # Chờ 1 phút # Press the green button in the gutter to run the script. if __name__ == '__main__': run_monitoring()