我正在尝试创建一个程序,该程序每2小时发出一次警报,并显示一个消息框
答案 0 :(得分:1)
另一种选择是将模块级变量设置为当前时间+两个小时(import nba_api
import requests
import pandas as pd
from nba_api.stats.endpoints import boxscoreadvancedv2
# vector of game ids (test purposes)
gameids = ['0021900001','0021900002','0021900012']
headers1 = {
'Host': 'stats.nba.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://stats.nba.com/',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive',
}
# store player and team results for each gameids as elements of list temp
temp = list()
for i in range(len(gameids)):
temp.append(boxscoreadvancedv2.BoxScoreAdvancedV2(game_id = gameids[i], headers=headers1))
# manually access elements of list and output to data frame
## there has to be an easier way to access list elements and rowbind the results!!!
df_out0 = temp[0].get_data_frames()
df_player0 = df_out0[0]
df_team0 = df_out0[1]
df_out1 = temp[1].get_data_frames()
df_player1 = df_out1[0]
df_team1 = df_out1[1]
),然后进行计时器中断检查以查看当前时间是否大于此存储值。
答案 1 :(得分:0)
您可以使用Timer控件来执行此操作,但是您无法直接将时间间隔设置为7200000。可以将时间间隔设置为60000(并将Enabled属性设置为True
),并具有一个计算过去的分钟数:
Dim iMinutesElapsed As Integer
Private Sub Timer1_Timer()
iMinutesElapsed = iMinutesElapsed + 1
If iMinutesElapsed = 120 Then
DoAlarm
iMinutesElapsed = 0
End If
End Sub
Private Sub DoAlarm()
MsgBox "2 hours have gone by."
End Sub
一种更好的方法是存储一个具有Timer function值的变量,并检查自您调用Start
以来已经有多长时间了。在这种方法中,将Timer1的时间间隔设置为1000,并将Enabled设置为False,Start
方法将为您启用Timer1:
Dim sngStart As Single
Public Sub Start()
sngStart = Timer
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim sngElapsedTime As Single
sngElapsedTime = Timer - sngStart
If sngElapsedTime < 0 Then
' Clock passed midnight
sngElapsedTime = (86400 - sngStart) + Timer
End If
If sngElapsedTime > 7200 Then ' counting seconds with this code
sngStart = Timer ' Restart
DoAlarm
End If
End Sub
最后,如注释中所述,将在每30分钟的奇数小时触发一个解决方案:
Private Sub Timer1_Timer()
If Hour(Now) Mod 2 = 1 And Minute(Now) = 30 Then
DoAlarm
End If
End Sub
答案 2 :(得分:0)
您还可以使用任务计划程序来运行显示您的消息框的VBScript。您只需创建一个带有触发器的任务,即可无限期地每2小时重复一次。
VBScript可以显示时间:
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.views import View
class loginController(View):
def get(self, request):
userobj = User.objects.filter(username = 'username')
return HttpResponse(request.POST.get('username'));