def works_from_links(linkList, reccer): authors = [] works = [] worksSinceSleep = 0 for link in linkList: if worksSinceSleep >= 40: print( 'We have been through {} works since last sleep. Pausing for 2 min so that we do not exceed requests.' .format(worksSinceSleep)) time.sleep(120) if ('/u/' in link) or ('/users/' in link): print( "Author link. Not going to create it because it's a hassle. Uncomment following line to create Authors." ) # authors.append(Author(link)) elif ('/s/' in link) or ('/works/' in link): works.append(Fic(link, reccer)) worksSinceSleep += 1 elif '/series/' in link: print('Link is to a series, trying to access series parts now') seriesworks = get_works_from_series( link.partition('/series/')[2], reccer) works.extend(seriesworks) worksSinceSleep += len(seriesworks) else: print('{} is an invalid link'.format(link)) return works
def get_works_from_bookmarks(username, mine=False, works_not_bookmarks=False): ''' Returns list of Works, one per bookmark ''' if mine: pw = str(input("Please input password: "******"starrybouquet", pw) bookmarks = session.get_bookmarks() elif works_not_bookmarks: author = AO3.User(username) bookmarks = author.get_works() else: reader = Reader(username) bookmarks = reader.get_bookmarks() bookmarked_works = [] broken_ids = [] for work in bookmarks: if len(bookmarked_works) % 20 == 0 and len(bookmarked_works) != 0: print('Pausing for 2 min; we have been through {} bookmarks'.format(len(bookmarked_works))) time.sleep(120) try: work.reload() try: if work.fandoms[0] == "Stargate SG-1": bookmarked_works.append(Fic(work.url, username, existingAO3Work=work)) print('Added work {}'.format(work.title)) except: broken_ids.append("{0} (id {1})".format(work.title, work.workid)) print("Work had no fandom, id was {}".format(work.workid)) except: broken_ids.append(work.workid) print("Work was restricted, skipping. Work id was {}".format(work.workid)) return bookmarked_works, broken_ids
def get_works_from_series(seriesid, reccer): '''get list of works of my Work class given an ao3 series id''' series = AO3.Series(seriesid) seriesparts = [] for work in series.work_list: work.reload() seriesparts.append(Fic(work.url, reccer, existingAO3Work=work)) return seriesparts
def single_work_from_link(link, reccer): '''Get single work from link given. Parameters ---------- link : str Returns ------- int, work Work Work (or multiple if the link was a series) int equal to number of works retrieved If the link was invalid/was an author, returns int, None ''' if ('/u/' in link) or ('/users/' in link): print("Author link. Not going to create it because it's a hassle. Uncomment following line to create Authors.") # authors.append(Author(link)) return 0, None elif ('/s/' in link) or ('/works/' in link): print("Actual fic, creating work...") work = Fic(link, reccer) numWorksRetrieved = 1 return numWorksRetrieved, [work] elif '/series/' in link: print('Link is to a series, trying to access series parts now') seriesworks = get_works_from_series(link.partition('/series/')[2], reccer) numWorksRetrieved = len(seriesworks) return numWorksRetrieved, seriesworks else: manual = str(input('{} is an invalid link. Do you want to manually enter info? (y or n): '.format(link))) if manual == 'y': title = str(input("Title: ")) author = str(input("Author: ")) desc = str(input("Summary: ")) work = Fic(link, reccer, manualEntry=True, title=title, author=author, desc=desc) numWorksRetrieved = 1 return numWorksRetrieved, [work] else: return 0, None
def get_faves_from_user(user_url, reccer): author = ffnet.User(url=user_url) author.download_data() favorite_works = [] for story in author.favorite_stories: # story.download_data() if len(favorite_works) % 100 == 0 and len(favorite_works) != 0: print('Pausing for 2 min; we have been through {} stories'.format(len(favorite_works))) time.sleep(120) if 'Stargate: SG-1' in story.fandoms: print('Found SG-1 story {}'.format(story.title)) favorite_works.append(Fic('', reccer, existingFFNStory=story)) return favorite_works
def get_works_from_bookmarks(mine=True): ''' Returns list of Works, one per bookmark ''' if mine: pw = str(input("Please input password: "******"starrybouquet", pw) bookmarks = session.get_bookmarks() bookmarked_works = [] for work in bookmarks: print(type(work)) work.reload() if work.fandoms[0] == "Stargate SG-1": bookmarked_works.append( Fic(work.url, 'starrybouquet', existingAO3Work=work)) return bookmarked_works