1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| import requests import json import time import datetime
instances = [ ["YOUR_API_KEY",'PRODUCT_ID'], ["YOUR_API_KEY2",'PRODUCT_ID2'] ] url_getinfo = "https://api.v2.rainyun.com/product/rgs/{id}/" url_renew = "https://api.v2.rainyun.com/product/point_renew"
duration_day = 7 def GetRemainingDays(unix_timestamp): # 获取当前时间的UNIX时间戳 current_timestamp = datetime.datetime.now().timestamp() # 将UNIX时间戳转换为datetime对象 target_date = datetime.datetime.fromtimestamp(unix_timestamp) # 将当前时间的UNIX时间戳转换为datetime对象 current_date = datetime.datetime.fromtimestamp(current_timestamp) # 计算两个日期之间的差异 difference = current_date - target_date # 获取差异的天数部分 days_difference = difference.days return -days_difference
print("Rainyun-PointRenew-V1 script, by CodeZhangBorui\n[Time] ", end='') print(time.ctime())
for instance in instances: key = instance[0] pid = instance[1] print("# 处理实例: API-KEY=" + key[:10] + "*"*22 + ",产品ID=" + pid) headers = { 'x-api-key': key, 'User-Agent': 'Rainyun-AutoRenew' } response = requests.request("GET", url_getinfo.replace('{id}',pid), headers=headers, data={}) result = json.loads(response.text) try: timestamp = result['data']['Data']['ExpDate'] except: print("! 当在获取剩余天数时出错\n") continue remainingdays = GetRemainingDays(timestamp) if(remainingdays > 3): print("## 服务器还剩 " + str(remainingdays) + " 天到期,无法用积分续费!\n") continue print("## 服务器还剩 " + str(remainingdays) + " 天到期,尝试续费... ",end='') try: response = requests.request("POST", url_renew, headers=headers, json={"duration_day":duration_day,"product_id":int(pid),"product_type":"rgs"}) result = json.loads(response.text) print(" | 服务器 DATA:" + str(result)) except: print(":( Something went wrong, retry in 10 seconds...") time.sleep(10) try: response = requests.request("POST", url_renew, headers=headers, json={"duration_day":duration_day,"product_id":int(pid),"product_type":"rgs"}) result = json.loads(response.text) print(" | 服务器 DATA:" + str(result)) except: print(":( Something went wrong, retry in 30 seconds...") time.sleep(30) try: response = requests.request("POST", url_renew, headers=headers, json={"duration_day":duration_day,"product_id":int(pid),"product_type":"rgs"}) result = json.loads(response.text) print(" | 服务器 DATA:" + str(result)) except: print(":( Something went wrong, skip this task") continue print("") print("# 程序已结束!") time.sleep(10)
|