Example #1
0
    def get(self):
        log_query = Behavlog.query()
        logs = log_query.fetch()

        labellist = []
        vectorlist = []

        for low in logs:

            templist = []

            for i in range(VEC_LENGTH):
                for j in range(VEC_LENGTH):
                    templist.append(0)

            for i in range(0, LIST_LENGTH - 1):
                for j in range(i + 1, LIST_LENGTH):
                    if low.vector[i] >= 0 and low.vector[j] >= 0:
                        templist[(VEC_LENGTH * low.vector[i]) +
                                 low.vector[j]] = 1

            vectorlist.append(templist)
            labellist.append(low.sflabel)

        for i in range(len(labellist)):
            print(labellist[i])
            print(vectorlist[i])
Example #2
0
    def get(self):

        try:
            whoswho = self.session[str(self.request.remote_addr)]

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            command = self.session['command']

            if command == 'cmtthds':

                try:

                    videoid = self.session['videoid']
                    commentthd = youtube.commentThreads().list(
                        videoId=videoid, part='id,snippet').execute()

                    items = []

                    for item in commentthd.get('items', []):
                        items.append(item)

                    if len(items) > 0:
                        idx = random.randrange(0, len(items))
                        self.session['cmtthdid'] = items[idx].get('id')
                        if items[idx].get('snippet').get(
                                'authorChannelId').get(
                                    'value') == self.session['channel']:
                            self.session['cstate'] = 5
                            self.session['cmtthdmine'] = True
                        else:
                            self.session['cstate'] = 6
                            self.session['cmtthdmine'] = False

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 6
Example #3
0
    def get(self):

        try:
            whoswho = self.session[str(self.request.remote_addr)]

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            command = self.session['command']

            if command == 'playlists':

                try:

                    playlistlist = youtube.playlists().list(
                        part='snippet', mine=True).execute()

                    playlists = []

                    for item in playlistlist.get('items', []):
                        print item.get('id')
                        playlists.append('%s' % (item.get('id')))

                    if len(playlists) > 0:
                        idx = random.randrange(0, len(playlists))
                        self.session['playlistId'] = playlists[idx]
                        self.session['playlistIdmine'] = True
                        self.session['cstate'] = 3

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 1
Example #4
0
    def get(self):

        try:
            whoswho = self.session[str(self.request.remote_addr)]

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            command = self.session['command']

            if command == 'activities':

                try:

                    comments = youtube.activities().list(
                        part='id,snippet,contentDetails', mine=True).execute()

                    items = []

                    for item in comments.get('items', []):
                        items.append(item)

                    if len(items) > 0:
                        idx = random.randrange(0, len(items))
                        self.session['activityid'] = items[idx].get('id')

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 21
Example #5
0
    def get(self):

        try:
            whoswho = self.session[str(self.request.remote_addr)]

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            developerKey=Keys.DEVELOPER_KEY)

            try:

                searchlist = youtube.search().list(q='Google Official',
                                                   part='snippet',
                                                   type='video',
                                                   maxResults=5).execute()

                videos = []

                for item in searchlist.get('items', []):
                    if item['id']['kind'] == 'youtube#video':
                        videos.append('%s' % (item['id']['videoId']))

                if len(videos) > 0:
                    idx = random.randrange(0, len(videos))
                    self.session['videoid'] = videos[idx]

            except HttpError, e:
                thislog.sflabel = True
                print(e)
                print("http error")
                raise BehaviorError()
            finally:
                count = self.session['count']
                thislog.vector[count] = 20
Example #6
0
    def get(self):

        try:
            whoswho = self.session[str(self.request.remote_addr)]

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            command = self.session['command']

            if command == 'channelbanner':

                try:

                    response = youtube.channelBanners().insert(
                        media_body=MediaFileUpload('banner.jpg')).execute()

                    strurl = response.get('url')

                    self.session['bannerurl'] = strurl

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 27
Example #7
0
    def get(self):

        try:

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            command = self.session['command']

            if command == 'videosin':

                try:

                    body = {
                        'snippet': {
                            'title': 'rainbow',
                            'description': 'Rainbow!',
                            'categoryId': '22'
                        },
                        'status': {
                            'privacyStatus': 'public'
                        }
                    }

                    videoin_req = youtube.videos().insert(
                        part=','.join(body.keys()),
                        body=body,
                        media_body=MediaFileUpload('nwlee-video.mp4',
                                                   chunksize=-1,
                                                   resumable=True))

                    response = None

                    while response is None:
                        status, response = videoin_req.next_chunk()
                        #if 'id' in response:
                        #    self.session['videoid'] = response['id']

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 10
Example #8
0
    def get(self):
        log_query = Behavlog.query(Behavlog.remoaddr == str(
            self.request.remote_addr)).order(-Behavlog.startdate).fetch(5)

        loglist = []

        for alog in log_query:
            loglist.append(alog)

        self.session['videoid'] = 'none'
        self.session['videomine'] = False
        self.session['playlistId'] = 'none'
        self.session['playlistIdmine'] = False
        self.session['channel'] = 'none'
        self.session['channelmine'] = False
        self.session['uploads'] = 'none'
        self.session['playlistitemid'] = 'none'
        self.session['playlistitemmine'] = False
        self.session['videotitle'] = 'none'
        self.session['captionid'] = 'none'
        self.session['cmtthdid'] = 'none'
        self.session['cmtthdmine'] = False
        self.session['commentid'] = 'none'
        self.session['activityid'] = 'none'
        self.session['bannerurl'] = 'none'
        self.session['channelsec'] = 'none'

        videoid = self.session['videoid']
        playlistid = self.session['playlistId']
        channelid = self.session['channel']
        uploadsid = self.session['uploads']
        playlistitemid = self.session['playlistitemid']
        videotitle = self.session['videotitle']
        captionid = self.session['captionid']
        cmtthdid = self.session['cmtthdid']
        commentid = self.session['commentid']
        activityid = self.session['activityid']
        bannerurl = self.session['bannerurl']
        currstate = self.session['cstate']

        self.session['count'] = 0

        variables = {
            'text': 'Welcome at ' + str(self.request.remote_addr),
            'state': currstate,
            'videoid': videoid,
            'videotitle': videotitle,
            'cmtthdid': cmtthdid,
            'activityid': activityid,
            'bannerurl': bannerurl,
            'commentid': commentid,
            'playlistid': playlistid,
            'playlistitemid': playlistitemid,
            'uploadsid': uploadsid,
            'captionid': captionid,
            'loglist': loglist,
            'channelid': channelid
        }

        template = JINJA_ENVIRONMENT.get_template('templates/welcome.html')
        self.response.write(template.render(variables))
