def post(self):
        body2 = self.request.body
        j = json.loads(body2)
        usr = j["usr"]
        stream_to_sub = j["stream_name"]

        targetStream = stream_bundle.myStream.query(
            ancestor=management.stream_key(stream_to_sub)).fetch(1)[0]
        subStreamKey = targetStream.key

        streamIOwn_query = stream_bundle.stream_bundles.query(
            ancestor=management.stream_key(usr)).fetch(1)
        stream_bundles_entity = streamIOwn_query[0]
        stream_bundles_entity.stream_isublist.append(subStreamKey)
        stream_bundles_entity.put()
Ejemplo n.º 2
0
    def get(self):
        inputText = self.request.get("query")
        print(inputText)
        print(type(inputText))
        # A query string
        keyword = ".*"
        # print(keyword)
        # Build the Query and run the search
        query = search.Query(query_string=keyword)
        index = search.Index(name='ConnexStreamPool', namespace="Connex")
        result = index.search(query)
        streamlist = list()

        for doc in result.results:
            singleStream = \
                stream_bundle.myStream.query(ancestor=management.stream_key(str(doc.fields[0].value))).fetch()[0]
            streamlist.append(singleStream.streamname)

        # for doc in result.results:
        #     streamlist.append(str(doc.fields[0].value))
        print(streamlist)
        output = []
        for streamName in streamlist:
            if inputText in streamName:
                output.append(streamName)
        print(output)
        output = json.dumps(output)
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(output)
    def post(self):
        try:
            stream_key = self.request.get("stream_key")
            #usrcomments = self.request.get("usrcomments")
            self.response.write(stream_key)
            myStream = stream_bundle.myStream.query(
                ancestor=management.stream_key(str(stream_key))).fetch(1)[0]

            #myStream.blob_key.append(upload.key())
            #myStream.photoComments = [usrcomments] + myStream.photoComments
            for blob_info in self.get_uploads():
                myStream.blob_key = [blob_info.key()] + myStream.blob_key
                myStream.imageCreateDateList = [
                    time.mktime(time.gmtime()) * 1000
                ] + myStream.imageCreateDateList
                myStream.imageLocation = [
                    Location(longitude=random.uniform(-170, 170),
                             latitude=random.uniform(-50, 50))
                ] + myStream.imageLocation
            print(len(myStream.blob_key))
            print(type(time.mktime(time.gmtime()) * 1000))
            myStream.lastNewPicture = datetime.datetime.now()
            # modified the following code
            # print(self.get_uploads().__len__())
            # print(myStream.numOfPictures)
            myStream.numOfPictures = myStream.numOfPictures + len(
                self.get_uploads())
            # print(myStream.numOfPictures)
            myStream.put()
            self.redirect("/viewStream?Stream_id=" + stream_key)
        except:
            self.error(500)
