コード例 #1
0
ファイル: web_services.py プロジェクト: Yanhan0507/Apt
    def post(self):
        req_json = json.loads(self.request.body)
        user_email = req_json[IDENTIFIER_USER_EMAIL]
        is_check_subscription = req_json[IDENTIFIER_CHECK_SUBSCRIPTION]
        if not is_check_subscription:
            print 'StreamQueryService >> checking all streams created by user[', user_email, ']'
            user_streams_list = ndb.Query(ancestor=ndb.Key('Account', user_email)).fetch()
            sorted_streams_list = sorted(user_streams_list, key=lambda stream: stream.last_add, reverse=True)
            sid_list = []
            for stream in sorted_streams_list:
                sid_list.append(stream.stream_id)

            dumpablelist = [Stream.get_stream(stream_id).dumpStream()
                            for stream_id in sid_list]

            self.respond(user_streams_list=dumpablelist, status="success")

        else:
            print 'StreamQueryService >> checking all streams subscribed by user[', user_email, ']'
            subscribed_list = Subscription.query(Subscription.user_email == user_email).fetch()
            subscribed_stream_ids = []
            for subscribed_item in subscribed_list:
                sub_stream = Stream.query(Stream.stream_id == subscribed_item.stream_id).fetch()
                if len(sub_stream) != 0:
                    subscribed_stream_ids.append(sub_stream[0].stream_id)

            dumpablelist = [Stream.get_stream(stream_id).dumpStream()
                            for stream_id in subscribed_stream_ids]

            self.respond(user_sub_streams_list=dumpablelist, status="success")
コード例 #2
0
ファイル: web_services.py プロジェクト: Yanhan0507/Apt
    def post(self):
        req_json = json.loads(self.request.body)
        stream_id = req_json[IDENTIFIER_STREAM_ID]
        img_req_page = req_json[IDENTIFIER_IMG_REQ_PAGE]
        print 'ViewStreamService >> get stream id: ', stream_id, ', img_req_page:', img_req_page
        stream_obj = Stream()
        stream = stream_obj.get_stream(stream_id)

        # check if the stream exists
        if not stream:
            return self.respond(error="ViewStreamService >> Requested stream id %s does not exist." % stream_id)

        # now start retrieving images
        image_id_lst = []  # saving img ids
        image_res_idx_lst = []  # saving img indexes. There might be inconsistency between the requested list and this one
        blob_key_lst = []

        if not img_req_page:
            #   if the index list turns out to be empty
            return self.respond(error="ViewStreamService >> page index is empty")

        img_req_page = int(img_req_page)

        idx_lst = range(img_req_page*3, (img_req_page+1)*3, 1)

        for idx in idx_lst:
            if idx >= len(stream.image_id_lst):
                continue
            image_id_lst.append(stream.image_id_lst[idx])
            blob_key_lst.append(str(stream.blob_key_lst[idx]))
            image_res_idx_lst.append(idx)

        #   increase view count
        stream.increase_view_cnt()

        # next/prev page indexes
        if (img_req_page+1)*3 < len(stream.image_id_lst):
            next_pg_idx = img_req_page+1
        else:
            next_pg_idx = -1
        if img_req_page > 0:
            prev_pg_idx = img_req_page-1
        else:
            prev_pg_idx = -1

        self.respond(stream_owner=stream.user_email, image_res_idx_lst=image_res_idx_lst, blob_key_lst=blob_key_lst,
                     image_id_lst=image_id_lst, stream_name=stream.stream_name, stream_description=stream.description,
                     next_page_idx=next_pg_idx, prev_page_idx=prev_pg_idx,
                     status="Retrieved image indexes %r from stream %r" % (image_id_lst, stream_id))
コード例 #3
0
ファイル: web_services.py プロジェクト: Yanhan0507/Apt
    def get(self):
        stream_id = self.request.get(IDENTIFIER_STREAM_ID)
        start_idx = self.request.get(VIEW_STREAM_START_INDEX)

        if not start_idx:
            start_idx = 0
        else:
            start_idx = int(start_idx)

        stream_obj = Stream()
        stream = stream_obj.get_stream(stream_id)

        # check if the stream exists
        if not stream:
            return self.respond(error="ViewStreamService >> Requested stream id %s does not exist." % stream_id)

        # now start retrieving images
        img_id_lst = []  # saving img ids
        img_url_lst = []
        stream_img_id_lst = stream.image_id_lst

        nrof_imgs_in_stream = len(stream_img_id_lst)

        last_idx = start_idx + NUM_STREAMS_PER_PAGE

        if last_idx >= nrof_imgs_in_stream:
            last_idx = nrof_imgs_in_stream-1

        idx_lst = xrange(start_idx, last_idx)

        for img_idx in idx_lst:
            img_id = stream_img_id_lst[img_idx]
            img_id_lst.append(img_id)
            image = Image.get_image(img_id)
            img_url_lst.append(SERVICE_URL+"/view_photo/"+str(image.blob_key))

        # increase view count
        stream.increase_view_cnt()

        # generate upload url
        upload_url = blobstore.create_upload_url('/ws/stream/view_imgs')

        self.respond(stream_owner=stream.user_email, stream_name=stream.stream_name, img_id_lst=img_id_lst,
                     img_url_lst=img_url_lst, last_idx=last_idx, nrof_imgs_in_stream=nrof_imgs_in_stream,
                     upload_url=upload_url, status="success")
