Пример #1
0
def test_request(es_cdlc):
    assert_that(list(CustomDLC.search('definitely not here'))).is_empty()

    cdlcs = list(CustomDLC.search('paradise'))
    assert_that(cdlcs).is_length(1)
    assert_that(
        cdlcs[0].full_title).is_equal_to('ZUN - Paradise ~ Deep Mountain')
Пример #2
0
def domains() -> FrozenSet[str]:
    """
    :returns set of domains for all links in the current index.
    """
    return frozenset(
        extract(hit.link).registered_domain
        for hit in CustomDLC.search().scan())
Пример #3
0
def test_loading_from_start(tl):
    with HTTMock(customsforge):
        tl.load()

    assert_that([hit.link for hit in CustomDLC.search().filter('term', from_auto_index=True)]) \
        .is_length(6) \
        .contains_only('magical_link')
Пример #4
0
def test_load_links(tl):
    # this simulates the scenario where link was empty due to error
    CustomDLC(_id=49841).update(direct_download='')

    with HTTMock(customsforge):
        tl.load_links()

    assert_that([hit.link for hit in CustomDLC.search()]) \
        .is_length(6) \
        .contains_only('magical_link')
Пример #5
0
def test_loading_continued(tl):
    # pretend we loaded cdlcs 2 days before TEST_DATE
    for cdlc_id in ['49706', '12990', '49792', '49841']:
        CustomDLC(_id=cdlc_id).update(from_auto_index=True)

    with HTTMock(customsforge):
        tl.load()

    hits = list(CustomDLC.search().filter('term', from_auto_index=True).filter('term', direct_download='magical_link'))
    # the only updated cdlcs are from the last two days (one each), and the latest cdlc before
    assert_that(hits).is_length(3)
Пример #6
0
def test_properties(es_cdlc):
    cdlc = CustomDLC.get(49874)
    assert_that(
        cdlc.full_title).is_equal_to("Trey Parker - Jackin' It In San Diego")
    assert_that(
        cdlc.link).is_equal_to('https://customsforge.com/process.php?id=49874')

    cdlc.update(direct_download='direct_link')

    same_cdlc = list(CustomDLC.search().query('match', id='49874'))
    assert_that(same_cdlc).is_length(1)
    assert_that(same_cdlc[0].link).is_equal_to('direct_link')
Пример #7
0
def find(query: str, results: int = None) -> List[CustomDLC]:
    """
    Searches for matching CDLCs in the index.
    """
    s = CustomDLC.search(query)
    result = list(s[:results] if results else s)
    if not result:
        LOG.warning('No CDLCs matching <%s> were found.', query)

    for hit in result:
        LOG.warning('(%5.2f) Found CDLC#%05d %s: <%s>', hit.meta.score, hit.id,
                    hit, hit.link)

    return result
Пример #8
0
    def read_all(self, start_from: int = 0) -> Iterator[dict]:
        LOG.warning('Loading elastic index CDLCs from %s (%s).', loading_from(start_from), self.__describe_mode())

        timestamp_range = {'gte': start_from} if start_from else {}

        s = CustomDLC.search()
        if self.__continuous:
            s = s.filter('term', from_auto_index=True).sort('snapshot_timestamp').params(preserve_order=True)
            timestamp_range['lte'] = self.start_from()

        if timestamp_range:
            s = s.filter('range', snapshot_timestamp=timestamp_range)

        for hit in s.scan():
            cdlc = hit.to_dict()
            cdlc.pop('from_auto_index', None)
            if self.__continuous:
                cdlc[CONTINUOUS_FROM] = start_from or 0

            yield cdlc
Пример #9
0
    def execute(self, user: User, alias: str, args: str,
                respond: ResponseHook) -> bool:
        """
        Adds any matching songs to the request queue. Query is taken as a literal search string. Can be empty.

        If multiple matches are found, you will be able to use !pick to choose the most relevant ones.

        The following rules do NOT apply to ADMIN rank:
        * If you already had a song in the queue, replaces it instead.
        * If the song is already in the queue, does not add it.
        * If the song has been played already, does not add it.
        """
        matches = list(CustomDLC.search(query=args)[:self.__max_search])
        if not matches:
            return respond.to_sender(f'No matches for <{args}>')

        playable = list(filter(lambda match: match.is_playable, matches))
        if not playable:
            unplayable = '; '.join(match.short for match in matches)
            return respond.to_sender(
                f'Matches for <{args}> not playable: {unplayable}')

        request = Match(user, args, *playable[:self.__max_pick])
        return self._enqueue_request(user, request, respond)
Пример #10
0
def domain_all(domain: str) -> Iterator[str]:
    for hit in CustomDLC.search().scan():
        if extract(hit.link).registered_domain == domain:
            LOG.warning('Found CDLC#%05d <%s>', hit.id, hit)
            yield hit.link