Ejemplo n.º 4
0
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('myhtml/Trending.html')
        # get the top3 guys with stream names
        top3list = stream_bundle.top3streams.query().fetch()[0].top3list
        # fetch the streams
        stream_list = list()

        for stream in top3list:
            if str(stream) is not "":
                myStream = stream_bundle.myStream.query(
                    ancestor=management.stream_key(str(stream))).fetch(1)[0]
                l_stream_name = myStream.streamname
                i_stream_blobkey = myStream.blob_key[0]
                i_stream_views = len(myStream.viewTimeQueue)
                i_stream = streamToShow(l_stream_name, i_stream_blobkey,
                                        i_stream_views)
                stream_list.append(i_stream)

        curr_usr = users.get_current_user()
        logout_url = users.create_logout_url('/')
        template_values = {
            'usr': curr_usr,
            'streams_to_show': stream_list,
            'logout_url': logout_url,
        }

        self.response.write(template.render(template_values))
    def post(self):
        stream_key = self.request.get("Stream_id")
        myStream_qurey = stream_bundle.myStream.query(
            ancestor=management.stream_key(str(stream_key))).fetch(1)
        if len(myStream_qurey) == 0:
            self.redirect("/myhtml/Errorpage.html?Error_code=404")
            return
        myStream = stream_bundle.myStream.query(
            ancestor=management.stream_key(str(stream_key))).fetch(1)[0]

        imagesToJquery = []
        pic = image()
        # get image if any
        if (len(myStream.blob_key) > 0):
            image_blob_key_list = myStream.blob_key
            image_created_time_list = myStream.imageCreateDateList
            image_location_list = myStream.imageLocation
            for bbkey in image_blob_key_list:
                pic.url = images.get_serving_url(bbkey)
                imagesToJquery.append(copy.deepcopy(pic))
            for i in range(len(image_created_time_list)):
                imagesToJquery[i].created = image_created_time_list[i]
            for i in range(len(image_location_list)):
                imagesToJquery[i].lat = image_location_list[i].latitude
                imagesToJquery[i].lng = image_location_list[i].longitude

        # for i in range(len(imagesToJquery)):
        #     print(i)
        #     print(imagesToJquery[i].url)
        #     print(imagesToJquery[i].created)
        #     print(imagesToJquery[i].lat)
        #     print(imagesToJquery[i].lng)
        #     # print(vars(imagesToJquery[i]))
        #     print(imagesToJquery[i].__dict__)
        json_string = json.dumps([img.__dict__ for img in imagesToJquery])
        print(json_string)
        # output = json.dumps(imagesToJquery)
        # obj_list = json.loads(json_string)
        # for obj in obj_list:
        #     print("#")
        #     print(obj['url'])
        #     print(obj['created'])
        #     print(obj['lat'])
        #     print(obj['lng'])
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(json_string)
Ejemplo n.º 6
0
    def get(self):
        # A query string
        keyword = self.request.get('search_key')

        query = search.Query(query_string=keyword)

        index = search.Index(name='ConnexStreamPool', namespace="Connex")
        result = index.search(query)

        streamlist = list()

        for doc in result.results:
            singleStream = stream_bundle.myStream.query(
                ancestor=management.stream_key(str(
                    doc.fields[0].value))).fetch()[0]
            streamlist.append(singleStream)

        stream_names = list()
        stream_owners = list()
        cover_urls = list()

        for stream in streamlist:
            if stream.numOfPictures > 0:
                l_stream_name = stream.streamname
                stream_names.append(l_stream_name)
                l_stream_owner = str(stream.streamOwner)
                if l_stream_owner.find("@") < 0:
                    l_stream_owner = l_stream_owner + "@gmail.com"
                stream_owners.append(l_stream_owner)

                i_stream_coverurl = stream.urltoCoverPhoto
                hasCover = True
                i_stream_blobKey = ""
                if (i_stream_coverurl == ""):
                    hasCover = False
                    i_stream_blobKey = stream.blob_key[0]
                if (hasCover):
                    cover_urls.append(i_stream_coverurl)
                else:
                    cover_urls.append(images.get_serving_url(i_stream_blobKey))

        if len(stream_names) > 0:
            hasResult = True
        else:
            hasResult = False

        dictPassed = {
            'keyword': keyword,
            'hasResult': hasResult,
            'stream_names': stream_names,
            'stream_owners': stream_owners,
            'cover_url': cover_urls,
        }
        jsonObj = json.dumps(dictPassed, sort_keys=True)
        self.response.write(jsonObj)
Ejemplo n.º 7
0
    def post(self):
        # A query string
        keyword = self.request.get('SearchInput')

        # Build the QueryOptions
        # Create a FieldExpression
        query_options = search.QueryOptions(limit=5, )

        # Build the Query and run the search
        query = search.Query(query_string=keyword, options=query_options)

        index = search.Index(name='ConnexStreamPool', namespace="Connex")
        result = index.search(query)
        streamlist = list()

        for doc in result.results:
            singleStream = stream_bundle.myStream.query(
                ancestor=management.stream_key(str(
                    doc.fields[0].value))).fetch()[0]
            streamlist.append(singleStream)

        streams_to_show = list()

        for stream in streamlist:
            if stream.numOfPictures > 0:
                l_stream_name = stream.streamname
                i_stream_coverurl = stream.urltoCoverPhoto
                hasCover = True
                i_stream_blobKey = ""
                if (i_stream_coverurl == ""):
                    hasCover = False
                    i_stream_blobKey = stream.blob_key[0]
                i_stream = streamToShow(l_stream_name, i_stream_coverurl,
                                        i_stream_blobKey, hasCover)
                streams_to_show.append(i_stream)

        curr_usr = users.get_current_user()
        logout_url = users.create_logout_url('/')
        if len(streams_to_show) > 0:
            hasResult = True
        else:
            hasResult = False

        template_values = {
            'usr': curr_usr,
            'streams_to_show': streams_to_show,
            'logout_url': logout_url,
            'hasResult': hasResult,
        }
        template = JINJA_ENVIRONMENT.get_template('myhtml/SearchHome.html')
        self.response.write(template.render(template_values))
