This is a Python-based system that manages the relationships between Authors, Magazines, and Articles. The system allows authors to contribute articles to magazines, track those contributions, and categorize them by topic areas. It also provides functionality to retrieve the magazine with the most articles.
- Authors can create articles, and each article is linked to the author.
- Authors can view the list of magazines they’ve contributed to.
- Authors can retrieve a list of unique topic areas from the magazines they’ve written for.
- Authors can add articles to magazines using the
add_article(magazine, title)method, where the magazine is an instance of theMagazineclass and the title is a string.
- Magazines can store articles.
- Magazines can list their contributors (authors).
- Magazines can return the list of titles for articles written for them.
- Magazines can return a list of authors who have written more than two articles for the magazine.
- The system can retrieve the magazine with the most articles using the
top_publisher()method.
- Articles are associated with both an author and a magazine.
- Articles have a title that must be between 5 and 50 characters long.
- Articles are linked to both the author and the magazine upon creation.
- Python 3.x
- pytest (for running tests)
Represents an article written by an author and published in a magazine.
author: The author of the article.magazine: The magazine in which the article is published.title: The title of the article (must be between 5 and 50 characters).
__init__(author, magazine, title): Initializes an article with an author, magazine, and title. The article is added to both the author's and magazine's lists of articles.all: A class attribute that stores all created articles.
Represents an author who writes articles for different magazines.
name: The name of the author.articles(): A list of articles written by the author.magazines(): A list of unique magazines the author has contributed to.
__init__(name): Initializes an author with a name.add_article(magazine, title): Creates and adds an article to the author’s list of articles and the magazine's list of articles.topic_areas(): Returns a unique list of topic areas (categories of magazines the author has written for). ReturnsNoneif the author has no articles.
Represents a magazine that publishes articles from different authors.
name: The name of the magazine.category: The category or topic area of the magazine (e.g., Fashion, Architecture).articles(): A list of articles published in the magazine.contributors(): A list of authors who have written articles for the magazine.
__init__(name, category): Initializes a magazine with a name and category.article_titles(): Returns a list of the titles of all articles written for the magazine. ReturnsNoneif the magazine has no articles.contributing_authors(): Returns a list of authors who have written more than two articles for the magazine. ReturnsNoneif there are no authors with more than two publications.top_publisher(): Returns the magazine with the most articles. ReturnsNoneif there are no articles.
To run the tests, you can use pytest. It will automatically discover and execute all tests within the tests directory or any files that start with test_ or end with _test.py.
If pytest is not already installed, run the following command:
pip install pytest
We welcome contributions to this project! If you would like to contribute, please follow these steps:
- Fork the repository to your own GitHub account.
- Clone your fork to your local machine.
- Create a new branch to work on your changes.
- Make your changes and ensure the code works as expected.
- Commit your changes and push them to your forked repository.
- Create a pull request from your fork to the main repository.
- We will review your changes and, if everything looks good, merge them into the main branch.
This project is licensed under the MIT License.
This system is designed to help manage articles written by authors and published in magazines, with basic validation for article titles, authorship, and magazine contributions. You can extend this system by adding more functionality or improving the design as needed.