Advertisement
Guest User

Untitled

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