コード例 #4
0
ファイル: web_services.py プロジェクト: Yanhan0507/Apt
    def get(self):
        stream_id_lst=list()
        stream_name_lst=list()
        cover_img_url_list=list()
        stream_lst=list()

        is_view_all_subscribed = self.request.get(IS_VIEW_ALL_SUBSCRIBED)
        usr_id = self.request.get(IDENTIFIER_USER_EMAIL)

        if is_view_all_subscribed:
            print 'mViewAllStreamsService:: getting subscribed streams list for user', usr_id

            subscribed_list = Subscription.query(Subscription.user_email == usr_id).fetch()
            for subscribed_item in subscribed_list:
                stream_lst.append(Stream.get_stream(subscribed_item.stream_id))

        else:
            print 'mViewAllStreamsService:: getting all streams list'
            stream_lst = Stream.query().fetch()

        sorted_streams = sorted(stream_lst, key=lambda stream:stream.last_add, reverse=True)

        nrof_streams = len(sorted_streams)

        start_idx = self.request.get(VIEW_ALL_START_INDEX)
        if not start_idx or (start_idx > nrof_streams):
            start_idx = 0

        last_idx = start_idx+NUM_STREAMS_PER_PAGE
        if last_idx > nrof_streams:
            last_idx = nrof_streams-1

        for i in xrange(start_idx, last_idx+1):
            stream = sorted_streams[i]
            stream_id_lst.append(stream.stream_id)
            stream_name_lst.append(stream.stream_name)
            cover_img_url_list.append(stream.cover_url)

        print "mViewAllStreamsService:: stream_id_lst:" + str(stream_id_lst) + " |||| stream_name_lst:" + \
              str(stream_name_lst) + " |||| cover_img_url_list:" + str(cover_img_url_list) + " |||| last_idx:" + \
              str(last_idx)

        self.respond(stream_id_lst=stream_id_lst, stream_name_lst=stream_name_lst,
                     cover_img_url_list=cover_img_url_list, last_idx=last_idx, status="success")
コード例 #5
0
ファイル: web_services.py プロジェクト: Yanhan0507/Apt
    def post(self):
        req_json = json.loads(self.request.body)
        stream_id = req_json[IDENTIFIER_STREAM_ID]
        current_user_email = req_json[IDENTIFIER_USER_EMAIL]
        photo_key = req_json[IDENTIFIER_PHOTO_KEY]

        response = {}
        stream = Stream.get_stream(stream_id)

        if not (stream_id and current_user_email and photo_key and stream):
            response['error'] = "Failed to find photo_key (" + photo_key + ") for user (" + current_user_email \
                                + ") under stream(" + stream_id+")."
            self.respond(**response)
        elif stream.user_id != current_user_email:
            response['error'] = "Failed to remove image user (" + current_user_email \
                                + ") is not the owner of stream(" + stream_id+")."
            self.respond(**response)
        else:
            stream.deleteImage(photo_key)
            self.respond(status="success")
コード例 #6
0
ファイル: web_services.py プロジェクト: Yanhan0507/Apt
    def get(self):

        stream_id = self.request.get(IDENTIFIER_STREAM_ID)

        query_begin_date = self.request.get(QUERY_BEGIN_DATE)
        query_end_date = self.request.get(QUERY_END_DATE)

        begin_date = datetime.strptime(query_begin_date, '%Y-%m-%dT%H:%M:%S.%fZ')
        end_date = datetime.strptime(query_end_date, '%Y-%m-%dT%H:%M:%S.%fZ')

        stream = Stream.get_stream(stream_id)
        response = {}
        markers_lst = list()
        if not stream:
            response['error'] = "Failed to find stream(" + stream_id+")."
            self.respond(**response)
        else:
            for image_id in stream.image_id_lst:
                image = Image.get_image(image_id)
                if begin_date <= image.date <= end_date:
                    content = '<img src="'+get_serving_url(image.blob_key, size=100)+'">'
                    marker = {"latitude": image.location.lat, "longitude": image.location.lon, "content":content}
                    markers_lst.append(marker)
            self.respond(markers=markers_lst, status="success")