Ejemplo n.º 8
0
    def post(self):
        try:
            upload = self.get_uploads()[0]
            stream_key = self.request.get("stream_key")
            usrcomments = self.request.get("usrcomments")
            self.response.write(stream_key)
            myStream = stream_bundle.myStream.query(ancestor= management.stream_key(str(stream_key))).fetch(1)[0]

            #myStream.blob_key.append(upload.key())
            myStream.photoComments = [usrcomments] + myStream.photoComments
            myStream.blob_key = [upload.key()] + myStream.blob_key
            myStream.lastNewPicture = datetime.datetime.now()
            myStream.numOfPictures = myStream.numOfPictures+1
            myStream.put()
            self.redirect("/viewStream?Stream_id="+stream_key)
        except:
            self.error(500)
    def post(self):
        upload = self.get_uploads()[0]

        stream_key = self.request.params['stream_id']
        pic_lat = self.request.params['pic_lat']
        pic_long = self.request.params['pic_long']


        myStream = stream_bundle.myStream.query(ancestor= management.stream_key(str(stream_key))).fetch(1)[0]

        myStream.blob_key = [upload.key()] + myStream.blob_key
        myStream.lastNewPicture = datetime.datetime.now()
        myStream.numOfPictures = myStream.numOfPictures+1
        myStream.pic_lat = [pic_lat] + myStream.pic_lat
        myStream.pic_long = [pic_long] + myStream.pic_long
        myStream.put()

        # some debug info
        dictPassed = {'pic_lat': pic_lat,'pic_long':pic_long,'stream_id':stream_key}
        jsonObj = json.dumps(dictPassed, sort_keys=True,indent=4, separators=(',', ': '))
        self.response.write(jsonObj)
    def get(self):
        stream_key = self.request.get("Stream_id")
        usr_launch_search = self.request.get('usr_launch_search')

        myStream = stream_bundle.myStream.query(ancestor= management.stream_key(str(stream_key))).fetch(1)[0]

        # increment the view number if usr other than owner view the stream
        l_stream_owner = str(myStream.streamOwner)
        if l_stream_owner.find("@") < 0:
            l_stream_owner = l_stream_owner+"@gmail.com"
        if(usr_launch_search != l_stream_owner):
            num_of_view = myStream.numOfViews
            myStream.numOfViews = num_of_view + 1;
            # get the view Time queue
            viewTimeQueue = myStream.viewTimeQueue
            currentTime = datetime.datetime.now()
            while len(viewTimeQueue)> 0 and (currentTime - viewTimeQueue[0]).seconds > 3600:
                del viewTimeQueue[0]
            viewTimeQueue.append(datetime.datetime.now())
            myStream.viewTimeQueue = viewTimeQueue
            myStream.put()

        # get image if any
        if(len(myStream.blob_key) > 0):
            image_bolb_key_list = myStream.blob_key
            image_url = list()
            for bbkey in image_bolb_key_list:
                image_url.append(images.get_serving_url(bbkey))
            weHaveImage = True
        else:
            weHaveImage = False
            image_url = list()

        dictPassed = {
            'displayImages_name': stream_key,
            'wehaveimage': weHaveImage,
            'image_url': image_url,
        }
        jsonObj = json.dumps(dictPassed, sort_keys=True)
        self.response.write(jsonObj)
    def post(self):
        body2 = self.request.body
        js_c = json.loads(body2)
        stream_id = js_c["stream_id"]
        numOfPage = js_c["page"]

        # fetch the urls
        myStream = stream_bundle.myStream.query(ancestor= management.stream_key(str(stream_id))).fetch(1)[0]
        blob_key_list = myStream.blob_key
        image_url = list()
        for bbkey in blob_key_list:
            image_url.append(images.get_serving_url(bbkey))

        # self.response.write(image_url)

        i = (numOfPage-1)*3
        j = i+3

        # check boundarys
        endIndex = len(image_url)-1
        if(i>endIndex):
            url_for_return = list()   # empty list
        elif (j > endIndex):
            url_for_return = image_url[i:(endIndex+1)]
        else:
            url_for_return = image_url[i:j]

        a = [""]*3
        s = list()
        for url in url_for_return:
            s.append(str(url))
        a[0:len(s)] = s

        myUrls = {
            'urls': s
        }
        self.response.write(json.dumps(myUrls))
Ejemplo n.º 12
0
    def post(self):
        body2 = self.request.body
        j = json.loads(body2)
        streamName = j["name"]
        streamTag = j["tag"]
        urltocover = j["urltocover"]
        invitelist = j["emaillist"]
        add_msg = j['add_msg']
        createDate = datetime.datetime.now()
        usr = users.get_current_user()

        # check if the stream is already created

        query_string = "stream_name: "+streamName
        query = search.Query(query_string=query_string)



        index = search.Index(name='ConnexStreamPool', namespace="Connex")
        result = index.search(query)
        for doc in result.results:
            singleStream = stream_bundle.myStream.query(ancestor= management.stream_key(str(doc.fields[0].value))).fetch()
            if(len(singleStream)>0 ):
                if(singleStream[0].streamname == streamName):
                    Duplicate = {
                        'duplicate': "dup",
                        'aha': singleStream[0].streamname
                    }
                    self.response.write(json.dumps(Duplicate))
                    return





        # add the stream_name to our search database for later search operation
        # step1 create the document
        # get doc_id
        doc_id = stream_bundle.doc_id.query(ancestor=ndb.Key('Connex','Coonex')).fetch(1)[0]
        mydoc_id = doc_id.doc_id
        doc_id.doc_id = mydoc_id+1
        doc_id.put()
        stream_document = search.Document(
            doc_id=str(mydoc_id),
            fields=[
                search.TextField(name='stream_name', value=streamName)
            ]
        )
        # step2 retrieve the index if not exit create one, index name is ConnexStreamPool
        myIndex = search.Index(name='ConnexStreamPool', namespace="Connex")

        # step3 put the document into the index


        myNewStream = stream_bundle.myStream(parent=stream_key(usr_name=streamName),
                                             streamOwner=usr,
                                             streamname=streamName,
                                             urltoCoverPhoto=urltocover,
                                             doc_id=stream_document.doc_id,
                                             lastNewPicture=None,
                                             createTime=createDate.date(),
                                             numOfPictures=0,
                                             numOfViews=0,
                                             )

        myIndex.put(stream_document)
        newStreamKey = myNewStream.put()

        # get the stream_bundles
        streamIOwn_query = stream_bundle.stream_bundles.query(
            ancestor=stream_key(usr)).fetch(1)
        stream_bundles_entity = streamIOwn_query[0]
        stream_bundles_entity.stream_iownlist.append(newStreamKey)
        stream_bundles_entity.put()

        # at last we send out invite email
        if len(invitelist) > 0:
            self.inviteEmail(invitelist, add_msg)
Ejemplo n.º 13
0
    def get(self):
        stream_key = self.request.get("Stream_id")
        usr = users.get_current_user()
        logout_url = users.create_logout_url('/')

        myStream_qurey = stream_bundle.myStream.query(ancestor= management.stream_key(str(stream_key))).fetch(1)
        if len(myStream_qurey) == 0:
            self.redirect("/myhtml/Errorpage.html?Error_code=404")
            return
        myStream = stream_bundle.myStream.query(ancestor= management.stream_key(str(stream_key))).fetch(1)[0]
        owner = myStream.streamOwner
        # increase the view by 1 if not view by owner
        if owner != usr:
            myStream.numOfViews = myStream.numOfViews +1
            # get the view Time queue
            viewTimeQueue = myStream.viewTimeQueue
            currentTime = datetime.datetime.now()
            while len(viewTimeQueue)> 0 and (currentTime - viewTimeQueue[0]).seconds > 3600:
                del viewTimeQueue[0]
            viewTimeQueue.append(datetime.datetime.now())
            myStream.viewTimeQueue = viewTimeQueue
            myStream.put()

        # test to see if this is the stream usr sub
        streamIOwn_query = stream_bundle.stream_bundles.query(ancestor=management.stream_key(usr)).fetch(1)
        stream_bundles_entity = streamIOwn_query[0]
        # get the list I sub
        listIsub = stream_bundles_entity.stream_isublist
        IsubthisStream = False
        for key in listIsub:
            if(key.get() is not None and key.get().streamname == stream_key):
                IsubthisStream = True
                break

        template = JINJA_ENVIRONMENT.get_template('myhtml/viewSingleStream.html')

        # step1 Create an upload URL if user want to upload pages
        upload_url = blobstore.create_upload_url('/viewSingleAfterUpload')

        # get image if any
        if(len(myStream.blob_key) > 0):
            image_bolb_key_list = myStream.blob_key
            image_url = [""]*3
            counter = 0
            for bbkey in image_bolb_key_list:
                image_url[counter]= images.get_serving_url(bbkey)
                counter = counter +1
                if(counter == 3):
                    break
            weHaveImage = True
        else:
            weHaveImage = False
            image_url = [""]*3

        template_values = {
            'owner': str(owner),
            'usr': str(usr),
            'blobstore_url': upload_url,
            'stream_key': stream_key,
            'haveImage': weHaveImage,
            'imageUrl': image_url,
            'IsubThisStream': IsubthisStream,
            'logout_url': logout_url,
        }

        self.response.write(template.render(template_values))