def createSearchURL(self): if self.searchParams == {}: print("ERROR: empty searchParams field!") # fetch the date try: d = self.searchParams['date'] tmp = convert.convertToAO3(d, 'within', False) d = tmp[0] except: dummy = '' # fetch the category(ies) c = '' try: c = self.searchParams['category'] tmp = convert.convertToAO3(c, 'cat', False) c = tmp[0] except: dummy = '' #print "no category in searchParams: ", self.searchParams # fetch the warning(s) w = '' try: w = self.searchParams['warning'] tmp = convert.convertToAO3(w, 'warn', False) w = tmp[0] except: dummy = '' #print "no warning in searchParams ", self.searchParams # fetch the tag(s) t = unicode('&tag_id=') try: tag = self.searchParams['tag'] tmp = convert.convertToAO3(tag, 'tag', False) t += unicode(tmp[0]) except: dummy = '' #print "no tag in searchParams ", self.searchParams # fetch the "search within results" swr = '&work_search%5Bquery%5D=' try: within = self.searchresults['search within results'] tmp = convert.convertToAO3(within, 'within', False) swr += tmp[0] except: dummy = '' #print "no search within results in searchParams ", self.searchParams # assemble the URL urlprefix = 'http://archiveofourown.org/works?utf8=%E2%9C%93&commit=Sort+and+Filter&work_search%5Bsort_column%5D=revised_at' urlprequery = '&work_search%5Bother_tag_names%5D=' urlpredate = '&work_search%5Brevised_at%5D=' urlpretag = '&work_search%5Blanguage_id%5D=&work_search%5Bcomplete%5D=0' tmp = unicode(urlprefix + c + w + urlpredate + d + urlprequery + swr + urlpretag + t) self.searchURL = tmp.encode('utf-8')
def createUnsortedSearchURL(self): if self.searchParams == {}: print("ERROR: empty searchParams field!") # fetch the date d = '' try: d = self.searchParams['date'] tmp = convert.convertToAO3(d, 'unsorted', False) d = tmp[0] except: dummy = '' # fetch the fandom(s) fan = '' try: fan = self.searchParams['fandom'] tmp = convert.convertToAO3(fan, 'unsorted', False) fan = tmp[0] # also replace the original version of the fandom tag with the new version # to remove any commas in the CSV outfile self.searchParams['fandom'] = fan except: dummy = '' # fetch the freeform tag(s) free = '' try: free = self.searchParams['freeform'] tmp = convert.convertToAO3(free, 'unsorted', False) free = tmp[0] # also replace the original version of the freeform tag with the new version # to remove any commas in the CSV outfile self.searchParams['freeform'] = free except: dummy = '' print d print fan print free # assemble the URL urlpredate = 'http://archiveofourown.org/works/search?utf8=%E2%9C%93&work_search%5Bquery%5D=&work_search%5Btitle%5D=&work_search%5Bcreator%5D=&work_search%5Brevised_at%5D=' urlprefandom = '&work_search%5Bcomplete%5D=0&work_search%5Bsingle_chapter%5D=0&work_search%5Bword_count%5D=&work_search%5Blanguage_id%5D=&work_search%5Bfandom_names%5D=' urlprefreeform = '&work_search%5Brating_ids%5D=&work_search%5Bcharacter_names%5D=&work_search%5Brelationship_names%5D=&work_search%5Bfreeform_names%5D=' urlsuffix = '&work_search%5Bhits%5D=&work_search%5Bkudos_count%5D=&work_search%5Bcomments_count%5D=&work_search%5Bbookmarks_count%5D=&work_search%5Bsort_column%5D=&work_search%5Bsort_direction%5D=&commit=Search' tmp = unicode(urlpredate + d + urlprefandom + fan + urlprefreeform + free + urlsuffix) self.searchURL = tmp.encode('utf-8')
def createUnsortedSearchURL(self): if self.searchParams == {}: print("ERROR: empty searchParams field!") # fetch the date try: d = self.searchParams['date'] tmp = convert.convertToAO3(d, 'unsorted', False) d = tmp[0] except: dummy = '' # fetch the fandom(s) fan = '' try: fan = self.searchParams['fandom'] tmp = convert.convertToAO3(fan, 'unsorted', False) fan = tmp[0] # also replace the original version of the fandom tag with the new version # to remove any commas in the CSV outfile self.searchParams['fandom'] = fan except: dummy = '' # fetch the freeform tag(s) free = '' try: free = self.searchParams['freeform'] tmp = convert.convertToAO3(free, 'unsorted', False) free = tmp[0] # also replace the original version of the freeform tag with the new version # to remove any commas in the CSV outfile self.searchParams['freeform'] = free except: dummy = '' print d print fan print free # assemble the URL urlpredate = 'http://archiveofourown.org/works/search?utf8=%E2%9C%93&work_search%5Bquery%5D=&work_search%5Btitle%5D=&work_search%5Bcreator%5D=&work_search%5Brevised_at%5D=' urlprefandom = '&work_search%5Bcomplete%5D=0&work_search%5Bsingle_chapter%5D=0&work_search%5Bword_count%5D=&work_search%5Blanguage_id%5D=&work_search%5Bfandom_names%5D=' urlprefreeform = '&work_search%5Brating_ids%5D=&work_search%5Bcharacter_names%5D=&work_search%5Brelationship_names%5D=&work_search%5Bfreeform_names%5D=' urlsuffix = '&work_search%5Bhits%5D=&work_search%5Bkudos_count%5D=&work_search%5Bcomments_count%5D=&work_search%5Bbookmarks_count%5D=&work_search%5Bsort_column%5D=&work_search%5Bsort_direction%5D=&commit=Search' tmp = unicode(urlpredate + d + urlprefandom + fan + urlprefreeform + free + urlsuffix) self.searchURL = tmp.encode('utf-8')
def getAO3SearchURL(tag, includeTags, excludeTags): url = "https://archiveofourown.org/works?utf8=%E2%9C%93&commit=Sort+and+Filter&work_search%5Bsort_column%5D=revised_at&work_search%5Bother_tag_names%5D=" url = addListOfTags(url, includeTags) url += "&work_search%5Bexcluded_tag_names%5D=" url = addListOfTags(url, excludeTags) ao3tag = convertToAO3(tag, "tag", False) url = url + "&work_search%5Bcrossover%5D=&work_search%5Bcomplete%5D=&work_search%5Bwords_from%5D=&work_search%5Bwords_to%5D=&work_search%5Bdate_from%5D=&work_search%5Bdate_to%5D=&work_search%5Bquery%5D=&work_search%5Blanguage_id%5D=&tag_id=" + ao3tag[ 0] return url
def addListOfTags(url, tagList): processedTags = [] for tag in tagList: ao3tag = convertToAO3(tag, "unsorted", False) url += ao3tag[0] processedTags.append(tag) if len(processedTags) < len(tagList): url += "%2C" return url
def getAO3LanguageTimeframeURL(langCode, timeframeString, singleChapterOnly): url = "https://archiveofourown.org/works/search?utf8=%E2%9C%93&commit=Search&work_search%5Bquery%5D=&work_search%5Btitle%5D=&work_search%5Bcreators%5D=&work_search%5Brevised_at%5D=" timeframeString, tmp = convertToAO3(timeframeString, "unsorted", False) url += timeframeString url += "&work_search%5Bcomplete%5D=&work_search%5Bcrossover%5D=&work_search%5Bsingle_chapter%5D=" if singleChapterOnly: url += "1" url += "&work_search%5Bword_count%5D=&work_search%5Blanguage_id%5D=" url += langCode url += "&work_search%5Bfandom_names%5D=&work_search%5Brating_ids%5D=&work_search%5Bcharacter_names%5D=&work_search%5Brelationship_names%5D=&work_search%5Bfreeform_names%5D=&work_search%5Bhits%5D=&work_search%5Bkudos_count%5D=&work_search%5Bcomments_count%5D=&work_search%5Bbookmarks_count%5D=&work_search%5Bsort_column%5D=_score&work_search%5Bsort_direction%5D=desc" return url
try: searches = j['searches'] except: sys.exit("No 'searches' field in file") for s in searches: if verbose: print "search: ", s params = '' # fetch the category(ies) c = '' try: c = s['category'] tmp = convert.convertToAO3(c, 'cat', verbose) c = tmp[0] params += tmp[1] params += ', ' if verbose: print "category: ", c print "params ", params except: if verbose: print "no category in search ", s # fetch the warning(s) w = '' try: w = s['warning'] tmp = convert.convertToAO3(w, 'warn', verbose)
def getAO3TagStructureURL(tag): formattedTag = convertToAO3(tag, "tag", False) return ("https://archiveofourown.org/tags/" + formattedTag[0] + "/")
def createSearchURL(self): if self.searchParams == {}: print("ERROR: empty searchParams field!") # fetch the date d = '' try: d = self.searchParams['date'] tmp = convert.convertToAO3(d, 'within', False) d = tmp[0] except: dummy = '' # fetch the category(ies) c = '' try: c = self.searchParams['category'] tmp = convert.convertToAO3(c, 'cat', False) c = tmp[0] except: dummy = '' #print "no category in searchParams: ", self.searchParams # fetch the warning(s) w = '' try: w = self.searchParams['warning'] tmp = convert.convertToAO3(w, 'warn', False) w = tmp[0] except: dummy = '' #print "no warning in searchParams ", self.searchParams # fetch the tag(s) t = unicode('&tag_id=') try: tag = self.searchParams['tag'] tmp = convert.convertToAO3(tag, 'tag', False) t += unicode(tmp[0]) except: dummy = '' #print "no tag in searchParams ", self.searchParams # fetch the "search within results" swr = '&work_search%5Bquery%5D=' try: within = self.searchresults['search within results'] tmp = convert.convertToAO3(within, 'within', False) swr += tmp[0] except: dummy = '' #print "no search within results in searchParams ", self.searchParams # assemble the URL urlprefix = 'http://archiveofourown.org/works?utf8=%E2%9C%93&commit=Sort+and+Filter&work_search%5Bsort_column%5D=revised_at' urlprequery = '&work_search%5Bother_tag_names%5D=' urlpredate = '&work_search%5Brevised_at%5D=' urlpretag = '&work_search%5Blanguage_id%5D=&work_search%5Bcomplete%5D=0' tmp = unicode(urlprefix + c + w + urlpredate + d + urlprequery + swr + urlpretag + t) self.searchURL = tmp.encode('utf-8')
def getAO3SimpleTagURL(tag): formattedTag = convertToAO3(tag, "tag", False) return("https://archiveofourown.org/tags/" + formattedTag[0] + "/works")