def getEvents(self, request): print("Entered Get Events Portion") temp = request.collegeId temp2 = request.clubId date = request.date future_date = request.future_date print ("Future date is",future_date) if(temp2==None): print "No CLubId" collegeId = ndb.Key('CollegeDb',int(temp)) events = Event.query(Event.collegeId==collegeId).order(-Event.start_time) elif(temp==None): print "No collegeID" clubId = ndb.Key('Club',int(temp2)) events = Event.query(Event.club_id==clubId).order(-Event.start_time) else: print "Not None" collegeId = ndb.Key('CollegeDb',int(temp)) clubId = ndb.Key('Club',int(temp2)) events = Event.query(Event.collegeId==collegeId,Event.club_id==clubId).order(-Event.start_time) #All events have been obtained, check if date field is provided and take only those that have start date = req.date finalList = [] if(future_date!=None): print ("Future Date part") for x in events: start_date = str(x.start_time.date()) print("Retrieve start date",start_date) if(start_date >= future_date): print ("Start Date is",start_date) print ("Event to be added",x.title) finalList.append(x) print("Returning all events from Final List") return Events(items=list(reversed([copyEventToForm(x) for x in finalList]))) elif(date != None): for x in events: start_date = str(x.start_time.date()) if(start_date == date): finalList.append(x) print("Returning all events from Final List") return Events(items=list(reversed([copyEventToForm(x) for x in finalList]))) else: print("Returning all events from Events List") return Events(items=list(reversed([copyEventToForm(x) for x in events])))
def getEvents(self, request): print("Entered Get Events Portion") temp = request.collegeId temp2 = request.clubId print "temp2" + str(temp2) if(temp2==None): print "No CLubId" collegeId = ndb.Key('CollegeDb',int(temp)) events = Event.query(Event.collegeId==collegeId) elif(temp==None): print "No collegeID" clubId = ndb.Key('Club',int(temp2)) events = Event.query(Event.clubId==clubId) else: print "Not None" collegeId = ndb.Key('CollegeDb',int(temp)) clubId = ndb.Key('Club',int(temp2)) events = Post.query(Event.collegeId==collegeId,Event.clubId==clubId) return Events(items=[copyEventToForm(x) for x in events])
def dontTouch(self, request): pid = ndb.Key('Profile',int(request.pid)) clubId = Club.query(Club.admin==pid) pylist=[] for x in clubId: print x.key posts = Post.query(Post.club_id==x.key).order(-Post.timestamp) events = Event.query(Event.club_id==x.key).order(-Post.timestamp) list1=[] list2=[] list1 = [copyToCollegeFeed(y) for y in events] list2 = [copyToCollegeFeed(z) for z in posts] list1+=list2 print "List-1",list1 pylist+=list1 pylist.sort(key=lambda x: x.timestamp, reverse=True) return CollegeFeed(items=pylist)
def deleteClub(request): #Steps to be incorporated for deletion of a club #1) Remove the club key from the clubsJoined list of every profile #2) Remove the club key from the follows list of every profile #3) Remove the club key from the admin list of everyprofile #4) Remove from college group list #5) Remove notifications that have the club id = given club id #6)Remove Join Creations and Join Requests #Call deleteEvent and deletePost for all events and posts that belong to the club #Delete the club entity club_key_id = request.club_id pid = request.pid print("Club_key_id", club_key_id) clubKey = ndb.Key('Club', int(request.club_id)) pidKey = ndb.Key('Profile', int(request.pid)) profileconsidered = pidKey.get() club = clubKey.get() print("Club to be removed", club) # Check if the club's collegeId and Profile's collegeId are the same print("club.coolegeId", club.collegeId) print("profileconsidered.collegeId", profileconsidered.collegeId) if (club.collegeId == profileconsidered.collegeId): #check if the profile is the admin of the club or if he is the super admin of the college print("entered first part") print("Club.admin", club.admin) print("pidKey", pidKey) if (club.admin == pidKey or club.collegeId in profileconsidered.superadmin): # Operation 1 : for every profile key in member list of club, extract profile and remove the club # from the clubsJoined list print("Ive Entered Corrctly") for profile_key in club.members: profile = profile_key.get() profile.clubsJoined.remove(clubKey) profile.put() # Operation 2 : for every profile key in follows list of club, extract profile and remove the club # from the follows list of Profile for profile_key in club.follows: profile = profile_key.get() profile.follows.remove(clubKey) profile.put() #Operation 3 : Get the profile of the admin and remove the club key from his admin list adminProfile = club.admin.get() adminProfile.admin.remove(clubKey) adminProfile.put() #Operation 4 : Get the college and remove the club key from his grouplist college = club.collegeId.get() college.group_list.remove(clubKey) college.put() #Operation 5 : Get all notifications where it matches with clubKey and remove them notificationsRet = Notifications.query( Notifications.clubId == clubKey) for notif in notificationsRet: notif.key.delete() #Operation 6 : Get all JoinCreations and JoinRequests where it matches with clubKey and remove them joinCreationRet = Join_Creation.query( Join_Creation.club_id == clubKey) for jc in joinCreationRet: jc.key.delete() joinReqRet = Join_Request.query(Join_Request.club_id == clubKey) for jr in joinReqRet: jr.key.delete() postReqRet = Post_Request.query(Post_Request.club_id == clubKey) for pr in postReqRet: pr.key.delete() #Operation 7 - Posts and Events delete postRet = Post.query(Post.club_id == clubKey) for posts in postRet: likePostmini = LikePost() likePostmini.from_pid = str(club.admin.id()) likePostmini.postId = str(posts.key.id()) deletePost(likePostmini) eventRet = Event.query(Event.club_id == clubKey) for events in eventRet: modifyeventmini = ModifyEvent() modifyeventmini.from_pid = str(club.admin.id()) modifyeventmini.eventId = str(events.key.id()) deleteEvent(modifyeventmini) #Operation 8 - delete club clubKey.delete()
def personalFeed(self, request): pid = ndb.Key('Profile',int(request.pid)) profile = pid.get() posts = [] events = [] pylist = [] pylist2 = [] pageLimit = 5 skipCount=0 upperBound=pageLimit print request.pageNumber try: skipCount = (int(request.pageNumber)-1)*pageLimit upperBound = int(request.pageNumber)*pageLimit except: print "Didnt give pageNumber-Default to 1" list1=[] list2=[] for x in profile.follows: print x print "LOOP-1" posts = (Post.query(Post.club_id==x)) events = (Event.query(Event.club_id==x)) list1=[] list2=[] #list1 = [copyToCollegeFeed(y) for y in events] #list2 = [copyToCollegeFeed(z) for z in posts] iteration=0 for y in posts: #if(iteration>=skipCount and iteration<upperBound): list1.append(copyToCollegeFeed(y)) #iteration+=1 #if(iteration==upperBound): # break iteration=0 for z in events: #if(iteration>=skipCount and iteration<upperBound): list1.append(copyToCollegeFeed(z)) #iteration+=1 #if(iteration==upperBound): # break print "LIST-1" print list1 pylist+=list1 pylist2+=list2 #for x in events: # print x #pylist = [copyToCollegeFeed(x) for x in events] #pylist2 = [copyToCollegeFeed(x) for x in posts] pylist+=pylist2 #pylist.append(copyToCollegeFeed(x) for x in events) pylist.sort(key=lambda x: x.timestamp, reverse=True) finalList = [] for i in xrange(skipCount,upperBound): if(i>=len(pylist)): break finalList.append(pylist[i]) cf = CollegeFeed() cf.items = finalList cf.completed=str(0) if(upperBound>=len(pylist)): cf.completed=str(1) #print pylist[1].timestamp #print pylist CollegeFeed(items=finalList) #return CollegeFeed(items=[copyToCollegeFeed(x) for x in events]) return cf
def collegeFeed(self, request): print "Entered the Like Posts Section" temp = request.clubId flag =0 pageLimit = 5 skipCount=0 upperBound=pageLimit print request.pageNumber try: skipCount = (int(request.pageNumber)-1)*pageLimit upperBound = int(request.pageNumber)*pageLimit except: print "Didnt give pageNumber-Default to 1" if request.date != None: date = datetime.strptime(getattr(request,"date"),"%Y-%m-%d").date() flag = 1 #print "TYPE-DATE", type(date) if (temp==None): collegeId = ndb.Key('CollegeDb',int(request.collegeId)) posts = Post.query(Post.collegeId==collegeId).order(-Post.timestamp) events = Event.query(Event.collegeId==collegeId).order(-Event.timestamp) print "TEMP IS NONE" else: clubId = ndb.Key('Club',int(request.clubId)) posts = Post.query(Post.club_id==clubId).order(-Post.timestamp) events = Event.query(Event.club_id==clubId).order(-Event.timestamp) print events #CollegeFeed(items=[copyEventToForm(x) for x in posts]) #CollegeFeed(items=[copyEventToForm(x) for x in events]) #pylist = [copyToCollegeFeed(x) for x in events] pylist=[] for x in events: print "TImestamp",type(x.timestamp.strftime("%Y-%m-%d")) if flag==1: if x.timestamp.strftime("%Y-%m-%d") == str(date): pylist.append(copyToCollegeFeed(x)) else: pylist.append(copyToCollegeFeed(x)) print pylist pylist2 = [] for x in posts: print "TImestamp",type(x.timestamp.strftime("%Y-%m-%d")) if flag==1: if x.timestamp.strftime("%Y-%m-%d") == str(date): pylist.append(copyToCollegeFeed(x)) else: pylist.append(copyToCollegeFeed(x)) #pylist2 = [copyToCollegeFeed(x) for x in posts] pylist+=pylist2 #pylist.append(copyToCollegeFeed(x) for x in events) pylist.sort(key=lambda x: x.timestamp, reverse=True) #print pylist[1].timestamp #print pylist #CollegeFeed(items=pylist) #return CollegeFeed(items=[copyToCollegeFeed(x) for x in events]) #return CollegeFeed(items=pylist) finalList = [] for i in xrange(skipCount,upperBound): if(i>=len(pylist)): break finalList.append(pylist[i]) cf = CollegeFeed() cf.items = finalList cf.completed=str(0) if(upperBound>=len(pylist)): cf.completed=str(1) #print pylist[1].timestamp #print pylist CollegeFeed(items=finalList) #return CollegeFeed(items=[copyToCollegeFeed(x) for x in events]) return cf
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 } 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): for pid in event.attendees: person = pid.get() LOG.info("PID is") LOG.info(person) gcmId = person.gcmId if (gcmId): attendeeslist.append(gcmId) 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)
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 } 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): for pid in event.attendees: person = pid.get() LOG.info("PID is") LOG.info(person) gcmId = person.gcmId if (gcmId): attendeeslist.append(gcmId) 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)
def deleteClub(request): # Steps to be incorporated for deletion of a club # 1) Remove the club key from the clubsJoined list of every profile # 2) Remove the club key from the follows list of every profile # 3) Remove the club key from the admin list of everyprofile # 4) Remove from college group list # 5) Remove notifications that have the club id = given club id # 6)Remove Join Creations and Join Requests # Call deleteEvent and deletePost for all events and posts that belong to the club # Delete the club entity club_key_id = request.club_id pid = request.pid print("Club_key_id", club_key_id) clubKey = ndb.Key("Club", int(request.club_id)) pidKey = ndb.Key("Profile", int(request.pid)) profileconsidered = pidKey.get() club = clubKey.get() print("Club to be removed", club) # Check if the club's collegeId and Profile's collegeId are the same print("club.coolegeId", club.collegeId) print("profileconsidered.collegeId", profileconsidered.collegeId) if club.collegeId == profileconsidered.collegeId: # check if the profile is the admin of the club or if he is the super admin of the college print("entered first part") print("Club.admin", club.admin) print("pidKey", pidKey) if club.admin == pidKey or club.collegeId in profileconsidered.superadmin: # Operation 1 : for every profile key in member list of club, extract profile and remove the club # from the clubsJoined list print("Ive Entered Corrctly") for profile_key in club.members: profile = profile_key.get() profile.clubsJoined.remove(clubKey) profile.put() # Operation 2 : for every profile key in follows list of club, extract profile and remove the club # from the follows list of Profile for profile_key in club.follows: profile = profile_key.get() profile.follows.remove(clubKey) profile.put() # Operation 3 : Get the profile of the admin and remove the club key from his admin list adminProfile = club.admin.get() adminProfile.admin.remove(clubKey) adminProfile.put() # Operation 4 : Get the college and remove the club key from his grouplist college = club.collegeId.get() college.group_list.remove(clubKey) college.put() # Operation 5 : Get all notifications where it matches with clubKey and remove them notificationsRet = Notifications.query(Notifications.clubId == clubKey) for notif in notificationsRet: notif.key.delete() # Operation 6 : Get all JoinCreations and JoinRequests where it matches with clubKey and remove them joinCreationRet = Join_Creation.query(Join_Creation.club_id == clubKey) for jc in joinCreationRet: jc.key.delete() joinReqRet = Join_Request.query(Join_Request.club_id == clubKey) for jr in joinReqRet: jr.key.delete() postReqRet = Post_Request.query(Post_Request.club_id == clubKey) for pr in postReqRet: pr.key.delete() # Operation 7 - Posts and Events delete postRet = Post.query(Post.club_id == clubKey) for posts in postRet: likePostmini = LikePost() likePostmini.from_pid = str(club.admin.id()) likePostmini.postId = str(posts.key.id()) deletePost(likePostmini) eventRet = Event.query(Event.club_id == clubKey) for events in eventRet: modifyeventmini = ModifyEvent() modifyeventmini.from_pid = str(club.admin.id()) modifyeventmini.eventId = str(events.key.id()) deleteEvent(modifyeventmini) # Operation 8 - delete club clubKey.delete()