Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from processing import *
- import firebase
- import time
- signedIn = False
- sendBtn = {
- "x": 5,
- "y": 5,
- "w": 130,
- "h": 30,
- "text": "Send A Message"
- }
- createAccBtn = {
- "x": 140,
- "y": 5,
- "w": 140,
- "h": 30,
- "text": "Create An Account"
- }
- btns = [sendBtn, createAccBtn]
- name = "This Is Under Maintenance"
- db = firebase.loadFirebase("AIzaSyDuC72a1917NqwNDy_vzqdb841xMyqCpeI", "chatroom-b7ae9", "chatroom-b7ae9")
- def setup():
- size(400, 200)
- def draw():
- background(0)
- drawBtns()
- def printOnSent(url, data):
- print data["value"]["time"], "|", data["value"]["name"], "|", data["value"]["text"]
- def drawBtns():
- for b in btns:
- stroke(255)
- fill(255)
- rect(b["x"], b["y"], b["w"], b["h"])
- stroke(0)
- fill(0)
- textSize(14)
- text(b["text"], b["x"]+10, b["y"]+20)
- def mouseClicked():
- if (sendBtn["x"] <= mouse.x <= sendBtn["x"] + sendBtn["w"] and sendBtn["y"] <= mouse.y <= sendBtn["y"] + sendBtn["h"]):
- if signedIn:
- newMessage = raw_input("What is your message?")
- curr = time.localtime(time.time())
- if curr[3] > 12:
- curr_hour = "pm"
- else:
- curr_hour = "am"
- curr_str = "%d:%d:%02d"%(curr[3]%12, curr[4], curr[5])+ curr_hour
- message = {
- 'name': name,
- 'text': newMessage,
- 'time': curr_str
- }
- db.push('messages/', message)
- db.child_added('messages/', printOnSent)
- else:
- print "You must be signed in to send messages!"
- if (createAccBtn["x"] <= mouse.x <= createAccBtn["x"] + createAccBtn["w"] and createAccBtn["y"] <= mouse.y <= createAccBtn["y"] + createAccBtn["h"]):
- verifyNewAcc = raw_input("Create a new account?").lower()
- if verifyNewAcc == "yes":
- newUsername = raw_input("Enter your new username.")
- newPassword = raw_input("Enter your new password. (Note: Passwords are not encrypted and could be stolen.)")
- newAccount = {
- "username": newUsername,
- "password": newPassword,
- }
- db.push("/users", newAccount)
- else:
- pass
- run()
- # (c) 2018 Henry Langmack under the GNU GPLv3 license.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement