Advertisement
Guest User

Untitled

a guest
Jul 31st, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. from processing import *
  2. import firebase
  3. import time
  4. signedIn = False
  5. sendBtn = {
  6. "x": 5,
  7. "y": 5,
  8. "w": 130,
  9. "h": 30,
  10. "text": "Send A Message"
  11. }
  12.  
  13. createAccBtn = {
  14. "x": 140,
  15. "y": 5,
  16. "w": 140,
  17. "h": 30,
  18. "text": "Create An Account"
  19. }
  20. btns = [sendBtn, createAccBtn]
  21. name = "This Is Under Maintenance"
  22.  
  23. db = firebase.loadFirebase("AIzaSyDuC72a1917NqwNDy_vzqdb841xMyqCpeI", "chatroom-b7ae9", "chatroom-b7ae9")
  24.  
  25.  
  26. def setup():
  27.  
  28. size(400, 200)
  29.  
  30. def draw():
  31. background(0)
  32. drawBtns()
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. def printOnSent(url, data):
  40. print data["value"]["time"], "|", data["value"]["name"], "|", data["value"]["text"]
  41.  
  42. def drawBtns():
  43. for b in btns:
  44. stroke(255)
  45. fill(255)
  46. rect(b["x"], b["y"], b["w"], b["h"])
  47. stroke(0)
  48. fill(0)
  49. textSize(14)
  50. text(b["text"], b["x"]+10, b["y"]+20)
  51. def mouseClicked():
  52. if (sendBtn["x"] <= mouse.x <= sendBtn["x"] + sendBtn["w"] and sendBtn["y"] <= mouse.y <= sendBtn["y"] + sendBtn["h"]):
  53. if signedIn:
  54. newMessage = raw_input("What is your message?")
  55. curr = time.localtime(time.time())
  56. if curr[3] > 12:
  57. curr_hour = "pm"
  58. else:
  59. curr_hour = "am"
  60. curr_str = "%d:%d:%02d"%(curr[3]%12, curr[4], curr[5])+ curr_hour
  61. message = {
  62. 'name': name,
  63. 'text': newMessage,
  64. 'time': curr_str
  65. }
  66. db.push('messages/', message)
  67.  
  68. db.child_added('messages/', printOnSent)
  69.  
  70. else:
  71. print "You must be signed in to send messages!"
  72.  
  73. if (createAccBtn["x"] <= mouse.x <= createAccBtn["x"] + createAccBtn["w"] and createAccBtn["y"] <= mouse.y <= createAccBtn["y"] + createAccBtn["h"]):
  74. verifyNewAcc = raw_input("Create a new account?").lower()
  75. if verifyNewAcc == "yes":
  76. newUsername = raw_input("Enter your new username.")
  77. newPassword = raw_input("Enter your new password. (Note: Passwords are not encrypted and could be stolen.)")
  78. newAccount = {
  79. "username": newUsername,
  80. "password": newPassword,
  81. }
  82. db.push("/users", newAccount)
  83. else:
  84. pass
  85.  
  86. run()
  87. # (c) 2018 Henry Langmack under the GNU GPLv3 license.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement