def valid_tags(key, tag_type_list): return [d[key].strip() for d in tag_type_list if key in d and d[key] is not None and d[key] != ''] if __name__ == "__main__": args_obj = Args() args = args_obj.args_for_06() log = args_obj.logger_with_filename() sql = Sql(args, log) tags = Tags(args, sql.db, log) final = FinalTables(args, sql.db, log) if args.archive_type == 'EF': table_names = efiction.table_names() else: table_names = { 'authors': 'authors', 'stories': 'stories', 'chapters': 'chapters' } log.info("Getting all tags per story...") tags_by_story_id = tags.tags_by_story_id() for (story_id, tags) in tags_by_story_id.items(): # group tags by type into comma-separated lists
def _clean_email(author): email = author['email'] if author['email'] is None or author['email'] == '': email = u'{0}{1}[email protected]'.format(author['name'], args.archive_name)\ .replace(' ', '').replace("'", "") if author['email'].startswith('mailto:'): email = author['email'].replace('mailto:', '') return email if __name__ == "__main__": args = Args.args_for_05() sql = Sql(args) tags = Tags(args, sql.db) final = FinalTables(args, sql.db) chaps = Chapters(args, sql.db) filter = '' coauthors = {} print "Creating destination tables in {0}".format(args.output_database) if args.archive_type == 'EF': table_names = efiction.table_names() 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 if has_coauthors: coauthors_dict = sql.execute_dict( "SELECT * FROM fanfiction_coauthors")
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)
email = author['email'] if email is None or email == '': email = u'{0}{1}[email protected]'.format(author['name'], args.archive_name)\ .replace(' ', '').replace("'", "") if email.startswith('mailto:'): email = author['email'].replace('mailto:', '') return email if __name__ == "__main__": args_obj = Args() args = args_obj.args_for_05() log = args_obj.logger_with_filename() sql = Sql(args, log) tags = Tags(args, sql.db, log) final = FinalTables(args, sql.db, log) chaps = Chapters(args, sql.db, log) coauthors = {} log.info("Creating destination tables in {0}".format(args.output_database)) table_names = { 'authors': 'authors', 'stories': 'stories', 'chapters': 'chapters', 'story_links': 'story_links' } filter = 'WHERE id NOT IN ' sql.run_script_from_file('shared_python/create-open-doors-tables.sql',
# encoding: utf-8 from shared_python.Args import Args from shared_python.FinalTables import FinalTables from shared_python.PopulateTags import PopulateTags from shared_python.Sql import Sql from shared_python.Tags import Tags if __name__ == "__main__": args_obj = Args() args = args_obj.args_for_06() log = args_obj.logger_with_filename() sql = Sql(args, log) tags = Tags(args, sql.db, log) final = FinalTables(args, sql.db, log) populate_tags = PopulateTags(args, sql.db, log, final) populate_tags.populate_tags()
from shared_python.Sql import Sql from shared_python.Tags import Tags def valid_tags(key, tag_type_list): return [ d[key].strip() for d in tag_type_list if key in d and d[key] is not None and d[key] != '' ] if __name__ == "__main__": args = Args.args_for_06() sql = Sql(args) tags = Tags(args, sql.db) final = FinalTables(args, sql.db) if args.archive_type == 'EF': table_names = efiction.table_names() else: table_names = { 'authors': 'authors', 'stories': 'stories', 'chapters': 'chapters' } print "Getting all tags per story..." tags_by_story_id = tags.tags_by_story_id() for (story_id, tags) in tags_by_story_id.items(): # group tags by type into comma-separated lists