当前位置: 首页>>代码示例>>Python>>正文


Python Stream.query方法代码示例

本文整理汇总了Python中data_class.Stream.query方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.query方法的具体用法?Python Stream.query怎么用?Python Stream.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在data_class.Stream的用法示例。


在下文中一共展示了Stream.query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def get(self):
        user = users.get_current_user()
        stream_id = self.request.get('stream_id')
        print 'stream id is', stream_id
        info = {'stream_id': self.request.get('stream_id')}
        info = urllib.urlencode(info)
        upload_url = blobstore.create_upload_url('/upload_image?'+info)

#       we should use the actual user
        user_streams = Stream.query(Stream.stream_id == stream_id).fetch()
        blob_key_list = []
        image_url = [""] * 3

        stream = user_streams[0]
        owner = stream.owner
        print 'stream id is', stream.stream_id
        if owner != str(user):
            stream.views += 1
            while len(stream.view_queue) > 0 and (datetime.now() - stream.view_queue[0]).seconds > 3600:
                del stream.view_queue[0]
            stream.view_queue.append(datetime.now())
            stream.put()
        blob_key_list = stream.blob_key     #get blob_key_list should be after stream.put()

        counter = 0
        has_image = True
        if len(blob_key_list) > 0:
            for blob_key in blob_key_list:
                image_url[counter] = images.get_serving_url(blob_key)
                counter += 1
                if counter == 3:
                    break;

        #calculate hasSub
        qry = StreamInfo.query_stream(ndb.Key('User', str(user))).fetch()
        has_sub = False
        if len(qry) == 0:
            has_sub = False
        else:
            for key in qry[0].subscribed:
                if key.get().stream_id == stream_id:
                    has_sub = True
                    break

        template_values = {
            'nav_links': USER_NAV_LINKS,
            'path': os.path.basename(self.request.path).capitalize(),
            'owner': owner,         #the owner of the stream
            'user': str(users.get_current_user()),   #current user
            'upload_url': upload_url,
            'image_url': image_url,
            'has_image': has_image,
            'hasSub': has_sub,
            'stream_id': stream_id,
        }

        print "owner is ", template_values['owner']
        print "user is ", template_values['user']
        template = JINJA_ENVIRONMENT.get_template('viewstream.html')
        self.response.write(template.render(template_values))
开发者ID:LiboChen,项目名称:Mini-Project-Phase1-Submission,代码行数:62,代码来源:main.py

示例2: get

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def get(self):
        user = users.get_current_user()
        print 'user is ', user
        subscribed_streams = []
        qry = StreamInfo.query_stream(ndb.Key('User', str(user))).fetch()
        if len(qry) > 0:
            for key in qry[0].subscribed:
                subscribed_streams.append(key.get())

        print subscribed_streams
        template_values = {
            'nav_links': USER_NAV_LINKS,
            'path': os.path.basename(self.request.path).capitalize(),
            'user_id': users.get_current_user(),
            'user_streams': Stream.query(Stream.owner == str(user)).fetch(),
            'subscribed_streams': subscribed_streams,
            'usr': user,
        }

        # all_streams = Stream.query(Stream.stream_id != '').fetch()
        # for s in all_streams:
        #     print s.stream_id
        #
        # print 'length of user_stream', len(template_values['user_streams'])
        # print 'length of subscribed streams', len(template_values['subscribed_streams'])

        template = JINJA_ENVIRONMENT.get_template('manage.html')
        self.response.write(template.render(template_values))
        print "in manage page, "
开发者ID:LiboChen,项目名称:Mini-Project-Phase2,代码行数:31,代码来源:main.py

示例3: get

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def get(self):
        user = users.get_current_user()
        stream_id = self.request.get("stream_id")
        print "stream id is", stream_id
        info = {"stream_id": self.request.get("stream_id")}
        info = urllib.urlencode(info)
        upload_url = blobstore.create_upload_url("/upload_image?" + info)

        #       we should use the actual user
        user_streams = Stream.query(Stream.stream_id == stream_id).fetch()
        blob_key_list = []
        image_url = [""] * 3

        stream = user_streams[0]
        owner = stream.owner
        print "stream id is", stream.stream_id
        if owner != str(user):
            stream.views += 1
            while len(stream.view_queue) > 0 and (datetime.now() - stream.view_queue[0]).seconds > 3600:
                del stream.view_queue[0]
            stream.view_queue.append(datetime.now())
            stream.put()
        blob_key_list = stream.blob_key  # get blob_key_list should be after stream.put()

        counter = 0
        has_image = True
        if len(blob_key_list) > 0:
            for blob_key in blob_key_list:
                image_url[counter] = images.get_serving_url(blob_key)
                counter += 1
                if counter == 3:
                    break

        # calculate hasSub
        qry = StreamInfo.query_stream(ndb.Key("User", str(user))).fetch()
        has_sub = False
        if len(qry) == 0:
            has_sub = False
        else:
            for key in qry[0].subscribed:
                if (not key) and key.get().stream_id == stream_id:
                    has_sub = True
                    break

        template_values = {
            "nav_links": USER_NAV_LINKS,
            "path": os.path.basename(self.request.path).capitalize(),
            "owner": owner,  # the owner of the stream
            "user": str(users.get_current_user()),  # current user
            "upload_url": upload_url,
            "image_url": image_url,
            "has_image": has_image,
            "hasSub": has_sub,
            "stream_id": stream_id,
        }

        print "owner is ", template_values["owner"]
        print "user is ", template_values["user"]
        template = JINJA_ENVIRONMENT.get_template("viewstream.html")
        self.response.write(template.render(template_values))
