1 回答
TA贡献1909条经验 获得超7个赞
这将运行程序,等待十分钟,检查上一个结果是否与当前结果相同,如果是,则退出。所以你现在要做的就是弄清楚如何在第二天之前戒掉它:)
//编辑:我编辑了与您的评论相对应的代码
from datetime import datetime
import pandas as pd
import requests
from tabulate import tabulate
import time
def main():
result = []
for unit_id in range(5095, 5099):
resp = requests.get(
f"https://calirdr.usedirect.com/rdr/rdr/fd/"
f"availability/getbyunit/{unit_id}/startdate/2020-10-30/nights/30/true?").json()
result.extend(resp)
filter_by = ['UnitId', 'StartTime', 'IsFree', 'IsWalkin']
df = pd.DataFrame(result)
df = df.filter(items=filter_by)
df['StartTime'] = df['StartTime'].apply(lambda d: datetime.fromisoformat(d).strftime("%Y-%m-%d"))
df = df[df['IsFree']]
df = df[~df['IsWalkin']]
df['UnitId'] = df['UnitId'].replace([5095], 'Site 81')
df['UnitId'] = df['UnitId'].replace([5096], 'Site 82')
return tabulate(df, headers=filter_by)
res_before = ""
while True:
res = main()
if res != res_before:
print(res)
res_before = res
else:
print("nothing changed")
time.sleep(600)
添加回答
举报