Exemple #1
0
def createClubRequestHelper(request):
    collegeId = ndb.Key('CollegeDb', int(request.collegeId))
    print("Required College ID", collegeId)

    college_ret = collegeId.get()

    print("College Ret", college_ret)
    if (college_ret):
        club_ret = Club.query(Club.name == request.clubName).filter(
            Club.abbreviation == request.abbreviation).filter(
                Club.collegeId == college_ret.key).fetch(1)
        print("Club Ret", club_ret)
        if (len(club_ret) == 0):
            clubRequest = createClub(request)
            currentProfile = clubRequest.to_pid.get()
            newNotif = Notifications(
                clubName=clubRequest.club_name,
                clubphotoUrl=clubRequest.photoUrl,
                #to_pid = clubRequest.to_pid,
                type="Club Creation Request",
                timestamp=dt.datetime.now().replace(microsecond=0))

            newNotif.to_pid_list.append(clubRequest.to_pid)

            print("Notification to be inserted in club creation request",
                  newNotif)
            newNotifKey = newNotif.put()
            data = {
                'message': clubRequest.club_name,
                "title": "Creation Request",
                'id': str(clubRequest.key.id()),
                'type': "Admin"
            }
            print(data)
            gcmId = currentProfile.gcmId
            gcm_message = GCMMessage(gcmId, data)
            gcm_conn = GCMConnection()
            #gcm_conn.notify_device(gcm_message)
            print("Finished the clubRequest")

    return None
Exemple #2
0
def getEventsBasedonTimeLeft():
    logging.basicConfig(level=logging.DEBUG)
    LOG = logging.getLogger(__name__)
    current = dt.datetime.now().replace(microsecond=0)
    #current_utc = current - dt.timedelta(hours =5,minutes=30)
    currentDate = current.date()
    currentTime = current.time()
    LOG.info("Current time")
    LOG.info(currentTime)
    eventlist = []
    event_query = Event.query().fetch()
    for event in event_query:
        #LOG.info("Event")
        #LOG.info(event.title)
        #LOG.info(event.start_time)
        start_time_utc = event.start_time - dt.timedelta(hours=5, minutes=30)
        start_date = start_time_utc.date()
        diff = start_date - currentDate
        #LOG.info("Considering this event")
        #LOG.info(event.title)

        if (diff == dt.timedelta(hours=0) and diff == dt.timedelta(minutes=0)
                and diff == dt.timedelta(seconds=0)):
            LOG.info("this event is happening today")
            LOG.info(event.title)
            start_time = start_time_utc.time()
            FMT = '%H:%M:%S'
            tdelta = datetime.strptime(str(start_time),
                                       FMT) - datetime.strptime(
                                           str(currentTime), FMT)
            LOG.info("Time delta is")
            LOG.info(tdelta)

            b = dt.timedelta(days=0)
            c = dt.timedelta(hours=2)

            if tdelta >= b:
                LOG.info("made through first part")

                if (tdelta <= c):
                    LOG.info(event.title)
                    eventlist.append(event.key)
                    LOG.info("has reached here")
                    LOG.info("Creating notification")
                    group = event.club_id.get()
                    groupName = group.name

                    data = {
                        'message': event.title + "About to start soon",
                        "title": groupName,
                        'id': str(event.key.id()),
                        'type': "Event"
                    }
                    LOG.info(data)

                    #get the followers of the club pids. Get GCM Id's from those and send
                    LOG.info("Event attendees list")
                    LOG.info(event.attendees)

                    attendeeslist = []
                    if (event.attendees):
                        newNotif = Notifications(
                            clubName=groupName,
                            clubId=event.club_id,
                            clubphotoUrl=group.photoUrl,
                            eventName=event.title,
                            eventId=event.key,
                            timestamp=dt.datetime.now().replace(microsecond=0),
                            type="Reminder")

                        for pid in event.attendees:
                            person = pid.get()
                            LOG.info("PID is")
                            LOG.info(person)
                            gcmId = person.gcmId

                            #to_pid = pid)

                            if (gcmId):
                                attendeeslist.append(gcmId)
                                newNotif.to_pid_list.append(pid)
                            #newNotif = Notifications(
                            #           clubName = groupName,
                            #           clubId = event.club_id,
                            #           clubphotoUrl = group.photoUrl,
                            #           eventName = event.title,
                            #           eventId = event.key,
                            #           timestamp = dt.datetime.now().replace(microsecond = 0),
                            #           type = "Reminder",
                            #           to_pid = pid)

                        newNotifKey = newNotif.put()

                    LOG.info("Attendees GCM list is")
                    LOG.info(attendeeslist)
                    gcm_message = GCMMessage(attendeeslist, data)
                    gcm_conn = GCMConnection()
                    gcm_conn.notify_device(gcm_message)

                    LOG.info("Chill")

                else:
                    LOG.info(
                        "This event is still some time away from notification")
            else:
                LOG.info("This event is over")

    LOG.info(eventlist)
