每天收发短信 (Python)
Send & receive text messages everyday (Python)
这是我的代码:
from zeep import Client
from datetime import datetime
from threading import Timer
def send_simple_sms(txt):
send_url = 'URL'
client = Client(send_url)
username = "MyUsername"
password = "Password"
text = txt
to_type = client.get_type('ns0:ArrayOfString')
to = to_type(['xxxxxxxxxxx'])
from_ = "xxxxxxxx"
result = client.service.SendSimpleSMS(username, password, to, from_, text, False)
print(result)
def timer8():
send_simple_sms('fff')
def timer9():
send_simple_sms('sss')
def timer10():
send_simple_sms('aaa')
def timer14():
send_simple_sms('uuu')
def timer00():
send_simple_sms('ppp')
td = datetime.today()
_8clock = td.replace(day=td.day+1, hour=8, minute=0, second=0, microsecond=0)
_9clock = td.replace(day=td.day+1, hour=9, minute=0, second=0, microsecond=0)
_10clock = td.replace(day=td.day+1, hour=10, minute=0, second=0, microsecond=0)
_14clock = td.replace(day=td.day+1, hour=14, minute=0, second=0, microsecond=0)
_00clock = td.replace(day=td.day+1, hour=0, minute=0, second=0, microsecond=0)
delta_8 = _8clock - td
delta_9 = _9clock - td
delta_10 = _10clock - td
delta_14 = _14clock - td
delta_00 = _00clock - td
secs8 = delta_8.seconds+1
secs9 = delta_9.seconds+1
secs10 = delta_10.seconds+1
secs14 = delta_14.seconds+1
secs00 = delta_00.seconds+1
Timer(secs8, timer8)
Timer(secs9, timer9)
Timer(secs10, timer10)
Timer(secs14, timer14)
Timer(secs00, timer00)
我想每天在这些时间收到一些东西(比如短信):
8:0:0
9:0:0
10:0:0
14:0:0
0:0:0
我一直这样做到这里。
但我有问题一起使用所有时间。
你能帮助我吗?
我该怎么办?
如果您的代码在 linux 环境中 运行ning,最好的方法是使用 crontab,这样您的代码就不会总是 运行ning。您将脚本配置为 运行 一次,然后在您想要的日期和时间使用 crontab 启动它。 Here 你可以找到关于 crontab 的最简单的信息。
这是我的代码:
from zeep import Client
from datetime import datetime
from threading import Timer
def send_simple_sms(txt):
send_url = 'URL'
client = Client(send_url)
username = "MyUsername"
password = "Password"
text = txt
to_type = client.get_type('ns0:ArrayOfString')
to = to_type(['xxxxxxxxxxx'])
from_ = "xxxxxxxx"
result = client.service.SendSimpleSMS(username, password, to, from_, text, False)
print(result)
def timer8():
send_simple_sms('fff')
def timer9():
send_simple_sms('sss')
def timer10():
send_simple_sms('aaa')
def timer14():
send_simple_sms('uuu')
def timer00():
send_simple_sms('ppp')
td = datetime.today()
_8clock = td.replace(day=td.day+1, hour=8, minute=0, second=0, microsecond=0)
_9clock = td.replace(day=td.day+1, hour=9, minute=0, second=0, microsecond=0)
_10clock = td.replace(day=td.day+1, hour=10, minute=0, second=0, microsecond=0)
_14clock = td.replace(day=td.day+1, hour=14, minute=0, second=0, microsecond=0)
_00clock = td.replace(day=td.day+1, hour=0, minute=0, second=0, microsecond=0)
delta_8 = _8clock - td
delta_9 = _9clock - td
delta_10 = _10clock - td
delta_14 = _14clock - td
delta_00 = _00clock - td
secs8 = delta_8.seconds+1
secs9 = delta_9.seconds+1
secs10 = delta_10.seconds+1
secs14 = delta_14.seconds+1
secs00 = delta_00.seconds+1
Timer(secs8, timer8)
Timer(secs9, timer9)
Timer(secs10, timer10)
Timer(secs14, timer14)
Timer(secs00, timer00)
我想每天在这些时间收到一些东西(比如短信): 8:0:0 9:0:0 10:0:0 14:0:0 0:0:0 我一直这样做到这里。 但我有问题一起使用所有时间。 你能帮助我吗? 我该怎么办?
如果您的代码在 linux 环境中 运行ning,最好的方法是使用 crontab,这样您的代码就不会总是 运行ning。您将脚本配置为 运行 一次,然后在您想要的日期和时间使用 crontab 启动它。 Here 你可以找到关于 crontab 的最简单的信息。