def add_movie(name,year, minutes, category_id): db.connect() category = db.get_category(category_id) movie = Movie(name=name, year=year, minutes=minutes, category=category) db.add_movie(movie) print(name + " was added to database.\n")
def display_movies_by_category(): category_id = int(input("Category ID: ")) category = db.get_category(category_id) if category == None: print("There is no category with that ID.\n") else: print() movies = db.get_movies_by_category(category_id) display_movies(movies, category.name.upper())
def display_books_by_category(): category_id = int(input("Category ID: ")) category = db.get_category(category_id) if category is None: print("There is no category with that ID.\n") else: print() books = db.search_book_by_category(category_id) display_books(books, category.name.upper())
def add_movie(): name = input("Name: ") year = int(input("Year: ")) minutes = int(input("Minutes: ")) category_id = int(input("Category ID: ")) category = db.get_category(category_id) movie = Movie(name=name, year=year, minutes=minutes, category=category) db.add_movie(movie) print(name + " was added to database.\n")
def add_movie(): name = input("Name: ") year = int(input("Year: ")) minutes = int(input("Minutes: ")) category_id = int(input("Category ID: ")) category = db.get_category(category_id) if category == None: print("There is no category with that ID. Movie NOT added.\n") else: movie = Movie(name=name, year=year, minutes=minutes, category=category) db.add_movie(movie) print(name + " was added to database.\n")
def update_category(category_id=0): if category_id == 0: category_id = int(input("category ID: ")) category = db.get_category(category_id) #articles = db.get_articles_by_category_id(category_id) #display_articles(articles, category.category_name.upper()) print('Current category name: {0}'.format(category.category_name)) new_category_name = btc.read_text( "Enter new category name or '.' to cancel: ") if new_category_name != '.': update_choice = btc.read_int_ranged( "1 to change article name to {0}, 2 to cancel: ".format( new_category_name), 1, 2) if update_choice == 1: db.update_category(category_id, new_category_name) print('Category update complete\n') elif update_choice == 2: print('Update cancelled.\n')
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.ArticleID)) 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) #Add in some text that is displayed to make it clear that the category is being updated 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): category = btc.read_int('Enter category for article: ') category = db.get_category(category) new_article = Article.manual_add(link=link, category=category) db.add_article(new_article) print(new_article.title + " was added to database.\n")
def from_newspaper(link): ''' Adds an article from the newspaper module after downloading it ''' for i in tqdm.tqdm(range(1)): try: newNewsItem = na.get_article_from_url(link) except: print('Article download failed, invalid URL') print('Returning to main menu') return print(newNewsItem) try: name = newNewsItem.title #get the title for the article except Exception as e: print(e) name = btc.read_text('Please enter title: ') #get article author try: author = ' '.join(newNewsItem.authors) #get article publication except Exception as e: print(e) author = btc.read_text('Please enter author: ') try: #works for most websites, but not Sudan Tribune publication = newNewsItem.meta_data['og']['site_name'] except Exception as e: print(e) publication = btc.read_text('Please enter publication: ') try: year = newNewsItem.publish_date.year month = newNewsItem.publish_date.month day = newNewsItem.publish_date.day new_date = datetime.date(day=day, month=month, year=year) except Exception as e: print(e) #use the new btc.read_date() function to simplify this try: new_date = btc.read_date('Enter article date MM/DD/YYYY: ') except Exception as e: print('invalid date', e) try: summary = newNewsItem.summary except Exception as e: print(e) print('Summary download failed') summary = 'Summary not found' try: keywords = ', '.join(newNewsItem.keywords) except Exception as e: print(e) print('Keyword download failed') keywords = 'keywords not found' print('TITLE - {0} - AUTHOR {1}'.format(name, author)) print('DATE - {0} - PUBLICATION {1}'.format(new_date.strftime("%m/%d/%Y"), publication)) print('KEYWORDS: ', keywords) display_categories() category_id = btc.read_text("Category ID: ") category = db.get_category(category_id) if category == None: print('There is no category with that ID. article NOT added.\n') return description_choice = btc.read_text('View article description? y/n: ') if description_choice == 'y': print('Title: {0}'.format(name)) print('Summary: {0}'.format(summary)) print('Keywords: {0}'.format(keywords)) description = btc.read_text("Description or '.' to cancel: ") if description == ".": return else: new_article = Article(name=name, date=new_date, category=category, link=link, description=description, author=author, publication=publication) display_single_article(article=new_article, title_term=new_article.name) confirm_article = btc.read_bool(decision="Finalize the article?", yes='y', no='n', yes_option='Confirm', no_option='Cancel') #This is the user's last chance to decide if they want to add the article if confirm_article == True: db.add_article(new_article) print(new_article.name + " was added to database.\n") elif confirm_article == False: print('Article add cancelled. Return to main menu.')
def from_snippet(snippet=None, snippet_type=None, start_date=None, end_date=None): ''' This function takes a snippet, as well as the snippet type, and retrieves a value from the database based on that snippet type. For example, if the snippet type is 'name' then it retrieves the article by name. If it is description, it retrieves it by description. This function is intended to replace many of the functions that retrieve data based on text fields. ''' results = None if snippet_type == 'description': if (start_date != None) or (end_date != None): results = db.get_snippet(snippet, snippet_type=snippet_type) else: results = db.get_snippet(snippet, snippet_type=snippet_type, start_date=start_date, end_date=end_date) elif snippet_type == 'title': #print(start_date, end_date) if (start_date == None) or (end_date == None): results = db.get_snippet(snippet, snippet_type=snippet_type) else: results = db.get_snippet(snippet, snippet_type=snippet_type, start_date=start_date, end_date=end_date) elif snippet_type == 'category': if (start_date == None) or (end_date == None): results = db.get_snippet(snippet, snippet_type=snippet_type) else: results = db.get_snippet(snippet, snippet_type=snippet_type, start_date=start_date, end_date=end_date) elif snippet_type == 'category_id': #print('category id detected') if (start_date == None) or (end_date == None): #category_id = db.get_category(snippet) results = db.get_snippet(snippet, snippet_type=snippet_type) else: results = db.get_snippet(snippet, snippet_type=snippet_type, start_date=start_date, end_date=end_date) #results = db.get_snippet(snippet, snippet_type='title') #remember it is called name if results == None: print('There is no article with that {0}.\n'.format(snippet_type)) else: if snippet_type == 'title': display_articles(results, str('Results for {0}'.format(snippet))) elif snippet_type == 'description': display_articles(results, str('Results for {0}'.format(snippet))) elif snippet_type == 'category': display_articles(results, str('Results for {0}'.format(snippet))) elif snippet_type == 'category_id': category_id = db.get_category( snippet) #retrieve the category for display #this replicates the depricated get_articles_by_category_id function category_name = category_id.category_name #get the name to display display_articles(results, str('Results for {0}'.format(category_name))) else: print('Search cancelled, returning to main menu.')
def display_movies_by_category(): category_id = int(input("Category ID: ")) print() category = db.get_category(category_id) movies = db.get_movies_by_category(category_id) display_movies(movies, category.name.upper())