Example #1
0
    def post(self):
        type = self.request.get("type")
        user_email = users.get_current_user().email()
        keyWord = self.request.get("keyWord")
        searchItem = keyWord.lower()
        stream_lst = Stream.query().fetch()
        return_lst = []

        if type == "title":
            for stream in stream_lst:
                if stream.stream_name != None:
                    if searchItem in stream.stream_name.lower():
                        return_lst.append(stream)
        else:
            for stream in stream_lst:
                if  stream.description != None:
                    if searchItem in stream.description.lower():
                        return_lst.append(stream)


        logout_url = users.create_login_url(self.request.uri)
        logout_linktext = 'Logout'

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

        template_values = {
            'streams' :  sorted_streams,
            'length': len(  sorted_streams),
            'user' : users.get_current_user(),
            'url': logout_url,
            'url_linktext': logout_linktext,
        }
        self.render('ViewAllStream.html', **template_values)
Example #2
0
 def get(self):
     stream_id = self.request.get("stream_id")
     user_email = users.get_current_user().email()
     stream_lst = Stream.query(Stream.user_email == user_email, Stream.stream_id == stream_id).fetch()
     curStream = stream_lst[0]
     curStream.deleteStream()
     self.redirect('/manage')
Example #3
0
    def get(self):
        trending_stream_lst = Stream.query().order(-Stream.views_cnt).fetch(3)

        template_values = {
            'trending_stream_lst': trending_stream_lst
        }
        self.render('Trending.html', **template_values)
Example #4
0
    def get(self):
        # get parameters from the request
        search_keyword = self.request.get(IDENTIFIER_SEARCH_KEYWORD)
        search_type = self.request.get(IDENTIFIER_SEARCH_TYPE)
        search_keyword = str(search_keyword).lower()

        # query streams
        stream_lst = Stream.query().fetch()
        res_stream_lst = []
        stream_id_lst = []
        stream_name_lst = []
        cover_img_url_list = []

        if search_type == "title":
            for stream_iter in stream_lst:
                if stream_iter.stream_name:
                    if search_keyword in stream_iter.stream_name.lower():
                        res_stream_lst.append(stream_iter)
        else:
            for stream_iter in stream_lst:
                if stream_iter.description:
                    if search_keyword in stream_iter.description.lower():
                        res_stream_lst.append(stream_iter)

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

        for stream_itr in res_stream_lst:
            stream_id_lst.append(stream_itr.stream_id)
            stream_name_lst.append(stream_itr.stream_name)
            cover_img_url_list.append(stream_itr.cover_url)

        self.respond(stream_id_lst=stream_id_lst, stream_name_lst=stream_name_lst,
                     cover_img_url_list=cover_img_url_list, status="success")
Example #5
0
    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")
Example #6
0
    def get(self):

        print '[Cron::SendReportCronJob] started'

        # get the last report time
        global global_last_report_time
        if not global_last_report_time:
            global_last_report_time = datetime.now()
            return

        print '[Cron::SendReportCronJob] global_last_report_time:', global_last_report_time
        # get the sending rate
        reportRate = ReportSendingRate.query().fetch()

        if len(reportRate) != 0:
             reportRate = reportRate[0].sending_rate

        print '[Cron::SendReportCronJob] reportRate:', reportRate
        interval_in_mins = -99
        if reportRate == 0:
            # No reports. Return
            return
        elif reportRate == 1:
            interval_in_mins = 5
        elif reportRate == 2:
            interval_in_mins = 60
        elif reportRate == 3:
            interval_in_mins = 1440     # one day
        else:
            print 'Error in report rate : ', reportRate

        # comparing the sending rate with the time interval since the last report
        time_passed = (datetime.now() - global_last_report_time).seconds
        print '[Cron::SendReportCronJob] time_passed:', time_passed
        if time_passed < int(interval_in_mins)*60:
            return

        # send the report mail
        trending_stream_lst = Stream.query().order(-Stream.views_cnt).fetch(3)

        sender_mail_addr = REPORT_SENDER_NAME + "@" + APP_ID + MAILBOX_SURFIX
        subject = "Trending Streams from Connexus " + str(global_last_report_time)
        body = """ Here are the trending streams on Connexus now: \n
        1) %s - %s  \n
        2) %s - %s  \n
        3) %s - %s  \n
        """ % (trending_stream_lst[0].stream_name,
               trending_stream_lst[0].user_email,
               trending_stream_lst[1].stream_name,
               trending_stream_lst[1].user_email,
               trending_stream_lst[2].stream_name,
               trending_stream_lst[2].user_email)

        for receiver_addr in report_email_list:
            mail.send_mail(sender_mail_addr, receiver_addr, subject, body)

        print "Successfully sent the trending email to " + str(report_email_list)
        #reset the timer
        global_last_report_time = datetime.now()
Example #7
0
 def get(self):
     user_email = users.get_current_user().email()
     stream_lst = Stream.query(Stream.user_email == user_email).fetch()
     print stream_lst
     for stream in stream_lst:
         print stream
         stream.deleteStream()
     self.redirect('/manage')
Example #8
0
 def get(self):
     pattern = self.request.get("term")
     stream_lst = Stream.query().fetch()
     ret_lst = []
     if pattern:
         for stream in stream_lst:
             if pattern in stream.stream_name:
                 ret_lst.append(stream.stream_name)
     ret_lst.sort()
     if len(ret_lst) == 0:
         valid = False
     else:
         valid = True
     context = {"valid": valid, "ret_lst": ret_lst}
     self.response.write(json.dumps(context))
Example #9
0
    def get(self):
        user_email = users.get_current_user().email()

        stream_lst = Stream.query().fetch()

        logout_url = users.create_login_url(self.request.uri)
        logout_linktext = 'Logout'

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

        template_values = {
            'streams' : sorted_streams,
            'length': len(sorted_streams),
            'user' : users.get_current_user(),
            'url': logout_url,
            'url_linktext': logout_linktext,
        }
        self.render('ViewAllStream.html', **template_values)
Example #10
0
    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")
Example #11
0
 def get(self):
     all_streams_lst = Stream.query().fetch()
     print 'Cron job executing ... cleaning the view counts for ', len(all_streams_lst), ' streams.'
     for stream in all_streams_lst:
         stream.reset_view_cnt()