Beispiel #1
0
	def GetVideoLinksBydate(self, offset, limit, startdate, enddate):
        # logging.info(category)
		startdate = datetime.strptime(startdate, '%Y-%m-%d')
		enddate = datetime.strptime(enddate, '%Y-%m-%d')
		vidquery = Video.query(Video.addedDate >= startdate, Video.addedDate <= enddate).order(-Video.addedDate)
		videos = vidquery.fetch(int(limit), offset=int(offset))
    
#         logging.info(str(videos))
		Videos = []
		for video in videos:
			vidobj = dict()
			vidobj["videoname"] = str(video.name.encode('utf-8'))
			vidobj["videolink"] = str(video.videolink)
			vidobj["videocat"] = str(video.videoCategory)
			vidobj["dubscount"] = str(video.dubsCount)
			vidobj["addeddate"] = str(video.addedDate)
			vidobj["videoGAEID"] = str(video.key.id())
			uniqueID = video.addedUser
# logging.info(uniqueID)
			if(uniqueID != None):
				userQuery = User.query(ancestor=self.UserKey(uniqueID))
				user = userQuery.get()
				if(user != None):
					vidobj["userName"] = user.userName
					vidobj["userDisplayName"] = user.userDisplayName

				vidobj["userUniqueID"] = str(uniqueID)
				# logging.info(video.key.id())
			Videos.append(vidobj)
		return Videos
Beispiel #2
0
    def UserVotesAnAudio(self, audioKey, direction, uniqueID):
        userQuery = User.query(ancestor=self.UserKey(uniqueID))
        user = userQuery.get()
        response = dict()
        if (user != None):
            if (direction == "up"):
                upVotedList = []
                upVotedList = user.upVotedAudios
                q = Audio.query(Audio.audiolink == audioKey)
                aud = q.get()
                # 			if(upVoteStatus == "1"):
                upvotecount = aud.upvotes
                upvotecount = int(upvotecount) + 1
                aud.upvotes = upvotecount
                upVotedList.append(audioKey)
                response["result"] = "Upvoted Successfully"
                user.upVotedAudios = upVotedList
            else:
                downVotedList = []
                downVotedList = user.downVotedAudios
                q = Audio.query(Audio.audiolink == audioKey)
                aud = q.get()
                downvotecount = aud.downvotes
                downvotecount = int(downvotecount) + 1
                aud.downvotes = downvotecount
                downVotedList.append(audioKey)
                response["result"] = "Downvoted Successfully"
                user.downVotedAudios = downVotedList
            user.put()
            aud.put()

            return json.dumps(response)
Beispiel #3
0
 def UpdateUserLanguages(self, uniqueID, langs):
     userQuery = User.query(ancestor=self.UserKey(uniqueID))
     user = userQuery.get()
     response = dict()
     if (user != None):
         user.knownlanguages = langs
         user.put()
         response["langList"] = langs
         response["result"] = "success"
     return response
Beispiel #4
0
    def UserHandleAvailability(self, handle, uniqueID):
        userQuery = User.query(User.userDisplayName == handle.lower())
        user = userQuery.get()
        available = {}

        if (user == None):
            available["available"] = "true"
        else:
            available["available"] = "false"

        return json.dumps(available)
Beispiel #5
0
 def checkIfUserExists(self, uniqueID, userName):
     userQuery = User.query(ancestor=self.UserKey(uniqueID))
     user2 = userQuery.get()
     response = dict()
     if (user2 != None):
         # logging.info(str(user2.uniqueID))
         if (str(user2.uniqueID) == uniqueID):
             response["valid"] = "Valid User"
             response["userDisplayName"] = user2.userDisplayName
     else:
         response["invalid"] = "User not Registered"
     return response
Beispiel #6
0
    def UpdateUserDisplayName(self, uniqueID, newName):
        userQuery = User.query(ancestor=self.UserKey(uniqueID))
        user = userQuery.get()
        response = dict()
        if (user != None):
            audquery = Audio.query(Audio.composerEmail == uniqueID)

            audios = audquery.fetch()
            for audio in audios:
                audio.composer = newName
                audio.put()
            user.userDisplayName = newName
            user.put()
            response["newName"] = newName

        return response
Beispiel #7
0
	def UpdateUserObject(self):
		userQuery = User.query().fetch(500)  # fetches all 500 users
		resp = {}
		for user in userQuery:
			logging.info(user.userDisplayName)
			userDisplayName = user.userDisplayName
			if(userDisplayName == None):
				user.userDisplayName = user.userName.replace(" ", "_")
				user.put()
				resp["result"] = "modified success"
			elif(" " in userDisplayName):
				user.userDisplayName = user.userDisplayName.replace(" ", "_")
				user.put()
				resp["result"] = "modified success"

		return resp
