def copy_to_temp_db(self, has_coauthors=None): efiction_db = self.efiction_original_database temp_db = self.args.temp_db_database coauthors = {} table_names = self.table_names() if has_coauthors is None: has_coauthor_table = raw_input( "\nDoes this archive have a coauthors table? Y/N\n") has_coauthors = True if str.lower( has_coauthor_table) == 'y' else False else: has_coauthors = has_coauthors if has_coauthors: coauthors_dict = self.sql.execute_dict( "SELECT * FROM fanfiction_coauthors") for coauthor in coauthors_dict: coauthors[coauthor['sid']] = coauthor['uid'] # Create Open Doors tables in temp db self.sql.run_script_from_file(os.path.join( os.path.dirname(__file__), '../shared_python/create-open-doors-tables.sql'), database=temp_db) # Export data to Open Doors tables final = FinalTables(self.args, self.sql.db, self.log) stories_without_tags = final.original_table(table_names['stories'], database_name=efiction_db) self.log.info("Stories without tags in original eFiction: {0}".format( len(stories_without_tags))) chapters = final.original_table(table_names['chapters'], database_name=efiction_db) self.log.info("Chapters in original eFiction: {0}".format( len(chapters))) # STORIES self.log.info( "Copying stories to temporary table {0}.stories...".format( temp_db)) final_stories = [] for story in stories_without_tags: if coauthors is not None and coauthors.has_key(story['sid']): story['coauthors'] = coauthors[story['sid']] else: story['coauthors'] = None final_stories.append(self.story_to_final_without_tags(story)) final.insert_into_final('stories', final_stories, temp_db) # AUTHORS self.log.info("Copying authors from original eFiction source...") final_authors = [] authors = final.original_table( table_names['authors'], database_name=self.efiction_original_database) for author in authors: final_author = self.author_to_final(author) final_authors.append(final_author) final.insert_into_final('authors', final_authors, temp_db) # CHAPTERS self.log.info("Copying chapters from original eFiction source...") final_chapters = [ self.chapter_to_final(chapter) for chapter in chapters ] final.insert_into_final('chapters', final_chapters, temp_db) # TAGS self.log.info("Copying tags from original eFiction source...") final_tags = final.original_table( 'tags', database_name=self.efiction_original_database) self.tags.create_tags_table(temp_db) final.insert_into_final('tags', final_tags, temp_db)
chapters = final.original_table(table_names['chapters'], '') bookmarks_without_tags = final.original_table(table_names['bookmarks'], story_exclusion_filter) # ---------------------- # AA and custom archives # ---------------------- if args.archive_type == 'AA': # STORIES print "Copying stories to final table {0}.{1}_stories...".format( args.output_database, args.db_table_prefix) final_stories = [] for story in stories_without_tags: # Add additional story processing here final_stories.append(aa.story_to_final_without_tags(story)) final.insert_into_final(args.db_table_prefix + '_stories', final_stories) # BOOKMARKS if bookmarks_without_tags is not None: print "Copying bookmarks to final table {0}.{1}_bookmarks...".format( args.output_database, args.db_table_prefix) final_bookmarks = [] for bookmark in bookmarks_without_tags: # Add additional bookmark processing here final_bookmarks.append( aa.story_to_final_without_tags(bookmark, False)) if final_bookmarks: final.insert_into_final(args.db_table_prefix + '_bookmarks', final_bookmarks) # AUTHORS
log.info("No bookmarks to remove") chapters = final.original_table(table_names['chapters'], '') # ---------------------- # AA and custom archives # ---------------------- if args.archive_type == 'AA': # STORIES log.info("Copying stories to final table {0}.stories...".format( args.output_database)) final_stories = [] for story in stories_without_tags: # Add additional story processing here final_stories.append(aa.story_to_final_without_tags(story)) final.insert_into_final('stories', final_stories) # BOOKMARKS if bookmarks_without_tags is not None: log.info( "Copying bookmarks to final table {0}.story_links...".format( args.output_database)) final_bookmarks = [] for bookmark in bookmarks_without_tags: # Add additional bookmark processing here final_bookmarks.append( aa.story_to_final_without_tags(bookmark, False)) if final_bookmarks: final.insert_into_final('story_links', final_bookmarks) # AUTHORS