Beispiel #1
0
def ReadTimestamps():
    mTimestamp = Timestamp()
    UsersTimestamps = mFirebaseData.child(Constants.Timestamps).get()
    print("Deleting relevant timestamps..")
    if (UsersTimestamps is not None):
        if (UsersTimestamps.each() is not None):
            for timestamp in UsersTimestamps.each():
                userId = timestamp.key()
                mTimestamp.setUserId(userId)
                print(userId)
                details = mFirebaseData.child(
                    Constants.Timestamps).child(userId).get()
                details = timestamp.val()
                details = dict(details)
                mTimestamp.setTimestamp(
                    details.get(Constants.Timestamp_Timestamp))
                mTimestamp.setBeachName(
                    details.get(Constants.Timestamp_BeachName))
                mTimestamp.setBeachId(details.get(Constants.Timestamp_BeachID))
                mTimestamp.setBeachListenerId(
                    details.get(Constants.Timestamp_BeachListenerId))
                mTimestamp.setBeachCountry(
                    details.get(Constants.Timestamp_Country))
                mTimestamp.print()
                date = datetime.datetime.utcfromtimestamp(
                    int(mTimestamp.Timestamp))
                dayOfMonth = date.day
                month = date.month
                currentDayOfMonth = datetime.datetime.utcnow().day
                currentMonth = datetime.datetime.utcnow().month
                print("received date: month: " + str(month) + " day " +
                      str(dayOfMonth))
                print("current date: month: " + str(currentMonth) + " day " +
                      str(currentDayOfMonth))
                checkInHour = datetime.datetime.utcfromtimestamp(
                    int(mTimestamp.Timestamp)).hour
                checkInMinutes = int(
                    datetime.datetime.fromtimestamp(int(
                        mTimestamp.Timestamp)).minute)
                print("check in minutes: " + str(checkInMinutes))
                print("check in hour: " + str(checkInHour))
                currentHour = datetime.datetime.utcnow().hour
                currentMinute = datetime.datetime.utcnow().minute
                print("current hour : " + str(currentHour))
                print("current minute: " + str(currentMinute))
                if ((checkInHour + Constants.Timestamp_Max_Hour) < currentHour
                        or (currentMonth > month)
                        or (currentDayOfMonth > dayOfMonth)):
                    print("deleting timestamp...")
                    mFirebaseData.child(Constants.Timestamps).child(
                        mTimestamp.UserID).remove()
                    mFirebaseData.child(Constants.Beaches).child(
                        mTimestamp.BeachID).child(Constants.Peoplelist).child(
                            mTimestamp.UserID).remove()
                    mFirebaseData.child(Constants.Users).child(
                        mTimestamp.UserID).child(
                            Constants.CurrentBeach).remove()
                    CurrentDevices = mFirebaseData.child(
                        Constants.BeachesListener).child(
                            mTimestamp.BeachListenerID).child(
                                Constants.CurrentDevices).get()
                    CurrentDevices = int(CurrentDevices.val())
                    CurrentDevices = CurrentDevices - 1
                    mFirebaseData.child(Constants.BeachesListener).child(
                        mTimestamp.BeachListenerID).child(
                            Constants.CurrentDevices).set(CurrentDevices)
                else:
                    print("Not deleteing from timestamps")