def start_end_test():
    test_urls = [
        ((0, None), 'http://youtube.com/watch?v=iwGFalTRHDA'),
        ((0, None),
         'http://www.youtube.com/watch?v=iwGFalTRHDA&feature=related'),
        ((0, None), 'https://youtube.com/iwGFalTRHDA'),
        ((0, None), 'http://youtu.be/n17B_uFF4cA'),
        ((0, None), 'youtube.com/iwGFalTRHDA'),
        ((0, None), 'youtube.com/n17B_uFF4cA'),
        ((0, None),
         'http://www.youtube.com/embed/watch?feature=player_embedded&v=r5nB9u4jjy4'
         ), ((0, None), 'http://www.youtube.com/watch?v=t-ZRX8984sc'),
        ((0, None), 'http://youtu.be/t-ZRX8984sc'),
        ((2, 32), 'https://www.youtube.com/embed/PnMfNyu7UIw?end=32&start=2'),
        ((3655, None),
         'https://www.youtube.com/watch?v=LCTYRqW-ne8&feature=youtu.be&t=1h55s'
         ),
        ((3600, None),
         'https://www.youtube.com/watch?v=LCTYRqW-ne8&feature=youtu.be&t=1h55'
         ), ((3340, None), 'https://youtu.be/LCTYRqW-ne8?t=3340')
    ]
    for ((start, end), url) in test_urls:
        try:
            # print("start, end: (" + str(start) + ", " + str(end) + ")")
            # print("url: " + url)

            got_start, got_end = utils.get_start_end(url)

            # print("get_start_end(): (" + str(got_start) + ", " + str(got_end) + ")")

            assert start == got_start
            assert end == got_end
        # if start == got_start and end == got_end:
        #     print("same")
        #     #print("IDs are same: " + id + " " + get_id(url))
        # else:
        #     print("different")
        #     #print("IDs are different: " + id + " " + get_id(url))
        # print()
        except:
            print(
                "An error occured. start: %s, end: %s, url: %s. \nContinuing..."
                % (got_start, got_end, url))
            continue

    print("All timestamp tests passed")
Beispiel #2
0
def test_search(board, search_func, only_stats=False):
    se = get_start_end(board)
    t0 = t()
    path = search_func(board, *se)
    dt = t() - t0
    board[se[0][0]][se[0][1]] = str2n['#']
    board[se[1][0]][se[1][1]] = str2n['$']

    ret = {'dt': dt,
           'touched': how_many(board, lambda x: x in (.2, .4, 1)),
           'visited': how_many(board, lambda x: x in (.4, 1)),
           'len': None, 'weight': None, 'path': None}

    if path:
        ret.update(len=len(path), weight=weight(path))
        if not only_stats:
            ret.update(path=path)

    return ret
    def fetch_vid_info(self,
                       period="month",
                       time_limit=datetime.timedelta.max,
                       max_vids=50,
                       min_score=0):
        """
        Args:
            period (str): "week", "month", "year", "all time"
            time_limit (timedelta): time limit for a given compilation
            max_vids (int): max number of vids for a given compilation
            min_score (int): min # of upvotes to get into the compilation
        Returns:
            vid_info (VidInfo[]): each element contains info about video:
                (submission, title, channel, duration, start, end)
            total_duration (timedelta): sum of videos' lengths
        """

        vid_info = []
        total_duration = datetime.timedelta(seconds=0)
        ctr = 0
        for submission in self.reddit.subreddit("youtubehaiku").top(period):
            if (ctr >= max_vids):
                break
            try:
                vid_id = utils.get_yt_id(submission.url)

                # To make sure that link isn't broken
                request = self.youtube.videos().list(
                    part="ContentDetails, snippet", id=vid_id)
                response = request.execute()

                # if 'items' is empty, no vid data was retrievable => don't want in list
                assert len(response['items']) != 0

                # parse url to see if it contains start & end information
                start, end = utils.get_start_end(submission.url)
                start = int(start)
                start_td = datetime.timedelta(seconds=start)
                # `end` will either be returned as None or int of seconds
                if end is not None:
                    end = int(end)
                    duration_timedelta = datetime.timedelta(
                        seconds=end) - start_td
                else:
                    duration_str = response['items'][0]['contentDetails'][
                        'duration']
                    duration_timedelta = isodate.parse_duration(
                        duration_str) - start_td

                # if we reach a max duration or min score, we end the for loop
                if (total_duration + duration_timedelta >
                        time_limit) or (submission.score < min_score):
                    break

                title = response['items'][0]['snippet']['title']
                channel = response['items'][0]['snippet']['channelTitle']

                vid_info.append(
                    VidInfo(submission, title, channel, duration_timedelta,
                            start, end))
                total_duration += duration_timedelta
                ctr += 1

            except Exception as e:
                print("Error with post: ", e)
                print("Post title: '%s'. \nPost url: %s" %
                      (submission.title, submission.url))
                if "quota" in str(e):
                    exit(0)
                print("Continuing...")

        return (vid_info, total_duration)
Beispiel #4
0
    for thread in threads_list:
        thread.start()

    for thread in threads_list:
        thread.join()

    for service in scanned_services:
        print(service)

    print(f'Scanned in {round(time() - start_time, 2)} seconds')


threads = int(argv[1])
diapason = argv[2]
diapason_start, diapason_end = utils.get_start_end(diapason)
nmap_args = ['nmap'] + argv[3:]
scanned_services = []

diapason_start_int10 = int.from_bytes(utils.ip_to_hex(diapason_start), 'big')
diapason_end_int10 = int.from_bytes(utils.ip_to_hex(diapason_end), 'big')

addresses_amount = diapason_end_int10 - diapason_start_int10 + 1
threads_list = []
lock = Lock()

start_time = time()
CMD_ENCODING = '866'

if __name__ == '__main__':
    main()
Beispiel #5
0
ins = tables.Person.insert()
values = []
for person in data['persons']:
    dob = utils.get_dob(1980, 2010)
    values.append({'name': person, 'date_of_birth': dob})

with engine.begin() as conn:
    conn.execute(ins, values)

ins = tables.Write.insert()
with engine.begin() as conn:
    for ind, _ in enumerate(data['books']):
        writers = utils.get_people_in_range([5, 10])
        writing_start_end = utils.get_start_end([datetime.datetime(2015, 1, 1),
                                                 datetime.datetime(2015, 6, 30)],
                                                [datetime.datetime(2017, 7, 1),
                                                 datetime.datetime(2017, 12, 31)])
        seshes = utils.get_sessions(writing_start_end[0], writing_start_end[1], [30, 50], 0.25)
        writer_sessions = utils.get_writer_sessions(len(seshes), writers)
        values = []
        for sesh, writer in zip(seshes, writer_sessions):
            values.append({'book_id': ind + 1, 'person_id': writer, 'start_time': sesh[0],
                           'end_time': sesh[1], 'finished': False})
        values[-1]['finished'] = utils.get_finished(90)
        conn.execute(ins, values)

s = select([tables.Write.c.book_id, func.min(tables.Write.c.end_time)])\
    .group_by(tables.Write.c.book_id)
with engine.begin() as conn:
    books_available = conn.execute(s).fetchall()
    def get_criteria(self):
        ''' combine request with topic criteria '''
        criteria = []
        portal_atct = getToolByName(self.context,'portal_atct')
        for criterion in self.topic.listCriteria():
            if criterion.meta_type in ['ATSimpleStringCriterion',
                'ATSelectionCriterion', 'ATListCriterion',
                'ATDateRangeCriterion', 'ATFriendlyDateCriteria']:
                index = portal_atct.getIndex(criterion.Field())
                criterion_field = {'id': criterion.id,
                    'description': index.description,
                    'label': index.friendlyName,
                    'field': criterion.Field(),
                    'type': criterion.meta_type,
                    }
                if criterion.meta_type=='ATSimpleStringCriterion':
                    value = self.request.get(criterion.Field(),'')
                    criterion_field['input'] = u'''<input type="text"
                            size="25"
                            name="%s"
                            id="search-%s"
                            value="%s"/>''' % (criterion.Field(),
                                criterion.Field(), value)
                elif criterion.meta_type in ['ATSelectionCriterion',
                                            'ATListCriterion']:
                    options = u''
                    if criterion.Value():
                        if len(criterion.Value()) ==1:
                            continue
                        selected = self.request.get(criterion.Field(),None)
                        if criterion.getOperator()=='or':
                            # we let the user choose from the selected
                            # values
                            if selected:
                                options = u'<option value="">All</option>'
                            else:
                                options = u'<option selected="selected" value="">All</option>'
                            idx_values = list(criterion.Value())
                            idx_values.sort()
                            for idx_value in idx_values:
                                if idx_value.find(KEYWORD_DELIMITER) > 0:
                                    idx_name=idx_value.split(KEYWORD_DELIMITER)[1]
                                else:
                                    idx_name=idx_value
                                is_selected = self._sel(idx_value,selected)
                                options += u'<option value="%(value)s" %(selected)s >%(name)s</option>' % {
                                    'value': idx_value,
                                    'selected': is_selected,
                                    'name': idx_name}
                            criterion_field['input'] = u'''
                                    <select id="%s" name="%s">
                                    %s
                                    </select>''' % ( criterion.Field(),
                                        criterion.Field(), options)

                        else:
                            # we let the user choose from all possible
                            # values minus the selected ones (as they will
                            # be added (AND) to the search anyway)
                            idx_values = self._get_index_values(criterion.Field())
                            for idx_value in idx_values:
                                if idx_value['value'] in criterion.Value():
                                    continue
                                else:
                                    options += u'<option value="%(value)s" %(selected)s >%(name)s</option>' % idx_value
                            criterion_field['input'] = u'''
                                <select id="%s" name="%s">
                                %s
                                </select>''' % ( criterion.Field(),
                                    criterion.Field(), options)
                    else:
                        # if nothing is selected to search we assume
                        # that we should present a selection with all
                        # posible values
                        idx_values = self._get_index_values(criterion.Field())
                        for idx_value in idx_values:
                            options += u'<option value="%(value)s" %(selected)s >%(name)s</option>' % idx_value
                        criterion_field['input'] = u'''
                            <select id="%s" name="%s">
                            %s
                            </select>''' % ( criterion.Field(),
                                criterion.Field(), options)
                elif criterion.meta_type in ['ATDateRangeCriterion',
                                            'ATFriendlyDateCriteria']:
                    # convert freindly date criteria into date ranges
                    # so we can display a slider to drill down inside
                    # the range
                    start_date, end_date = get_start_end(self, criterion,
                                                self.portal_catalog)
                    startval = self.request.get('start-' + criterion.Field(),
                            start_date.strftime('%Y/%m/%d'))
                    endval = self.request.get('end-' + criterion.Field(),
                            end_date.strftime('%Y/%m/%d'))

                    criterion_field['input'] = self._daterange_criterion(
                        criterion.Field(), start_date, startval,
                        end_date, endval)

                    #criterion_field['input'] = daterange_criterion(criterion)
                else:
                    criterion_field['input'] = None
                criteria.append(criterion_field)
        return criteria