Spaces:
Sleeping
Sleeping
def generate_citation(style, author, title, publisher, year, city=None, url=None, access_date=None): | |
""" | |
Generate a citation in MLA, Chicago, or APA format. | |
:param style: Citation style ('mla', 'chicago', or 'apa') | |
:param author: Author's name (last name, first name) | |
:param title: Title of the work | |
:param publisher: Publisher's name | |
:param year: Year of publication | |
:param city: City of publication (optional) | |
:param url: URL of the source (optional) | |
:param access_date: Date accessed for online sources (optional) | |
:return: Formatted citation string | |
""" | |
if author == None: | |
author = 'Arcana' | |
if title == None: | |
title = '' | |
if publisher == None: | |
publisher = "Peer Advisor" | |
if year == None: | |
year = '' | |
if style == None: | |
style='mla' | |
if style.lower() == 'mla': | |
citation = f"{author.split(', ')[1]} {author.split(', ')[0]}. {title}. " | |
if city: | |
citation += f"{city}: " | |
citation += f"{publisher}, {year}." | |
if url: | |
citation += f" {url}." | |
if access_date: | |
citation += f" Accessed {access_date}." | |
elif style.lower() == 'chicago': | |
citation = f"{author.split(', ')[1]} {author.split(', ')[0]}. {title}. " | |
if city: | |
citation += f"{city}: " | |
citation += f"{publisher}, {year}." | |
if url: | |
citation += f" {url}." | |
elif style.lower() == 'apa': | |
citation = f"{author}. ({year}). {title}. " | |
if city: | |
citation += f"{city}: " | |
citation += f"{publisher}." | |
if url: | |
citation += f" {url}" | |
else: | |
return "Invalid citation style. Please choose 'mla', 'chicago', or 'apa'." | |
return citation | |
''' | |
# MLA citation | |
mla_citation = generate_citation('mla', 'Doe, John', 'The Great Book', 'Awesome Publishers', '2023', 'New York', 'https://example.com', 'July 20, 2024') | |
print(mla_citation) | |
# Chicago citation | |
chicago_citation = generate_citation('chicago', 'Smith, Jane', 'An Amazing Study', 'Academic Press', '2022', 'London') | |
print(chicago_citation) | |
# APA citation | |
apa_citation = generate_citation('apa', 'Johnson, Robert', 'The Future of Technology', 'Tech Books Inc.', '2024', url='https://techbooks.com/future') | |
print(apa_citation) | |
''' | |