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


Python data_class.Stream类代码示例

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


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

示例1: post

    def post(self):
        pictures = self.request.get_all('files[]')
        results = []
        if len(pictures) > 0:
            stream_id = self.request.get('stream_id')
            # print "stream name is ", stream_id

            for image in pictures:
                Stream.insert_with_lock(stream_id, image)
                results.append({'name': '', 'url': '', 'type': '', 'size': 0})

        s = json.dumps({'files': results}, separators=(',', ':'))
        self.response.headers['Content-Type'] = 'application/json'
        # print "duming material is ", s
        return self.response.write(s)
开发者ID:LiboChen,项目名称:Mini-Project-Phase2,代码行数:15,代码来源:main.py

示例2: get

    def get(self):
        pattern = self.request.get("qry")
        print pattern
        all_streams = Stream.query(Stream.stream_id != '').fetch()
        search_result = []
        if pattern:
            for stream in all_streams:
                if pattern in stream.tags:
                    stream_id = stream.stream_id
                    blob_key_list = stream.blob_key
                    if stream.cover_url != '':
                        image_url = stream.cover_url
                    elif len(blob_key_list) == 0:
                        image_url = ''
                    else:
                        image_url = images.get_serving_url(blob_key_list[0])
                    result = ShowStream(image_url, 0, stream_id)
                    search_result.append(result)

        template_values = {
            'nav_links': USER_NAV_LINKS,
            'path': os.path.basename(self.request.path).capitalize(),
            'user_id': self.request.get('user_id'),
            'query_results': search_result,
        }

        template = JINJA_ENVIRONMENT.get_template('search.html')
        self.response.write(template.render(template_values))
开发者ID:LiboChen,项目名称:Mini-Project-Phase1-Submission,代码行数:28,代码来源:main.py

示例3: get

    def get(self):
        pattern = self.request.get("qry")
        print pattern
        all_streams = Stream.query(Stream.stream_id != '').fetch()
        search_result = []
        if pattern:
            for stream in all_streams:
                if pattern in stream.tags:
                    stream_id = stream.stream_id
                    if stream.cover_url != '':
                        image_url = stream.cover_url
                    else:
                        image_url = "https://encrypted-tbn0.gstatic.com/images?" + \
                                    "q=tbn:ANd9GcQ3DFxGhXSmn0MHjbEEtw-0N9sDKhyIP7tM_r3Wo1mY7WhY2xvZ"
                    result = ShowStream(image_url, 0, stream_id)
                    search_result.append(result)

        template_values = {
            'nav_links': USER_NAV_LINKS,
            'path': os.path.basename(self.request.path).capitalize(),
            'user_id': self.request.get('user_id'),
            'query_results': search_result,
        }

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

示例4: post

    def post(self):
        print 'stream id is', self.request.get('stream_id')
        try:
            upload = self.get_uploads()[0]
            print "upload size is", len(self.get_uploads())
            print "before error1"
            print users.get_current_user().nickname()

            user = users.get_current_user()
            ancestor_key = ndb.Key('User', str(user))
            user_streams = Stream.query_stream(ancestor_key).fetch()

            for stream in user_streams:
                if stream.stream_id == self.request.get('stream_id'):
                    print 'find my stream'
                    print type(stream.blob_key)
                    stream.blob_key.insert(0, upload.key())
                    stream.num_images += 1
                    stream.last_add = str(datetime.now())
                    stream.put()

            info = {'stream_id': self.request.get('stream_id')}
            info = urllib.urlencode(info)
            self.redirect('/view_single?' + info)

        except:
            print "error!"
开发者ID:LiboChen,项目名称:Mini-Project-Phase1-Submission,代码行数:27,代码来源:main.py

示例5: post

    def post(self):
        pictures = self.request.get_all('files')
        results = []
        print "Android_upload called"
        if len(pictures) > 0:
            stream_id = self.request.get('stream_id')
            print "stream name is ", stream_id
            str_lon = self.request.get('longitude')
            str_lat = self.request.get('latitude')
            print str_lon + " " + str_lat

            for image in pictures:
                if str_lon == "" or str_lat == "":
                    Stream.insert_with_lock(stream_id,image)
                else:
                    Stream.insert_with_lock(stream_id, image,False,float(str_lat),float(str_lon))
开发者ID:LiboChen,项目名称:Mini-Project-Phase3-Backend,代码行数:16,代码来源:main.py

示例6: get

    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,代码行数:60,代码来源:main.py

示例7: get

    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,代码行数:26,代码来源:main.py

示例8: post

    def post(self):
        data = json.loads(self.request.body)
        user = data["user_id"]
        print user, " is creating"
        new_stream = Stream(
            parent=ndb.Key("User", user),
            stream_id=data["stream_id"],
            user_id=data["user_id"],
            tags=data["tags"],
            cover_url=data["cover_url"] if "cover_url" in data else "",
            views=0,
            num_images=0,
            last_add=str(datetime.now()),
            owner=data["owner"],
        )

        new_stream.put()
        result = json.dumps({"status": "0"})
        self.response.write(result)
开发者ID:LiboChen,项目名称:Mini-Project-Phase1,代码行数:19,代码来源:main.py


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