Advertisement
K4CZP3R

Untitled

Mar 11th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. from utils.media_sender import UrlPrintSender
  2. from yowsup.layers.protocol_messages.protocolentities.message_text import TextMessageProtocolEntity
  3. import random
  4. from somtoday import *
  5. import string
  6. import os
  7. import sys
  8. import datetime
  9.  
  10. #default login strings
  11. username = "154355"
  12. password = "??????"
  13. school = "hethooghuis"
  14. nr = "19XH"
  15. class SuperKacper():
  16. def __init__(self, interface_layer):
  17. self.interface_layer = interface_layer
  18. self.url_print_sender = UrlPrintSender(self.interface_layer)
  19. self.routes = [
  20. ("^.cijfers", self.cijfers),
  21. ("^.hw", self.hw),
  22. ("^.nexthw", self.hwnext),
  23. ("^.kacper", self.about),
  24. ("^.caitlin", self.cait),
  25. ]
  26. def hwnext(self, message=None, match=None, to=None):
  27. somhw=Somtoday(username,password,school,nr)
  28. todayis = datetime.datetime.today().weekday()
  29. hw = " "
  30. hww = " "
  31. if todayis == 4:
  32. hw = "HW voor Dinsdag\n"
  33. for what in somhw.getschedule(4):
  34. hw = hw + what["titel"] + "\n"
  35. hw = hw + str(what["huiswerk"]) + "\n_________\n"
  36. elif todayis == 5:
  37. hw = "HW voor Dinsdag\n"
  38. for what in somhw.getschedule(3):
  39. hw = hw + what["titel"] + "\n"
  40. hw = hw + str(what["huiswerk"]) + "\n_________\n"
  41.  
  42. for what in somhw.getschedule(2):
  43. hw = hw + what["titel"] + "\n"
  44. hw = hw + str(what["huiswerk"]) + "\n_________\n"
  45. hw_fix = str(hw)
  46. hw_fix1 = hw_fix.replace("<br>", "")
  47. hw_fix2 = hw_fix1.replace("<b>", "")
  48. hw_fix3 = hw_fix2.replace("</b>", "")
  49. hw_fix4 = hw_fix3.replace("</p>", "")
  50. hw_fix5 = hw_fix4.replace("<p>", "")
  51. hw_fix6 = hw_fix5.replace("<i>", "")
  52. hw_fix7 = hw_fix6.replace("</i>", "")
  53. hw_fix8 = hw_fix7.replace("<br/>", "")
  54. hw_fix9 = hw_fix8.replace("&nbsp;", "")
  55.  
  56.  
  57.  
  58. if str(hw_fix9) == " ":
  59. return TextMessageProtocolEntity("Geen Huiswerk", to=message.getFrom())
  60. else:
  61. return TextMessageProtocolEntity(str(hw_fix9), to=message.getFrom())
  62.  
  63. def cijfers(self, message=None, match=None, to=None):
  64. som=Somtoday(username,password,school,nr)
  65. gradesstring = " "
  66. oldf=open("grades.txt")
  67. oldlinesr=oldf.readlines()
  68. old = oldlinesr[0]
  69. oldf.close()
  70.  
  71. targetnew = open("grades.txt", 'w+')
  72. for grades in som.getgrades():
  73. gradesstring = gradesstring + str(grades["vak"]) + "\n"
  74. targetnew.write(gradesstring)
  75. targetnew.close()
  76. newf=open("grades.txt")
  77. newlinesr=newf.readlines()
  78. new = newlinesr[0]
  79. newf.close()
  80. if old == new:
  81. return TextMessageProtocolEntity("Geen nieuwe cijfers", to=message.getFrom())
  82. else:
  83. return TextMessageProtocolEntity("Nieuwe cijfer voor" + new, to=message.getFrom())
  84. def hw(self, message=None, match=None, to=None):
  85. somhw=Somtoday(username,password,school,nr)
  86. todayis = datetime.datetime.today().weekday()
  87. hw = " "
  88. hww = " "
  89. if todayis == 4:
  90. hw = "HW voor Maandag\n"
  91. for what in somhw.getschedule(3):
  92. hw = hw + what["titel"] + "\n"
  93. hw = hw + str(what["huiswerk"]) + "\n_________\n"
  94. elif todayis == 5:
  95. hw = "HW voor Maandag\n"
  96. for what in somhw.getschedule(2):
  97. hw = hw + what["titel"] + "\n"
  98. hw = hw + str(what["huiswerk"]) + "\n_________\n"
  99.  
  100. for what in somhw.getschedule(1):
  101. hw = hw + what["titel"] + "\n"
  102. hw = hw + str(what["huiswerk"]) + "\n_________\n"
  103. hw_fix = str(hw)
  104. hw_fix1 = hw_fix.replace("<br>", "")
  105. hw_fix2 = hw_fix1.replace("<b>", "")
  106. hw_fix3 = hw_fix2.replace("</b>", "")
  107. hw_fix4 = hw_fix3.replace("</p>", "")
  108. hw_fix5 = hw_fix4.replace("<p>", "")
  109. hw_fix6 = hw_fix5.replace("<i>", "")
  110. hw_fix7 = hw_fix6.replace("</i>", "")
  111. hw_fix8 = hw_fix7.replace("<br/>", "")
  112. hw_fix9 = hw_fix8.replace("&nbsp;", "")
  113.  
  114.  
  115.  
  116. if str(hw_fix9) == " ":
  117. return TextMessageProtocolEntity("Geen Huiswerk", to=message.getFrom())
  118. else:
  119. return TextMessageProtocolEntity(str(hw_fix9), to=message.getFrom())
  120.  
  121. def about(self, message=None, match=None, to=None):
  122. return TextMessageProtocolEntity(HELP_TEXT, to=message.getFrom())
  123. def cait(self, message=None, match=None, to=None):
  124. return TextMessageProtocolEntity("Caitlin :D", to=message.getFrom())
  125.  
  126. HELP_TEXT = """ [HELP]
  127. - Bot gemaakt door Kacper S.
  128. Gemaakt met behulp van:
  129. Python 2.7 []
  130. Raspberry Pi B+ []
  131. SomToday API [git]
  132. yowsup [git]
  133. WA-bot-API [git]
  134. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement