def test_papers_from_embedded_script(mock_get):
    mock_get.return_value = MockResponse()

    papers = papers_from_embedded_script("http://www.arxiv-sanity.com/")

    assert papers is not None
    assert len(papers) is 200
    assert papers[0]['title'] == 'Efficient Action Detection in Untrimmed Videos via Multi-Task Learning'
Beispiel #2
0
 def get_similar(self, pid):
     """ Get papers similar in content to the named paper. """
     logging.info("Getting ArXiv papers similar to paper: {}".format(pid))
     similarURL = ASP_BaseURL + str(pid)
     similar_papers = papers_from_embedded_script(similarURL)[1:] # TODO is the searched paper always first?
     attached_papers = []
     for p in similar_papers:
         attached_papers.append(paper_snippet(p))
     return build_message(text="*Your Library*", markdown=False, parts=attached_papers)
Beispiel #3
0
 def get_recommended(self, session):
     """ Get the papers recommended to the user based on their
     saved papers and their search domain. """
     # TODO the /recommend endpoint has FILTERS
     logging.info("Getting recommended ArXiv papers for user.")
     recommendedURL = ASP_BaseURL + "/recommend"
     papers = papers_from_embedded_script(recommendedURL, session)
     attached_papers = []
     for i, p in enumerate(papers):
         attached_papers.append(paper_snippet(p, i + 1))
     return build_message( text="*Your Recommended*", markdown=False, parts=attached_papers), attached_papers[:5]
Beispiel #4
0
 def get_paper(self, paper_id):
     """ Return specified paper from within the set. """
     if not self.previous_attachments:
         logging.info("Can't retreive paper. No papers in current context.")
         return build_message(text="*Can't retreive paper*"), None
     else:
         pid = re.findall('[0-9]+\.?[0-9]*', self.previous_attachments[paper_id - 1]['text'])[0]
         logging.info("Getting paper: {} from ArXiv.".format(pid))
     paperURL = ASP_BaseURL + "/" + str(pid)
     paper = papers_from_embedded_script(paperURL)[0] # only get first, rest are related papers
     return build_message(text="*Here's your paper*", markdown=False, parts=None), [paper_snippet(paper, 1, include_abstract=True)]
Beispiel #5
0
    def get_most_recent(self, session):
        """ Get most recently published papers within the user's search
        domain.
        """
        logging.info("Getting most recent ArXiv papers within user's domain.")
        papers = papers_from_embedded_script(ASP_BaseURL+"/", session)
        attached_papers = []
        for i, p in enumerate(papers):
            attached_papers.append(paper_snippet(p, i + 1))

        return build_message( text="*Your Most Recent*", markdown=False, parts=attached_papers), attached_papers[:5]
Beispiel #6
0
 def clear_library(self, session):
     """ Remove all saved paper's from the users library. """
     logging.info("Clearing ArXiv library.")
     libraryURL = ASP_BaseURL + "/library"
     papers = papers_from_embedded_script(libraryURL)
     toggleURL = ASP_BaseURL + "/libtoggle"
     for p in papers:
         # toggle off each paper from library
         r = session.post(toggleURL, data = {'pid':p["pid"]})
         if r.status_code != 200:
             # TODO log error. pass up to user?
             pass
Beispiel #7
0
 def get_top_recent(self, session):
     """
     Get the 'top' recent papers within the user's search domain.
     """
     # TODO the /top endpoint has FILTERS
     logging.info("Getting top recent ArXiv papers in user's domain.")
     topURL = ASP_BaseURL + "/top" # default filters
     papers = papers_from_embedded_script(topURL, session=session)
     attached_papers = []
     for i, p in enumerate(papers):
         attached_papers.append(paper_snippet(p, i + 1))
     return build_message( text="*Your Library*", markdown=False, parts=attached_papers), attached_papers[:5]
Beispiel #8
0
    def get_library(self, session):
        """ Get all papers saved by the user. Their 'library'. """
        logging.info("Getting ArXiv library.")
        libraryURL = ASP_BaseURL + "/library"
        try:
            papers = papers_from_embedded_script(libraryURL, session=session)
        except ReadTimeout:
            return build_message( text="*Connection Problem. Please try again*", markdown=False, parts=None)

        attached_papers = []
        for i, p in enumerate(papers):
            attached_papers.append(paper_snippet(p, i + 1))
        return build_message( text="*Your Library*", markdown=False, parts=attached_papers), attached_papers
Beispiel #9
0
    def search_arxiv(self, query, num_papers=5):
        """ Search arxiv papers by search string. """
        logging.info("Searching ArXiv for: {}".format(query))
        tokens = query.split(' ')
        searchEndpoint = 'search?q=' + '+'.join(tokens)
        searchURL = ASP_BaseURL + searchEndpoint
        papers = papers_from_embedded_script(searchURL)
        bot_uid = self.clients.bot_user_id()
        attached_papers = []
        # For each paper
        for i in range(min(num_papers,len(papers))):
            attached_papers.append(paper_snippet(papers[i], i + 1))

        attached_papers[-1]['footer'] = "> `<@" + bot_uid + "> show more papers` - to see more papers"
        # build the json message object

        return build_message( text="*Search Results*", markdown=False, parts=attached_papers), attached_papers