Exemple #3
0
def createPostHelper(request):
    response = MessageResponse()
    print("Entered Post Entry Portion")
    flag = 0
    try:
        person_key = ndb.Key('Profile', int(request.fromPid))

        profile = person_key.get()
        print(profile)
        club_key = ndb.Key('Club', int(request.clubId))
        if club_key in profile.follows:
            print "Present"
            newPost = postEntry(request, flag)

            print("NEW POST", newPost)
            response.status = "1"
            response.text = "Inserted into Posts Table"
            #Create Notification Feed
            group = newPost.club_id.get()
            groupName = group.name
            data = {
                'message': groupName,
                "title": newPost.title,
                'id': str(newPost.key.id()),
                'type': "Post"
            }

            postlist = []
            if (group.follows):
                newNotif = Notifications(
                    clubName=groupName,
                    clubId=newPost.club_id,
                    clubphotoUrl=group.photoUrl,
                    postName=newPost.title,
                    postId=newPost.key,
                    timestamp=newPost.timestamp,
                    type="Post",
                    #to_pid = pid
                )
                for pid in group.follows:
                    person = pid.get()
                    newNotif.to_pid_list.append(pid)
                    print("PID is", person)
                    gcmId = person.gcmId
                    if (gcmId):
                        print("GCM ID is", gcmId)
                        postlist.append(gcmId)

                    #newNotif = Notifications(
                    #          clubName = groupName,
                    #           clubId = newPost.club_id,
                    #           clubphotoUrl = group.photoUrl,
                    #           postName = newPost.title,
                    #           postId = newPost.key,
                    #           timestamp = newPost.timestamp,
                    #           type = "Post",
                    #           to_pid = pid
                    #           )

                print("Notification to be inserted", newNotif)
                newNotifKey = newNotif.put()

            print("post list is", postlist)
            gcm_message = GCMMessage(postlist, data)
            gcm_conn = GCMConnection()
            #gcm_conn.notify_device(gcm_message)

        else:
            print "Not present"
            clubRequest = postRequest(request)
            response.status = "2"
            response.text = "Inserted into Posts Requests Table"

    except Exception, e:
        print "Error"
        print str(e)
        response.status = "3"
        response.text = "Couldn't insert into Posts Table"
Exemple #4
0
def createEventHelper(request):
    response = MessageResponse()
    print("Entered Event Entry Portion")

    try:
        person_key = ndb.Key('Profile', int(request.eventCreator))
        print(person_key)
        profile = person_key.get()

        club_key = ndb.Key('Club', int(request.clubId))
        if club_key in profile.clubsJoined:
            print "GOING INTO EVENTS ENTRY"
            newEvent = eventEntry(request)
            response.status = "1"
            response.text = "Inserted into Posts Table"
            group = newEvent.club_id.get()
            groupName = group.name

            data = {
                'message': groupName,
                "title": newEvent.title,
                'id': str(newEvent.key.id()),
                'type': "newEvent"
            }
            #get the followers of the club pids. Get GCM Id's from those and send
            print("GROUP FOLLOWS LIST ", group.follows)

            eventlist = []
            if (group.follows):
                newNotif = Notifications(
                    clubName=groupName,
                    clubId=newEvent.club_id,
                    clubphotoUrl=group.photoUrl,
                    eventName=newEvent.title,
                    eventId=newEvent.key,
                    timestamp=newEvent.timestamp,
                    type="Event",
                    #to_pid = pid
                )

                for pid in group.follows:
                    person = pid.get()
                    newNotif.to_pid_list.append(pid)
                    gcmId = person.gcmId
                    if (gcmId):
                        print("GCM ID is", gcmId)
                        eventlist.append(gcmId)

                    #newNotif = Notifications(
                    #             clubName = groupName,
                    #             clubId = newEvent.club_id,
                    #             clubphotoUrl = group.photoUrl,
                    #             eventName = newEvent.title,
                    #             eventId = newEvent.key,
                    #             timestamp = newEvent.timestamp,
                    #             type = "Event",
                    #             to_pid = pid
                    #             )
                print("Notification to be inserted", newNotif)
                newNotifKey = newNotif.put()

            print("Event list is", eventlist)
            gcm_message = GCMMessage(eventlist, data)
            gcm_conn = GCMConnection()
            #gcm_conn.notify_device(gcm_message)

            print("Should have worked")

        else:
            print "Not Present"
            response.status = "2"
            response.text = "Could not insert"

    except Exception, e:
        print "Error"
        print str(e)
        response.status = "3"
        response.text = "Error"