Beispiel #8
0
 def GetAudiosList(self, videoLink, language, offset, limit, uniqueID,
                   byUser, handle):
     if (language != ""):
         audquery = Audio.query(ancestor=self.AudioLink(videoLink)).filter(
             Audio.language == str(language)).order(-Audio.viewCount)
     elif (byUser == "true"):
         audquery = Audio.query(
             Audio.composer == handle).order(-Audio.recordeddate)
     else:
         audquery = Audio.query(
             ancestor=self.AudioLink(videoLink)).order(-Audio.viewCount)
     audios = audquery.fetch(int(limit), offset=int(offset))
     Audios = []
     upVotedList = []
     downVotedList = []
     if (uniqueID != ""):
         userQuery = User.query(ancestor=self.UserKey(uniqueID))
         user = userQuery.get()
         response = dict()
         if (user != None):
             upVotedList = user.upVotedAudios
             downVotedList = user.downVotedAudios
     for audio in audios:
         aud = dict()
         aud["audname"] = audio.name
         aud["audkey"] = str(audio.audiolink)
         aud["composer"] = audio.composer
         aud["starttime"] = str(audio.starttime)
         aud["viewcount"] = str(audio.viewCount)
         aud["language"] = str(audio.language)
         aud["upvotes"] = str(audio.upvotes)
         aud["downvotes"] = str(audio.downvotes)
         aud["videolink"] = str(audio.videolink)
         aud["recordeddate"] = str(audio.recordeddate)
         aud["audioGAEID"] = str(audio.key.id())
         # logging.info(upVotedList)
         if (audio.audiolink in upVotedList):
             aud["voted"] = "up"
         elif (audio.audiolink in downVotedList):
             aud["voted"] = "down"
         else:
             aud["voted"] = "none"
             #             aud["audname"]=audio.name
             # logging.info(audio.audiolink)
         Audios.append(aud)
     return Audios
Beispiel #9
0
 def UserUpVotesAnAudio(self, audioKey, upVoteStatus, uniqueID):
     userQuery = User.query(ancestor=self.UserKey(uniqueID))
     user = userQuery.get()
     response = {}
     if (user != None):
         upVotedList = []
         upVotedList = user.upVotedAudios
         q = Audio.query(Audio.audiolink == audioKey)
         aud = q.get()
         # 			if(upVoteStatus == "1"):
         upvotecount = aud.upvotes
         upvotecount = int(upvotecount) + 1
         aud.upvotes = upvotecount
         upVotedList.append(audioKey)
         response["upvoteIncreased"] = "Upvoted Successfully"
         user.upVotedAudios = upVotedList
         user.put()
         aud.put()
Beispiel #10
0
    def GetAudioDetails(self, audkey, uniqueID):
            
        upVotedList = []
        downVotedList = []
        if(str(uniqueID) != ""):
            userQuery = User.query(ancestor=self.UserKey(uniqueID))
            user = userQuery.get()
            
            if(user != None):
                upVotedList = user.upVotedAudios
                downVotedList = user.downVotedAudios

        q = Audio.query(Audio.audiolink == audkey)
#         q  = ndb.gql("Select * from Audio where audioblobkey = :1",audBlobkey)
        Audios = []
        audio = q.get()
        # logging.info(audio)
        if(audio != None):
            aud = dict()
            aud["audname"] = audio.name
            aud["audkey"] = str(audio.audiolink)
            aud["composer"] = audio.composer
            aud["starttime"] = str(audio.starttime)
            aud["viewcount"] = str(audio.viewCount)
            aud["language"] = str(audio.language)
            aud["upvotes"] = str(audio.upvotes)
            aud["downvotes"] = str(audio.downvotes)
            aud["recordeddate"] = str(audio.recordeddate)
            aud["audioGAEID"] = str(audio.key.id())
            
            if(audkey in upVotedList):
                aud["voted"] = "up"
            elif(audkey in downVotedList):
                aud["voted"] = "down"
            else:
                aud["voted"] = "none"
    #             aud["audname"]=audio.name
            
            Audios.append(aud)
        else:
            aud = dict()
            aud["error"] = "Url contains in valid audio key"
            Audios.append(aud)
        return json.dumps(Audios)
