def display_categories(command=''): del command print("CATEGORIES") categories = db.get_categories() for category in categories: print(str(category.id) + ". " + category.name.strip(), end=' ') print()
def export_roundup(): roundup_title = btc.read_text('Enter the roundup title or "." to cancel: ') filename = btc.read_text('Enter the filename or "." to cancel: ') if roundup_title != '.': roundup_categories = db.get_categories() for category in roundup_categories: category.articles = db.get_articles_by_category_id(category.id) roundup_docx.create_complete_roundup(filename=filename, roundup_title=roundup_title, categories=roundup_categories)
def export_roundup_by_year(): roundup_title = btc.read_text('Enter the roundup title: ') roundup_year = btc.read_int_ranged('Enter roundup year: ', 1, 2100) filename = btc.read_text('Enter roundup filename: ') roundup_choice = btc.read_int_ranged('Enter 1 to export roundup, 2 to cancel: ', 1, 2) if roundup_choice == 1: roundup_categories = db.get_categories() for category in roundup_categories: category.articles = db.yearly_roundup_articles(roundup_year, category.id) roundup_docx.create_complete_roundup(filename=filename, roundup_title=roundup_title, categories=roundup_categories) #display_title() elif roundup_choice == 2: print('Roundup export cancelled. Return to main menu.\n')
def export_roundup_by_category(): display_categories() roundup_categories = db.get_categories() categories_remaining = len(roundup_categories) categories_for_roundup = [] for category in roundup_categories: print('Categories remaining: {0}'.format(categories_remaining)) print('Include {0}'.format(category.name)) category_choice = btc.read_int_ranged('1 to include, 2 to exclude: ', 1, 2) if category_choice != 1: categories_for_roundup.append(category) roundup_title = btc.read_text('Enter the roundup title: ') roundup_month = btc.read_int_ranged('Enter roundup month: ', 1, 12) roundup_year = btc.read_int_ranged('Enter roundup year: ', 1, 2100) filename = btc.read_text('Enter roundup filename: ') roundup_choice = btc.read_int_ranged('Enter 1 to export roundup, 2 to cancel: ', 1, 2) if roundup_choice == 1: for category in categories_for_roundup: # for category in roundup_categories: category.articles = db.get_articles_for_roundup(roundup_month, roundup_year, category.id) roundup_docx.create_complete_roundup(filename=filename, roundup_title=roundup_title, categories=categories_for_roundup) #display_title() elif roundup_choice == 2: print('Roundup export cancelled. Return to main menu.\n')
def get_yearly_category_stats(year): categories = db.get_categories() total_articles = len(db.get_articles_by_year(year)) category_ids = [[category.id, category.name, db.get_yearly_article_count(category.id, year)] for category in categories] category_ids = sorted(category_ids, key=operator.itemgetter(2), reverse=True) uncategorized_articles = db.display_articles_by_description('Not specified') uncategorized_articles = len(uncategorized_articles) try: percent_incomplete = (uncategorized_articles/total_articles)*100 total_articles_completed = 100 percent_incomplete = total_articles_completed - percent_incomplete print('CATEGORY STATS - {0}'.format(year)) print('-'*64) line_format = '{0:<3} {1:11s} \t{2:10}' print('{0:<3} {1:11s} {2:10}'.format('ID', 'Name', '\tQty.')) print('-'*64) for item in category_ids: print(line_format.format(item[0], item[1], str(item[2]))) print('-'*64) print('Uncategorized Articles: {0} (Completed: {1} percent)'.format(uncategorized_articles, percent_incomplete)) print('Total Articles: {0}'.format(total_articles)) except ZeroDivisionError as e: print(e) return