Exemplo n.º 1
0
def __url_to_seriesref(url_s):
   ''' 
   Converts a ComicVine URL into a SeriesRef.  The URL has to contain
   a magic number of the form 4050-XXXXXXXX (a series) or 4000-XXXXXXXX
   (an issue.)   If the given URL has a usable magic number, use it to query
   the db and construct a SeriesRef for the series associated with that 
   number.  Returns none if the url couldn't be converted, for any reason. 
   '''
   series_ref = None
   
   # 1. try interpreting the url as a comicvine issue (i.e. 4000-XXXXXXXX)
   if not series_ref:
      url_s = url_s.strip()
      pattern=r"^.*?\b(4000)-(?<num>\d{2,})\b.*$"
         
      match = re.match(pattern, url_s, re.I)
      if match:
         issueid_s = match.group("num")
         try:
            dom = cvconnection._query_issue_details_dom( __api_key, issueid_s)
            num_results_n = int(dom.number_of_total_results)
            if num_results_n == 1:
               # convert url into the series id for this issue
               url_s = "4050-"+dom.results.volume.id
         except:
            pass # happens when the user enters an non-existent key

   # 2. now try interpreting the url as a comicvine series (4050-XXXXXX) 
   if not series_ref:
      url_s = url_s.strip()
      pattern=r"^.*?\b(49|4050)-(?<num>\d{2,})\b.*$"
         
      match = re.match(pattern, url_s, re.I)
      if match:
         seriesid_s = match.group("num")
         try:
            dom = cvconnection._query_series_details_dom(__api_key, seriesid_s)
            num_results_n = int(dom.number_of_total_results)
            if num_results_n == 1:
               series_ref = __volume_to_seriesref(dom.results)
         except:
            pass # happens when the user enters an non-existent key

   return series_ref
Exemplo n.º 2
0
def _query_issue(issue_ref, slow_data):
    """ ComicVine implementation of the identically named method in the db.py """

    # interesting: can we implement a cache here?  could speed things up...
    issue = Issue(issue_ref)

    dom = cvconnection._query_issue_details_dom(__api_key, sstr(issue_ref.issue_key))
    __issue_parse_simple_stuff(issue, dom)
    __issue_parse_series_details(issue, dom)
    __issue_parse_story_credits(issue, dom)
    __issue_parse_summary(issue, dom)
    __issue_parse_roles(issue, dom)

    if slow_data:
        # grab extra cover images and a community rating score
        page = cvconnection._query_issue_details_page(__api_key, sstr(issue_ref.issue_key))
        __issue_scrape_extra_details(issue, page)

    return issue
Exemplo n.º 3
0
def _query_issue(issue_ref, slow_data):
   ''' ComicVine implementation of the identically named method in the db.py '''
   
   del slow_data; # unused 

   # interesting: can we implement a cache here?  could speed things up...
   issue = Issue(issue_ref)
   
   dom = cvconnection._query_issue_details_dom(
            __api_key, sstr(issue_ref.issue_key))
   __issue_parse_simple_stuff(issue, dom)
   __issue_parse_series_details(issue, dom)
   __issue_parse_story_credits(issue, dom)
   __issue_parse_summary(issue, dom)
   __issue_parse_roles(issue, dom)
   
   
   #    the commented code below once scraped additional cover images and 
   #    the community rating from Comic Vine directly. it did this by reading 
   #    in the contents of an html page on the Comic Vine website, rather
   #    than using part of the Comic Vine API.   This is against Comic 
   #    Vine's acceptable use policy (see issue 421, 
   #        https://github.com/cbanack/comic-vine-scraper/issues/421 )
   #
   #    I have removed this code to address this issue, but if Comic Vine
   #    ever gives us the option to access additional cover art or community
   #    ratings directly, the code below could be rewritten to get those details
   #    again, and then the features that rely on it will start using that data
   #    and working as they used to (the features affected are:  scraping
   #    community rating, auto-identification of comic series, and searching
   #    for additional covers for a particular issue.) 
   
   #if slow_data:
      # grab extra cover images and a community rating score
   #   page = cvconnection._query_issue_details_page(
   #             __api_key, sstr(issue_ref.issue_key))
   #   __issue_scrape_extra_details( issue, page )
   
   return issue
Exemplo n.º 4
0
def _query_issue(issue_ref, slow_data):
   ''' ComicVine implementation of the identically named method in the db.py '''
   
   del slow_data; # unused 

   # interesting: can we implement a cache here?  could speed things up...
   issue = Issue(issue_ref)
   
   dom = cvconnection._query_issue_details_dom(
            __api_key, sstr(issue_ref.issue_key))
   __issue_parse_simple_stuff(issue, dom)
   __issue_parse_series_details(issue, dom)
   __issue_parse_story_credits(issue, dom)
   __issue_parse_summary(issue, dom)
   __issue_parse_roles(issue, dom)
   
   
   #    the commented code below once scraped additional cover images and 
   #    the community rating from Comic Vine directly. it did this by reading 
   #    in the contents of an html page on the Comic Vine website, rather
   #    than using part of the Comic Vine API.   This is against Comic 
   #    Vine's acceptable use policy (see issue 421, 
   #        https://github.com/cbanack/comic-vine-scraper/issues/421 )
   #
   #    I have removed this code to address this issue, but if Comic Vine
   #    ever gives us the option to access additional cover art or community
   #    ratings directly, the code below could be rewritten to get those details
   #    again, and then the features that rely on it will start using that data
   #    and working as they used to (the features affected are:  scraping
   #    community rating, auto-identification of comic series, and searching
   #    for additional covers for a particular issue.) 
   
   #if slow_data:
      # grab extra cover images and a community rating score
   #   page = cvconnection._query_issue_details_page(
   #             __api_key, sstr(issue_ref.issue_key))
   #   __issue_scrape_extra_details( issue, page )
   
   return issue