这几天 OVH 的闪购是非常吸引眼球的,主要还是价格便宜,我个人比较喜欢KS-LE-B这个配置。不过之前6号抢购到了两台,付费后一周居然还是因为订单太多,被砍单了。

Dear Customer,

Thanks for placing your Flash Sales orders: 1818xxx 1818xxx

We're sorry, due to the high demand for our limited editions, we'reunable to fulfil all orders. We've weighed all our options and unfortunately have to cancel your order. A full refund will be issued as soon as possible.

We completely understand how frustrating and inconvenient this is, and sincerely apologise for the trouble it has caused. We've made this decision to ensure we can deliver the quality of service you've come to expect from us.

Thank you for your patience and understanding. We're always ready to offer assistance, so feel free to contact our team with any questions or requests. Let us know if you're interested in exploring a similar product, we would be happy to help.

这几天还是不死心,继续刷,希望还是能够抢到一台,不过大概率我想不会补货了,逼近马上就要黑五了,不知黑五会不会有其他的优惠。不过不管怎么样,刷一下总没错。所以下面就是我的监控脚本,如果有货了会发送到邮箱,需要的可以试试。

脚本根据需要自己调整CHECK_INTERVAL监控频率时间,RETRY_INTERVAL超时重试的时间,另外是邮箱的配置信息。

import requests
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import time

# 配置
CHECK_INTERVAL = 180  # 每次检查的间隔时间(秒)
RETRY_INTERVAL = 30   # 请求失败后的重试间隔时间(秒)
OVH_API_URL = "https://www.ovh.com/engine/apiv6/dedicated/server/datacenter/availabilities/?excludeDatacenters=true&planCode=25skleb01&server=25skleb01"
EMAIL_HOST = "smtp.qq.com"  # QQ邮箱SMTP服务器地址
EMAIL_PORT = 465  # SMTP服务器端口
EMAIL_USER = "你的QQ邮箱"  # 替换为你的QQ邮箱
EMAIL_PASS = "你的授权码"  # 替换为QQ邮箱的授权码
TO_EMAIL = "接收提醒的邮箱地址"  # 替换为接收提醒的邮箱

# 要监控的配置和数据中心
CONFIGS = ["softraid-2x2000sa", "softraid-2x450nvme"]
DATACENTERS = ["fra", "gra"]

# 上一次库存记录(避免重复通知)
last_availability = {}

# 检查库存函数
def check_availability():
    try:
        response = requests.get(OVH_API_URL, timeout=10)
        response.raise_for_status()
        data = response.json()
        
        available_items = []
        for item in data:
            if item["storage"] in CONFIGS:  # 只检查我们关注的配置
                for datacenter in item["datacenters"]:
                    if datacenter["datacenter"] in DATACENTERS and datacenter["availability"] == "available":
                        available_items.append({
                            "fqn": item["fqn"],
                            "storage": item["storage"],
                            "datacenter": datacenter["datacenter"]
                        })
        return available_items
    except requests.exceptions.RequestException as e:
        print(f"请求失败: {e}")
        return []

# 发送邮件函数
def send_email(content):
    try:
        # 邮件内容
        message = MIMEText(content, "plain", "utf-8")
        message["From"] = Header("OVH库存监控", "utf-8")
        message["To"] = Header("用户", "utf-8")
        message["Subject"] = Header("OVH库存提醒", "utf-8")
        
        # 连接SMTP服务器并发送邮件
        with smtplib.SMTP_SSL(EMAIL_HOST, EMAIL_PORT) as server:
            server.login(EMAIL_USER, EMAIL_PASS)
            server.sendmail(EMAIL_USER, TO_EMAIL, message.as_string())
        print("邮件发送成功!")
    except Exception as e:
        print(f"邮件发送失败: {e}")

# 主程序
def main():
    global last_availability
    while True:
        print("正在检查库存...")
        available_items = check_availability()
        
        if available_items:
            # 生成库存信息
            content = "以下商品有库存:\n"
            for item in available_items:
                key = f"{item['storage']}_{item['datacenter']}"
                content += f"商品名称: {item['fqn']}\n硬盘类型: {item['storage']}\n服务器地址: {item['datacenter']}\n\n"
                
                # 检查是否已通知过
                if key not in last_availability or not last_availability[key]:
                    last_availability[key] = True  # 标记为已通知
                    print(f"新库存:{item['storage']} 在 {item['datacenter']} 有货!")
            
            # 发送库存邮件
            send_email(content)
        else:
            print("当前无货。")
            # 清除上次记录(无货时重新监控)
            last_availability = {key: False for key in last_availability}
        
        print("等待下一次检查...")
        time.sleep(CHECK_INTERVAL)

if __name__ == "__main__":
    while True:
        try:
            main()
        except Exception as e:
            print(f"主程序出错: {e}")
            print(f"{RETRY_INTERVAL} 秒后重试...")
            time.sleep(RETRY_INTERVAL)

最后修改:2024 年 11 月 17 日
如果觉得我的文章对你有用,请随意赞赏