python - 如何使用本地机器调度程序每分钟运行一次 python 脚本?
问题描述
我有一个 python 脚本来执行一些 API 调用,并希望它每分钟或每小时运行一次。
我提供了一种解决方案,即 Windows 10 中的任务调度程序。
from urllib.parse import urlencode
import json
import requests
credentials = 'mart.polman@lamudi.co.id', 'lamudionfire'
session = requests.Session()
session.auth = credentials
params = {
'query': 'type:ticket tags:"send_whatsapp" status<closed',
}
url_search = 'https://propertypro.zendesk.com/api/v2/search.json?' + \
urlencode(params)
response = session.get(url_search)
if response.status_code != 200:
print('Status:', response.status_code,
'Problem with the request. Exiting.')
exit()
# Print the subject of each ticket in the results
data = response.json()
id_merged = [result['id'] for result in data['results']]
print(type(id_merged))
print(id_merged)
# Join value of list by using comma separated
id_merged_joined = ','.join(map(str, id_merged))
print(id_merged_joined)
# Set the request parameters
body = 'Hai Pak/Bu'
# Package the data in a dictionary matching the expected JSON
data_comment = {"ticket":
{
"comment": {"body": body},
"remove_tags":["send_whatsapp"]
}
}
# Encode the data to create a JSON payload
payload = json.dumps(data_comment)
print("**Start**")
# Set the request parameters
url_put_comments = 'https://propertypro.zendesk.com/api/v2/tickets/update_many.json?' +\
'ids=' + id_merged_joined
user = 'mart.polman@lamudi.co.id'
pwd = 'lamudionfire'
headers = {'content-type': 'application/json'}
# Do the HTTP put request
response_request = requests.put(url_put_comments, data=payload,
auth=(user, pwd), headers=headers)
# Check for HTTP codes other than 200
if response_request.status_code != 200:
print('Status:', response.status_code,
'Problem with the request. Exiting.')
exit()
# Report success
print('Successfully added comment to ticket #{}'.format(id_merged))
我不希望它在我的本地机器上运行,因为它要求我的机器 24 小时待机,这并不理想。
有人可以帮我吗?
解决方案
推荐阅读
- android - 如何请求关注嵌套滚动视图中当前扩展的容器布局?
- php - 自动检查登录处理程序上的用户角色,而不是检查每个页面上的会话?
- sap - Sybase - SAP ASE - 复制服务器:路由声明
- android - 回收站查看项目未使用 Firebase 加载
- c# - C#如何读取xml文件
- python - 使用正则表达式查找和替换每个匹配项的任意数量的元素
- python - 如何使用 tkinter 使按钮中的文本快速重复更改
- cmake - CMake find_package 包路径
- java - 如何比较 Double.MAX_VALUE
- google-sheets - 防止添加到谷歌表格的重复谷歌表单提交