开发者ID:LiboChen,项目名称:Mini-Project-Phase1,代码行数:62,代码来源:main.py

示例4: get

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def get(self):
        target_long = (float)(self.request.get('longitude'))
        target_lat = (float)(self.request.get('latitude'))
        streams = Stream.query(Stream.stream_id != '').fetch()
        image_url = []

        for stream in streams:
            image_query = db.GqlQuery("SELECT *FROM Image WHERE ANCESTOR IS :1 ORDER BY upload_date DESC",
                                      db.Key.from_path('Stream', stream.stream_id))

            for image in image_query[0:stream.num_images]:
                d = dict()
                d["url"] = SERVICES_URL + "image?image_id=" + str(image.key())
                d["stream_id"] = stream.stream_id
                d["long"] = image.geo_loc.lon
                d["lat"] = image.geo_loc.lat
                image_url.append(d)

        mycmp = lambda a, b: (int)((target_long - a["long"]) * (target_long - a["long"]) +
                              (target_lat - a["lat"]) * (target_lat - a["lat"]) -
                              (target_long - b["long"]) * (target_long - b["long"]) -
                              (target_lat - b["lat"]) * (target_lat - b["lat"]))
        image_url.sort(mycmp)
        dict_passed = {'displayImages': image_url}
        json_obj = json.dumps(dict_passed, sort_keys=True, indent=4, separators=(',', ': '))
        self.response.write(json_obj)
开发者ID:LiboChen,项目名称:Mini-Project-Phase3-Backend,代码行数:28,代码来源:main.py

示例5: post

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def post(self):
        user = users.get_current_user()
        stream_id = self.request.get('stream_id')
        print 'first', stream_id
        streams = Stream.query(Stream.stream_id != '').fetch()
        for stream in streams:
            print 'hi', stream.stream_id
            if stream.stream_id == stream_id:
                info = {'error': 'you tried to create a stream whose name already existed'}
                info = urllib.urlencode(info)
                self.redirect('/error?'+info)
                return

        if self.request.get("subscribers"):
            mail.send_mail(sender=str(user)+"<"+str(user)+"@gmail.com>",
                           to="<"+self.request.get("subscribers")+">",
                           subject="Please subscribe my stream",
                           body=self.request.get("message"))

        form = {'stream_id': self.request.get('stream_id'),
                'user_id': str(users.get_current_user()),
                'tags': self.request.get('tags'),
#               'subscribers': self.request.get('subscribers'),
                'cover_url': self.request.get('cover_url'),
                'owner': str(users.get_current_user()),
                'views': 0,
                }

        form_data = json.dumps(form)
        result = urlfetch.fetch(payload=form_data, url=SERVICES_URL + 'create_a_new_stream',
                                method=urlfetch.POST, headers={'Content-Type': 'application/json'})
        self.redirect('/manage')
开发者ID:LiboChen,项目名称:Mini-Project-Phase2,代码行数:34,代码来源:main.py

示例6: post

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def post(self):
        data = json.loads(self.request.body)
        user = data["user"]
        for stream_id in data["stream_id"]:
            qry = Stream.query(Stream.stream_id == stream_id).fetch()
            if len(qry) > 0:
                qry[0].key.delete()

        #########helper code to delete zombie stream
        # streams = Stream.query(Stream.stream_id != '').fetch()
        # for stream in streams:
        #     if stream.stream_id == "ereraefdas":
        #         stream.key.delete()

        self.redirect("/manage")
开发者ID:LiboChen,项目名称:Mini-Project-Phase1,代码行数:17,代码来源:main.py

示例7: post

# 需要导入模块: from data_class import Stream [as 别名]
# 或者: from data_class.Stream import query [as 别名]
    def post(self):
        print "************delete stream******************"
        data = json.loads(self.request.body)
        user = data['user']
        for stream_id in data['stream_id']:
            qry = Stream.query(Stream.stream_id == stream_id).fetch()
            if len(qry) > 0:
                #delete all the images in this stream
                image_query = db.GqlQuery("SELECT *FROM Image WHERE ANCESTOR IS :1 ORDER BY upload_date DESC",
                                          db.Key.from_path('Stream', stream_id))
                for image in image_query[0:qry[0].num_images]:
                    image.delete()
                    print "******************delete images"

                Stream.reset_image_num(qry[0].stream_id)
                #delete stream
                qry[0].key.delete()

        self.redirect('/manage')
开发者ID:LiboChen,项目名称:Mini-Project-Phase3-Backend,代码行数:21,代码来源:main.py


注:本文中的data_class.Stream.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。