【发布时间】:2022-08-14 01:50:13
【问题描述】:
我目前编写了一个脚本,在其中我正在对自己的 Web API 进行某种监视。我的脚本的重点是我想做一种监视器,我每小时检查一次,看看是否有新数据已应用到我的 API 中,每当有新数据时,我希望它打印出来.
class Monitor:
def __init__(self, url: str) -> None:
self.url = url
self.stored_id: set = set()
def doRequest(self) -> None:
while True:
try:
response = requests.get(
self.url,
timeout=12,
)
if response.status_code == 200:
parser = response.json()
if parser.get(\'configurations\', {}):
for configuration in parser[\'configurations\']:
if configuration[\'configuration\'][\'id\'] not in self.stored_id
upload_to_discord({
\'art-number\': configuration[\'art\'],
...
})
self.stored_id.add(configuration[\'configuration\'][\'id\'])
time.sleep(3600)
except Exception as e:
print(e)
但是我的问题是,每当我运行此脚本时,它总是会打印到我的不和谐 (upload_to_discord(dict)) 中,这意味着每当我重新启动脚本时,它总是会打印出来。我想知道如何跳过第一次迭代,而不是在第一次循环中打印出来,而是存储找到的数据,然后在第一次迭代之后,它将开始“监控”以查看是否添加了任何内容和每当有新数据时打印出来?
标签: python python-3.x