def date_search(search_choice): #search_choice = btc.read_int_ranged('Options:\n1 - day\n2 - month\n3 - year\n4 - cancel\nEnter your choice: ', 1, 4) if search_choice in range(1, 4): #user searches by year year = btc.read_int('Year: ') if search_choice in range(1, 3): month = btc.read_int('Month: ') if search_choice in range(1, 2): day = btc.read_int('Day: ') try: assert datetime.date(day=day, month=month, year = year) display_articles_by_date(year, month, day) except ValueError: print('Invalid date. Return to main menu.') return #if Article.validate_date(day=day, month=month, year=year) == True: #display_articles_by_date(year, month, day) #else: # print('Invalid date selected') else: display_articles_by_month(month, year) else: display_articles_by_year(year) else: print('Search cancelled. ')
def update_article_category(article_id): article = db.get_article(article_id) if article == None: print("There is no article with that ID. article NOT found.\n") else: print() display_single_article(article, str(article.id)) article_choice = btc.read_int_ranged('1 to edit article category, 2 to leave as is: ' , min_value = 1, max_value = 2) if article_choice == 1: new_category_id = btc.read_int('Enter new category_id: ') result = db.get_category(new_category_id) if result == None: print('There is no category with that ID, article category NOT updated.\n') else: db.update_article_category(article_id, new_category_id) else: print('Edit cancelled, article title unchanged')
def manual_add(link=None): if (link == None) or (not link): print('Link', link) print('No link supplied, manual_add must be followed by link.') return else: print('Manual article creation/n') print('Link: {0}'.format(link)) display_categories() #print(link) #if link == None: # print('No link supplied, manual_add must be followed by link.') new_article_category = btc.read_int('Enter category for article: ') category = db.get_category(new_article_category) assert category != None new_article = Article.from_input(link=link, category=category) if new_article == None: print('Article creation cancelled. Returning to main menu.') return db.add_article(new_article) print(new_article.title + " was added to database.\n")