예제 #1
0
 def __init__(self, roomID):
     assert '.' not in roomID
     with open('credentials', 'r') as f:
         config = dict(json.load(f))
     self.roomID = roomID
     firebase = pyrebase.initialize_app(config)
     self.db = firebase.database()
예제 #2
0
def change_value():
    #Firebase details
    url ="https://fir-test-8c15d.firebaseio.com/"#"https://java1d.firebaseio.com/"
    apikey = "AIzaSyCOj5VmBPcENI3WuZaXnwEdc016wk-Xe7k"#"AIzaSyD_szQHeqkFF9f4FzZzh0FBseupcV8O0kk"
    config = {"apiKey": apikey,"databaseURL": url }#required details for the firebase database
    firebase = pyrebase.initialize_app(config)#initializing firebase
    db =firebase.database()#creating a database object to acccess firebase realtime database
    print("Trying to authorize " )
    try:
        f = open("roomcount.txt", "r", encoding = "utf_8") #This text file was written by our java code that contains room name and room count
        print("herrrr")

        namecount = []
        for line in f:
            namecount.append(line.strip())
        f.close()
      
      
        
        db.child("Locations").child(namecount[0]).child("number").set(int(namecount[1]))#Setting the locations room number to the number of perople obtained from the text file
        db.child("Locations").child(namecount[0]).child("occupancy rate").set(int(50))#Similar for occupancy rate
        print(5)
        total = db.child("Locations").child(namecount[0]).child("total capacity").get().val()#Similar for total capacity
        db.child("Locations").child(namecount[0]).child("occupancy rate").set(int(namecount[1])/int(total))

        print("Authorization successful")
    except:#take care of exceptions
        print("ERROR: Authorization failed. Try again")
 def __init__(self, loginCallback=None):
     self.loggedIn = False
     self.structured_data = {}        
     self.loginCallback = loginCallback
     
     #connect
     firebase = pyrebase.initialize_app(config)
     self.db = firebase.database()                
예제 #4
0
 def __init__(self):
     firebase = pyrebase.initialize_app(config)
     self.db = firebase.database()
     state = self.db.child('/state').get().val()
     if state is None:
         self.state = [{'text': 'off', 'state': 'normal'},
                       {'text': 'off', 'state': 'normal'}]
     else:
         self.state = state
class Check_others(Screen):
    url = firebasesecrets['url']  # URL to Firebase database
    apikey = firebasesecrets['apikey']  # unique token used for authentication

    config = {
        "apiKey": apikey,
        "databaseURL": url,
    }
    firebase = pyrebase.initialize_app(config)
    db = firebase.database()

    # edit_others functions changes the occupancy of the tables in the room when the user presses the button
    # The room occupancy should be updated both on the firebase and the app

    def edit_others1(self):
        if self.ids.others1.text == "Occupied":
            self.ids.others1.text = "Empty"
            self.ids.others1_name.text = "ended"

        else:
            self.ids.others1.text = "Occupied"
            self.ids.others1_name.text = self.db.child("name1").get().val()

        self.db.child("table1").set(self.ids.others1.text)
        self.db.child("name1").set(self.ids.others1_name.text)

    def edit_others2(self):
        if self.ids.others2.text == "Occupied":
            self.ids.others2.text = "Empty"
            self.ids.others2_name.text = "ended"

        else:
            self.ids.others2.text = "Occupied"
            self.ids.others2_name.text = "Unknown"

        self.db.child("table2").set(self.ids.others2.text)
        self.db.child("name2").set(self.ids.others2_name.text)

# check_update updates the values of the app from firebase data at 3 seconds intervals
# The occupancy of the tables should similarly be derived from the name values

    def check_update(self, *args):
        #self.ids.others1.text = self.db.child("table1").get().val()
        self.ids.others1_name.text = self.db.child("name1").get().val()

        if self.ids.others1_name.text == "":
            self.ids.others1.text = "Empty"
        else:
            self.ids.others1.text = "Occupied"
            self.ids.others1_name.text = "by " + self.ids.others1_name.text

        self.ids.others2_name.text = self.db.child("name2").get().val()
        if self.ids.others2_name.text == "":
            self.ids.others2.text = "Empty"
        else:
            self.ids.others2.text = "Occupied"
            self.ids.others2_name.text = "by " + self.ids.others2_name.text
예제 #6
0
    def __init__(self):
        #creates attributes
        self.loggedIn = False
        self.data = {}

        firebase = pyrebase.initialize_app(
            config)  #initialize firebase storage
        self.db = firebase.database()
        self.my_prof_slots = [
        ]  #list of slots for currently logged in professor
예제 #7
0
    def zero(self, value):
        url = "https://ohsnappp-837d7.firebaseio.com"
        apikey = "AIzaSyAOKIBnAUiI9VSt3x1FoocWp0udv34xdqA"

        config = {
            "apiKey": apikey,
            "databaseURL": url,
        }

        firebase = pyrebase.initialize_app(config)
        db = firebase.database()
        db.child('Joel').set(0)
예제 #8
0
def init_firebase():
    # Create a firebase object by specifying the URL of the database and its secret token.
    # The firebase object has functions put and get, that allows user to put data onto
    # the database and also retrieve data from the database.
    from credential import *

    firebase = pyrebase.initialize_app(config)
    auth = firebase.auth()
    db = firebase.database()
    user = auth.sign_in_with_email_and_password(email, password)

    return db, user
예제 #9
0
    def __init__(self, node, room=None, mode='rw'):
        # Get room name if unspecified
        if not room:
            room = get_room_arg()

        # Connect to database
        self.db = pyrebase.initialize_app({
            "apiKey": self.API_KEY,
            "databaseURL": self.DATABASE_URL
        }).database()

        # Save arguments
        self._node = node
        self.room = room
        self.mode = mode

        # Check if room exists
        if not self.node('Name').get().val():
            print('Room does not exist')
            exit(-1)
예제 #10
0
from libdw import pyrebase
import datetime
import RPi.GPIO as GPIO
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.clock import Clock

############################# Firebase Initialisation ####################################################
url = 'https://test-firebase-95e43.firebaseio.com/'
apikey = 'AIzaSyDDzT4FSVfdXLocVNLyio0vwFlWRkhmnTQ'

config = {
    "apiKey": apikey,
    "databaseURL": url,
}

firebase = pyrebase.initialize_app(config)
db = firebase.database()
##########################################################################################################

############################# GPIO Initialization ########################################################
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(12, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(16, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(20, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(21, GPIO.IN, GPIO.PUD_DOWN)
black = 25  # Subject Buttons
green = 12
red = 16
yellow = 20
white = 21  # Starts the Application