Exemple #5
0
def approveClubHelper(request):

    clubRequest = ndb.Key('Club_Creation', int(request.reqId))
    action = request.action

    print("Action is", action)
    req = clubRequest.get()
    currentProfile = req.from_pid.get()
    print("From Pid profile is", currentProfile)
    if (action == 'N'):
        print("Disapproving request and removing entry")
        print("Request Approval Denied")
        newNotif = Notifications(
            clubName=req.club_name,
            clubphotoUrl=req.photoUrl,
            #to_pid = req.from_pid,
            type="Rejected Club Creation Request",
            timestamp=dt.datetime.now().replace(microsecond=0))

        newNotif.to_pid_list.append(req.from_pid)
        print("Notification to be inserted in club approval rejection",
              newNotif)
        newNotifKey = newNotif.put()
        data = {
            'message': req.club_name,
            "title": "Creation Request Denied",
            'id': "None",
            'type': "None"
        }
        print(data)
        gcmId = currentProfile.gcmId
        gcm_message = GCMMessage(gcmId, data)
        gcm_conn = GCMConnection()
        #gcm_conn.notify_device(gcm_message)
        req.key.delete()

    elif (req and req.approval_status == "N"):
        status = approveClub(req)
        if (status == "Y"):
            print("Request Approval Granted")
            newClub = createClubAfterApproval(req)
            currentProfile = newClub.admin.get()
            if (newClub):
                newNotif = Notifications(
                    clubName=newClub.name,
                    clubId=newClub.key,
                    clubphotoUrl=newClub.photoUrl,
                    #to_pid = newClub.admin,
                    type="Approved Club Creation Request",
                    timestamp=dt.datetime.now().replace(microsecond=0))
                newNotif.to_pid_list.append(newClub.admin)

            print("Notification to be inserted in club approval ", newNotif)
            newNotifKey = newNotif.put()
            data = {
                'message': newClub.name,
                "title": "Creation Request Approved",
                'id': str(newClub.key.id()),
                'type': "Club"
            }
            print(data)
            gcmId = currentProfile.gcmId
            gcm_message = GCMMessage(gcmId, data)
            gcm_conn = GCMConnection()
            #gcm_conn.notify_device(gcm_message)

            print("The club that has been created is", newClub)
            req.key.delete()
        else:
            print("Request Approval Denied")
            newNotif = Notifications(
                clubName=req.club_name,
                clubphotoUrl=req.photoUrl,
                #to_pid = req.from_pid,
                type="Rejected Club Creation Request",
                timestamp=dt.datetime.now().replace(microsecond=0))

            newNotif.to_pid_list.append(req.from_pid)

            print("Notification to be inserted in club approval rejection",
                  newNotif)
            newNotifKey = newNotif.put()
            data = {
                'message': req.club_name,
                "title": "Creation Request Denied",
                'id': "None",
                'type': "None"
            }
            print(data)
            gcmId = currentProfile.gcmId
            gcm_message = GCMMessage(gcmId, data)
            gcm_conn = GCMConnection()
            #gcm_conn.notify_device(gcm_message)
            req.key.delete()

    return message_types.VoidMessage()