Advertisement
Guest User

Untitled

a guest
May 24th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. def whatDay ():
  2.     # return date.datetime.now()
  3.     day_in_int = date.datetime.today().weekday()
  4.     if (day_in_int == 0):
  5.         return "Monday"
  6.     elif (day_in_int == 1):
  7.         return "Tuesday"
  8.     elif (day_in_int == 2):
  9.         return "Wednesday"
  10.     elif (day_in_int == 3):
  11.         return "Thursday"
  12.     elif (day_in_int == 4):
  13.         return "Friday"
  14.     elif (day_in_int == 5):
  15.         return "Saturday"
  16.     elif (day_in_int == 6):
  17.         return "Sunday"
  18.     else:
  19.         return ""
  20.  
  21. def whatTime():
  22.     return date.datetime.utcnow().hour
  23.  
  24. def isPractice ():
  25.     currDay = whatDay()
  26.  
  27.     if (currDay == "Tuesday") or (currDay == "Wednesday") or (currDay == "Thursday") or (currDay == "Friday"):
  28.         return 1
  29.     else:
  30.         return 0
  31.  
  32. def waitTillPractice():
  33.     bSentMessage = 0
  34.     while(bSentMessage == 0):
  35.         while(not isPractice()):
  36.             print('Waiting for practice')
  37.             time.sleep(30)
  38.        
  39.         #check if it's 20:00 UTC (2pm MST)
  40.         if(whatTime() == 15):
  41.             print("Sent checkin message at ", date.datetime.utcnow())
  42.             #send checkin message:
  43.             send()
  44.             bSentMessage = 1
  45.         else:
  46.             print("wtf?")
  47.        
  48.         #wait 23.9 hours, so that we're not taking up cpu cycles
  49.         print("Waiting till tomorrow <3")
  50.         time.sleep(86040)
  51.         bSentMessage = 0
  52.         print('bSendMessage= ', bSentMessage)
  53.        
  54. def send():
  55.     message = "<@&559797378757034093> Check-in for practice/ games! If you're going to be late, signify the time you'll arrive. E.g. :eight: = I'm arriving at 8pm EST"
  56.  
  57.     # message = "Check-in for practice/ games! If you're going to be late, signify the time you'll arrive. E.g. :eight: = I'm arriving at 8pm EST"
  58.  
  59.     # your webhook URL
  60.     webhookurl = "<webhook url>"
  61.  
  62.     # compile the form data (BOUNDARY can be anything)
  63.     formdata = "------:::BOUNDARY:::\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n" + message + "\r\n------:::BOUNDARY:::--"
  64.  
  65.     # get the connection and make the request
  66.     connection = http.client.HTTPSConnection("discordapp.com")
  67.     connection.request("POST", webhookurl, formdata, {
  68.         'content-type': "multipart/form-data; boundary=----:::BOUNDARY:::",
  69.         'cache-control': "no-cache",
  70.         })
  71.  
  72.     # get the response
  73.     response = connection.getresponse()
  74.     result = response.read()
  75.  
  76.     # return back to the calling function with the result
  77.     return result.decode("utf-8")
  78.  
  79. waitTillPractice()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement