Beispiel #1
0
 def extract_direct_links(self, body, context):
     return (
         (
             match.start(0),
             self.generate_response(self.id_to_url(safe_int(id)), context)
         )
         for match in FFA_LINK_REGEX.finditer(body)
     )
Beispiel #2
0
    def find_link(self, request, context):
        # Find link by ID.
        id = safe_int(request)
        if id is not None:
            return self.id_to_url(id)
        # Filter out direct links.
        match = FFA_LINK_REGEX.match(request)
        if match is not None:
            return request

        return default_cache.search(FFA_SEARCH_QUERY % request)
Beispiel #3
0
    def find_link(self, request, context):
        # Find link by ID.
        id = safe_int(request)
        if id is not None:
            return self.id_to_url(id)
        # Filter out direct links.
        match = FFA_LINK_REGEX.match(request)
        if match is not None:
            return request

        return default_cache.search(FFA_SEARCH_QUERY % request)
Beispiel #4
0
    def find_link(self, request, context):
        # Find link by ID.
        id = safe_int(request)
        if id is not None:
            return self._id_to_link(str(id))


# Filter out direct links.
        match = AO3_LINK_REGEX.match(request)
        if match is not None:
            return request

        return get_default_cache().search(request,
                                          "http://archiveofourown.org/works")
Beispiel #5
0
    def find_link(self, request, context):
        # Find link by ID.
        id = safe_int(request)
        if id is not None:
            return self._id_to_link(str(id))

# Filter out direct links.
        match = AO3_LINK_REGEX.match(request)
        if match is not None:
            return request

        return get_default_cache().search(
            request,
            "http://archiveofourown.org/works"
        )
Beispiel #6
0
    def find_link(self, fic_name, context):
        # Prevent users from crashing program eith bad link names.
        fic_name = fic_name.encode('ascii', errors='replace')
        fic_name = fic_name.decode('ascii', errors='replace')

        # Allow just to post the ID of the fanfiction.
        sid = bot_tools.safe_int(fic_name)
        if sid is not None:
            return self.id_link % sid

# Yield links directly without googling.
        match = self.link_regex.match(fic_name)
        if match is not None:
            return fic_name

        search_request = 'site:www.{1}/s/ {0}'.format(fic_name, self.site)
        return default_cache.search(search_request)
Beispiel #7
0
    def find_link(self, fic_name, context):
        # Prevent users from crashing program with bad link names.
        fic_name = fic_name.encode('ascii', errors='replace')
        fic_name = fic_name.decode('ascii', errors='replace')

        # Allow just to post the ID of the fanfiction.
        sid = bot_tools.safe_int(fic_name)
        if sid is not None:
            return self.id_link % sid

        # Yield links directly without googling.
        match = self.link_regex.match(fic_name)
        if match is not None:
            return fic_name

        search_request = 'site:www.{1}/s/ {0}'.format(fic_name, self.site)
        return default_cache.search(search_request)
Beispiel #8
0
    def find_link(self, fic_name, context):
        # Prevent users from crashing program eith bad link names.
        fic_name = fic_name.encode('ascii', errors='replace')
        fic_name = fic_name.decode('ascii', errors='replace')

        # Allow just to post the ID of the fanfiction.
        sid = bot_tools.safe_int(fic_name)
        if sid is not None:
            return self.id_link % sid

        # Yield links directly without googling.
        match = self.link_regex.match(fic_name)
        if match is not None:
            return fic_name

        return get_default_cache().search(
            fic_name, "http://www." + self.site + "/s/"
        )
Beispiel #9
0
 def extract_direct_links(self, body, context):
     return (self.generate_response(self.id_to_url(safe_int(id)), context)
             for id in FFA_LINK_REGEX.findall(body))
Beispiel #10
0
 def extract_direct_links(self, body, context):
     return (
         self.generate_response(self.id_to_url(safe_int(id)), context)
         for id in FFA_LINK_REGEX.findall(body)
     )
Beispiel #11
0
 def extract_direct_links(self, body, context):
     return ((match.start(0),
              self.generate_response(self.id_to_url(safe_int(id)), context))
             for match in FFA_LINK_REGEX.finditer(body))