Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,10 @@ import smtplib
|
|
3 |
from email.mime.text import MIMEText
|
4 |
from email.mime.multipart import MIMEMultipart
|
5 |
import time
|
|
|
|
|
|
|
|
|
6 |
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"
|
7 |
|
8 |
def send_email(subject, body):
|
@@ -21,14 +25,31 @@ def send_email(subject, body):
|
|
21 |
|
22 |
# Gửi email qua SMTP server
|
23 |
try:
|
24 |
-
with smtplib.SMTP_SSL('smtp.gmail.com',
|
25 |
-
server.starttls()
|
26 |
server.login(sender_email, password)
|
27 |
server.sendmail(sender_email, receiver_email, msg.as_string())
|
28 |
print("Email sent successfully.")
|
29 |
except Exception as e:
|
30 |
print(f"Failed to send email: {e}")
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
def check_url_for_value(url, target_value):
|
33 |
try:
|
34 |
response = requests.get(url)
|
@@ -41,7 +62,7 @@ def check_url_for_value(url, target_value):
|
|
41 |
for i in range(len(target_value)):
|
42 |
for j in range(len(machine)):
|
43 |
if machine[j] == target_value[i]:
|
44 |
-
|
45 |
break
|
46 |
except Exception as e:
|
47 |
print(f"Failed to fetch data from URL: {e}")
|
@@ -53,7 +74,9 @@ def run_monitoring():
|
|
53 |
|
54 |
while True:
|
55 |
check_url_for_value(url, target_value)
|
56 |
-
time.sleep(
|
57 |
# Press the green button in the gutter to run the script.
|
58 |
if __name__ == '__main__':
|
59 |
run_monitoring()
|
|
|
|
|
|
3 |
from email.mime.text import MIMEText
|
4 |
from email.mime.multipart import MIMEMultipart
|
5 |
import time
|
6 |
+
from google.oauth2 import service_account
|
7 |
+
from googleapiclient.discovery import build
|
8 |
+
import base64
|
9 |
+
from Google import Create_Service
|
10 |
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"
|
11 |
|
12 |
def send_email(subject, body):
|
|
|
25 |
|
26 |
# Gửi email qua SMTP server
|
27 |
try:
|
28 |
+
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
|
|
|
29 |
server.login(sender_email, password)
|
30 |
server.sendmail(sender_email, receiver_email, msg.as_string())
|
31 |
print("Email sent successfully.")
|
32 |
except Exception as e:
|
33 |
print(f"Failed to send email: {e}")
|
34 |
|
35 |
+
|
36 |
+
def send_email_via_gmail_api(subject, body, receiver_email):
|
37 |
+
CLIENT_SECRET_FILE = 'client_secret.json'
|
38 |
+
API_NAME = 'gmail'
|
39 |
+
API_VERSION = 'v1'
|
40 |
+
SCOPES = ['https://mail.google.com/']
|
41 |
+
|
42 |
+
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
|
43 |
+
|
44 |
+
emailMsg = body
|
45 |
+
mimeMessage = MIMEMultipart()
|
46 |
+
mimeMessage['to'] = receiver_email
|
47 |
+
mimeMessage['subject'] = subject
|
48 |
+
mimeMessage.attach(MIMEText(emailMsg, 'plain'))
|
49 |
+
raw_string = base64.urlsafe_b64encode(mimeMessage.as_bytes()).decode()
|
50 |
+
|
51 |
+
message = service.users().messages().send(userId='me', body={'raw': raw_string}).execute()
|
52 |
+
print(message)
|
53 |
def check_url_for_value(url, target_value):
|
54 |
try:
|
55 |
response = requests.get(url)
|
|
|
62 |
for i in range(len(target_value)):
|
63 |
for j in range(len(machine)):
|
64 |
if machine[j] == target_value[i]:
|
65 |
+
send_email_via_gmail_api("Có Máy VAST AI", f"Nhanh lẹ lên vô chiếm máy {target_value[i]}!!!","[email protected]")
|
66 |
break
|
67 |
except Exception as e:
|
68 |
print(f"Failed to fetch data from URL: {e}")
|
|
|
74 |
|
75 |
while True:
|
76 |
check_url_for_value(url, target_value)
|
77 |
+
time.sleep(120) # Chờ 1 phút
|
78 |
# Press the green button in the gutter to run the script.
|
79 |
if __name__ == '__main__':
|
80 |
run_monitoring()
|
81 |
+
|
82 |
+
|