Beispiel #11
0
	def GetAudiosListByDate(self, offset, limit, startdate, enddate):
		startdate = datetime.strptime(startdate, '%Y-%m-%d')
		enddate = datetime.strptime(enddate, '%Y-%m-%d')


		# logging.info(startdate)
		audquery = Audio.query(Audio.recordeddate >= startdate, Audio.recordeddate <= enddate)
		audios = audquery.fetch(int(limit), offset=int(offset))
		Audios = []
		# upVotedList=[]
		# downVotedList=[]

		# if(uniqueID != ""):
		#     userQuery=User.query(ancestor=self.UserKey(uniqueID))
		#     user = userQuery.get()
		#     response = dict()
		#     if(user != None):
		#         upVotedList = user.upVotedAudios
		#         downVotedList = user.downVotedAudios
		for audio in audios:
			aud = dict()
			aud["audname"] = audio.name
			aud["audkey"] = str(audio.audioblobkey)
			aud["userDisplayName"] = audio.composer
			aud["uniqueID"] = str(audio.composerEmail)
			uniqueID = audio.composerEmail
			userQuery = User.query(ancestor=self.UserKey(uniqueID))
			user = userQuery.get()
			if(user != None):
				aud["userName"] = user.userName


			aud["starttime"] = str(audio.starttime)
			aud["viewcount"] = str(audio.viewCount)
			aud["language"] = str(audio.language)
			aud["upvotes"] = str(audio.upvotes)
			aud["downvotes"] = str(audio.downvotes)
			aud["videolink"] = str(audio.videolink)
			aud["recordeddate"] = str(audio.recordeddate)

			aud["audioGAEID"] = str(audio.key.id())
			Audios.append(aud)
		return Audios
Beispiel #12
0
    def GetUserDetailsByHandle(self, handle):
        userQuery = User.query(User.userName == handle)
        user = userQuery.get()
        userObj = {}
        if (user != None):
            userObj["userName"] = str(user.userName)
            userObj["userDisplayName"] = str(user.userDisplayName)
            userObj["uniqueID"] = str(user.uniqueID)

            userObj["knownlanguages"] = user.knownlanguages

            # dda = DubrooDataAccess()
            audioList = self.GetAudiosList("", "", 0, 10, user.uniqueID,
                                           "true", handle)
            userObj["audioList"] = audioList

        else:
            userObj["error"] = "User not found"

        return userObj
Beispiel #13
0
    def GetVideoLinks(self, category, sortBy, offset, limit):
        # logging.info(category)
        if(sortBy == "time"):
            if(category == "all"):
                vidquery = Video.query().order(-Video.addedDate)
            else:
                vidquery = Video.query(Video.videoCategory == str(category)).order(-Video.addedDate)
                
        elif(sortBy == "dubscount"):
            if(category == "all"):
                vidquery = Video.query().order(-Video.dubsCount)
            else:
                vidquery = Video.query(Video.videoCategory == str(category)).order(-Video.dubsCount)
                
        if(limit == "" or limit == None):
            videos = vidquery.fetch(100)
        else:
            videos = vidquery.fetch(int(limit), offset=int(offset))
        
        Videos = []
        for video in videos:
            vidobj = dict()
            vidobj["videoname"] = str(video.name.encode('utf-8'))
            vidobj["videolink"] = str(video.videolink)
            vidobj["videocat"] = str(video.videoCategory)
            vidobj["dubscount"] = str(video.dubsCount)
            vidobj["addeddate"] = str(video.addedDate)
            vidobj["videoGAEID"] = str(video.key.id())
            addedUser = video.addedUser
            if(addedUser != None and addedUser != ""):
                userQuery = User.query(ancestor=self.UserKey(addedUser))
                user = userQuery.get()
                if(user != None):
                    vidobj["userDisplayName"] = user.userDisplayName
            # vidobj["videoAddedBy"] = str(video.addedUser)

            # logging.info(video.key.id())
            Videos.append(vidobj)
        return json.dumps(Videos)
Beispiel #14
0
 def UserDownVotesAnAudio(self, audioKey, downVoteStatus, uniqueID):
     userQuery = User.query(ancestor=self.UserKey(uniqueID))
     user = userQuery.get()
     response = dict()
     if (user != None):
         downVotedList = []
         downVotedList = user.downVotedAudios
         q = Audio.query(Audio.audiolink == audioKey)
         aud = q.get()
         if (downVoteStatus == "1"):
             downvotecount = aud.downvotes
             downvotecount = int(downvotecount) + 1
             aud.downvotes = downvotecount
             downVotedList.append(audioKey)
             response["downvoteIncreased"] = "downvoted Successfully"
         else:
             downvotecount = aud.downvotes
             downvotecount = int(downvotecount) - 1
             aud.downvotes = downvotecount
             downVotedList.remove(audioKey)
             response["downvoteReduced"] = "downvote Reduced Successfully"
         user.downVotedAudios = downVotedList
         user.put()
         aud.put()
Beispiel #15
0
 def RegisterNewUser(self, uniqueID, userName):
     userQuery = User.query(ancestor=self.UserKey(uniqueID))
     user = userQuery.get()
     response = dict()
     if (user != None):
         logging.info(str(user.uniqueID))
         if (str(user.uniqueID) == uniqueID):
             response["exists"] = "User already Exists"
     else:
         user = User(parent=self.UserKey(uniqueID))
         user.uniqueID = uniqueID
         user.userName = userName
         user.userDisplayName = str(userName.replace(" ", "_"))
         user.upVotedAudios = []
         user.downVotedAudios = []
         user.addedVideos = []
         user.put()
         response["registered"] = "New user Added"
     return response