namkuner commited on
Commit
8ec82da
·
verified ·
1 Parent(s): 20c2ec7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ 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):
9
+ sender_email = "[email protected]"
10
+ receiver_email = "[email protected]"
11
+ password = "hycw jsiw klia djbs"
12
+
13
+ # Thiết lập nội dung email
14
+ msg = MIMEMultipart()
15
+ msg['From'] = sender_email
16
+ msg['To'] = receiver_email
17
+ msg['Subject'] = subject
18
+
19
+ # Thêm nội dung vào email
20
+ msg.attach(MIMEText(body, 'plain'))
21
+
22
+ # Gửi email qua SMTP server
23
+ try:
24
+ with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
25
+ server.login(sender_email, password)
26
+ server.sendmail(sender_email, receiver_email, msg.as_string())
27
+ print("Email sent successfully.")
28
+ except Exception as e:
29
+ print(f"Failed to send email: {e}")
30
+
31
+ def check_url_for_value(url, target_value):
32
+ try:
33
+ response = requests.get(url)
34
+ response.raise_for_status()
35
+ data = response.json() # Giả sử dữ liệu nhận được là JSON
36
+
37
+ machine = [ i["machine_id"]for i in data['offers']]
38
+ print(machine)
39
+ # Kiểm tra nếu giá trị mong muốn có trong dữ liệu
40
+ for i in range(len(target_value)):
41
+ for j in range(len(machine)):
42
+ if machine[j] == target_value[i]:
43
+ send_email("Có Máy VAST AI", f"Nhanh lẹ lên vô chiếm máy {target_value[i]}!!!")
44
+ break
45
+ except Exception as e:
46
+ print(f"Failed to fetch data from URL: {e}")
47
+
48
+
49
+ def run_monitoring():
50
+
51
+ target_value = [27828,11611,28244]
52
+
53
+ while True:
54
+ check_url_for_value(url, target_value)
55
+ time.sleep(120) # Chờ 1 phút
56
+ # Press the green button in the gutter to run the script.
57
+ if __name__ == '__main__':
58
+ run_monitoring()