def update_article_description(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 description, 2 to leave as is: ' , min_value = 1, max_value = 2) if article_choice == 1: description_choice = btc.read_text('View article description? y/n: ') if description_choice == 'y': article_summary = na.get_article_summary(article.link) print(article_summary) # article_text = Article.get_text(article.link) # #article_text = dm.get_cleaned_text(link) # article_text = article_text.split() # article_text = [i for i in article_text if de.isEnglish(i) == True] # article_text = ' '.join(article_text) # print(article_text) new_description = btc.read_text('Enter new description or "." to cancel: ') if new_description != '.': db.update_article_description(article_id, new_description) print('Article description updated.\n') else: print('Edit cancelled, article description unchanged') else: print('Edit cancelled, article description unchanged')
def scrape_article_name(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 rescrape title, 2 to leave as is: ', min_value = 1, max_value = 2) if article_choice == 1: try: new_article_news_item = na.get_article_from_url(article.link) new_title = new_article_news_item.title #new_title = na.get_article_title(article.link) #new_title = Article.get_title(article.link) print(''' New title: {0} Old title: {1}'''.format(new_title, article.name)) except: new_title = 'Title scrape failed' title_choice = btc.read_int_ranged('1 to replace title, 2 to keep original title: ', min_value = 1, max_value = 2) if title_choice == 1: db.update_article_name(article_id, new_title) elif title_choice == 2: print('article update cancelled') elif article_choice == 2: print('article update cancelled')
def update_article_name(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 title, 2 to leave as is: ' , min_value = 1, max_value = 2) if article_choice == 1: try: newsItem1 = na.get_article_from_url(article.link) updated_title = newsItem1.title except Exception as e: print('Scrape failed because of {0}'.format(e)) updated_title = 'Invalid' print('Rescraped title: {0}'.format(updated_title)) title_choice = btc.read_int_ranged('1 - existing title, 2 - scraped title, 3 - manual input: ', 1, 3) if title_choice == 1: print('Title update cancelled, article title unchanged.') return elif title_choice == 2: db.update_article_name(article_id, updated_title) print('Title update complete. Return to main menu.') elif title_choice == 3: new_title = btc.read_text('Enter new title or . to cancel: ') if new_title != '.': db.update_article_name(article_id, new_title) else: print('Edit cancelled, return to main menu') return else: print('Edit cancelled, article title unchanged')
def display_article_by_id(): article_id = int(input("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))
def delete_article(article_id): try: article = db.get_article(article_id) choice = input("Are you sure you want to delete '" + article.name + "'? (y/n): ") if choice == "y": db.delete_article(article_id) print("'" + article.name + "' was deleted from database.\n") else: print("'" + article.name + "' was NOT deleted from database.\n") except AttributeError as e: print(e, 'Article id not found')
def update_article_author(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 author, 2 to leave as is: ' , min_value = 1, max_value = 2) if article_choice == 1: new_author = btc.read_text('Enter new author name or . to cancel: ') if new_author != '.': db.update_article_author(article_id, new_author) else: print('Edit cancelled, article title unchanged')
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 update_article_date(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 date, 2 to leave as is: ' , min_value = 1, max_value = 2) if article_choice == 1: new_day = btc.read_int_ranged('Enter new day: ', min_value = 1, max_value = 31) new_month = btc.read_int_ranged('Enter new month: ', min_value = 1, max_value = 12) new_year = btc.read_int_ranged('Enter new year: ', min_value = 1, max_value = 2100) date_choice = btc.read_int_ranged('1 to change date to: {0}/{1}/{2}, 2 to cancel: '.format(new_month, new_day, new_year), min_value=1, max_value=2) if date_choice == 1: db.update_article_date(article_id, new_day, new_month, new_year) print('Update complete.\n') elif date_choice == 2: print('Edit cancelled, article date unchanged') else: print('Edit cancelled, article date unchanged')