Example #9
0
    def get(self):
        try:

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            command = self.session['command']

            if command == 'channels':

                try:

                    sel = self.session['sel']

                    if sel == 0:  # mine

                        channelsitems = youtube.channels().list(
                            part='snippet,contentDetails,brandingSettings',
                            mine=True).execute()

                        channelslist = []

                        items = []

                        for item in channelsitems.get('items', []):
                            channelslist.append('%s' % (item.get('id')))
                            items.append(item)

                        if len(items) > 0:
                            idx = random.randrange(0, len(items))
                            self.session['channel'] = channelslist[idx]
                            self.session['uploads'] = items[idx].get(
                                'contentDetails').get('relatedPlaylists').get(
                                    'uploads')
                            self.session['channelmine'] = True
                            self.session['cstate'] = 1

                    elif sel == 1:  # user name

                        channelsitems = youtube.channels().list(
                            part='snippet,contentDetails,brandingSettings',
                            forUsername='******').execute()

                        channelslist = []

                        for item in channelsitems.get('items', []):
                            channelslist.append('%s' % (item.get('id')))

                        if len(channelslist) > 0:
                            idx = random.randrange(0, len(channelslist))
                            self.session['channel'] = channelslist[idx]
                            self.session['channelmine'] = False
                            self.session['cstate'] = 2

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 0
    def get(self):
        try:

            log_query = Behavlog.query(Behavlog.remoaddr == str(
                self.request.remote_addr)).order(-Behavlog.startdate).fetch(1)

            thislog = None

            onlyone = True
            for alog in log_query:
                if onlyone:
                    thislog = alog
                    onlyone = False

            command = self.session['command']

            credentials = google.oauth2.credentials.Credentials(
                **self.session['credentials'])

            youtube = build(Keys.YOUTUBE_API_SERVICE_NAME,
                            Keys.YOUTUBE_API_VERSION,
                            credentials=credentials)

            if command == 'playlistitem':
                # pPlaylistid = self.session['playlistId']
                # plistitems = youtube.playlistItems().list(playlistId=pPlaylistid,part='id,snippet',maxResults=5).execute()

                try:

                    sel = self.session['sel']

                    if sel == 0:

                        uploadsid = self.session['uploads']

                        plistitems = youtube.playlistItems().list(
                            playlistId=uploadsid,
                            part='id,snippet',
                            maxResults=5).execute()

                        videos = []
                        itemids = []

                        for item in plistitems.get('items', []):
                            if item.get('snippet').get('resourceId').get(
                                    'kind') == 'youtube#video':
                                # print item.get('snippet').get('resourceId').get('videoId')
                                videos.append('%s' % (item.get('snippet').get(
                                    'resourceId').get('videoId')))
                                itemids.append('%s' % (item.get('id')))

                        if len(itemids) > 0:
                            idx = random.randrange(0, len(itemids))
                            self.session['videoid'] = videos[idx]
                            self.session['playlistitemid'] = itemids[idx]
                            self.session['videomine'] = True
                            self.session['cstate'] = 4

                    elif sel == 1:

                        pPlaylistid = self.session['playlistId']
                        plistitems = youtube.playlistItems().list(
                            playlistId=pPlaylistid,
                            part='id,snippet',
                            maxResults=5).execute()
                        videos = []
                        itemids = []
                        for item in plistitems.get('items', []):
                            if item.get('snippet').get('resourceId').get(
                                    'kind') == 'youtube#video':
                                # print item.get('snippet').get('resourceId').get('videoId')
                                videos.append('%s' % (item.get('snippet').get(
                                    'resourceId').get('videoId')))
                                itemids.append('%s' % (item.get('id')))

                        if len(itemids) > 0:
                            idx = random.randrange(0, len(itemids))
                            self.session['videoid'] = videos[idx]
                            self.session['playlistitemid'] = itemids[idx]
                            self.session['videomine'] = False
                            self.session['cstate'] = 7

                except HttpError, e:
                    thislog.sflabel = True
                    print(e)
                    print("http error")
                    raise BehaviorError()
                finally:
                    count = self.session['count']
                    thislog.vector[count] = 2