Spaces:
Sleeping
Sleeping
Upload cite_source.py
Browse files- cite_source.py +68 -0
cite_source.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def generate_citation(style, author, title, publisher, year, city=None, url=None, access_date=None):
|
| 2 |
+
"""
|
| 3 |
+
Generate a citation in MLA, Chicago, or APA format.
|
| 4 |
+
|
| 5 |
+
:param style: Citation style ('mla', 'chicago', or 'apa')
|
| 6 |
+
:param author: Author's name (last name, first name)
|
| 7 |
+
:param title: Title of the work
|
| 8 |
+
:param publisher: Publisher's name
|
| 9 |
+
:param year: Year of publication
|
| 10 |
+
:param city: City of publication (optional)
|
| 11 |
+
:param url: URL of the source (optional)
|
| 12 |
+
:param access_date: Date accessed for online sources (optional)
|
| 13 |
+
:return: Formatted citation string
|
| 14 |
+
"""
|
| 15 |
+
if author == None:
|
| 16 |
+
author = 'Arcana'
|
| 17 |
+
if title == None:
|
| 18 |
+
title = ''
|
| 19 |
+
if publisher == None:
|
| 20 |
+
publisher = "Peer Advisor"
|
| 21 |
+
if year == None:
|
| 22 |
+
year = ''
|
| 23 |
+
if style == None:
|
| 24 |
+
style='mla'
|
| 25 |
+
|
| 26 |
+
if style.lower() == 'mla':
|
| 27 |
+
citation = f"{author.split(', ')[1]} {author.split(', ')[0]}. {title}. "
|
| 28 |
+
if city:
|
| 29 |
+
citation += f"{city}: "
|
| 30 |
+
citation += f"{publisher}, {year}."
|
| 31 |
+
if url:
|
| 32 |
+
citation += f" {url}."
|
| 33 |
+
if access_date:
|
| 34 |
+
citation += f" Accessed {access_date}."
|
| 35 |
+
|
| 36 |
+
elif style.lower() == 'chicago':
|
| 37 |
+
citation = f"{author.split(', ')[1]} {author.split(', ')[0]}. {title}. "
|
| 38 |
+
if city:
|
| 39 |
+
citation += f"{city}: "
|
| 40 |
+
citation += f"{publisher}, {year}."
|
| 41 |
+
if url:
|
| 42 |
+
citation += f" {url}."
|
| 43 |
+
|
| 44 |
+
elif style.lower() == 'apa':
|
| 45 |
+
citation = f"{author}. ({year}). {title}. "
|
| 46 |
+
if city:
|
| 47 |
+
citation += f"{city}: "
|
| 48 |
+
citation += f"{publisher}."
|
| 49 |
+
if url:
|
| 50 |
+
citation += f" {url}"
|
| 51 |
+
|
| 52 |
+
else:
|
| 53 |
+
return "Invalid citation style. Please choose 'mla', 'chicago', or 'apa'."
|
| 54 |
+
|
| 55 |
+
return citation
|
| 56 |
+
'''
|
| 57 |
+
# MLA citation
|
| 58 |
+
mla_citation = generate_citation('mla', 'Doe, John', 'The Great Book', 'Awesome Publishers', '2023', 'New York', 'https://example.com', 'July 20, 2024')
|
| 59 |
+
print(mla_citation)
|
| 60 |
+
|
| 61 |
+
# Chicago citation
|
| 62 |
+
chicago_citation = generate_citation('chicago', 'Smith, Jane', 'An Amazing Study', 'Academic Press', '2022', 'London')
|
| 63 |
+
print(chicago_citation)
|
| 64 |
+
|
| 65 |
+
# APA citation
|
| 66 |
+
apa_citation = generate_citation('apa', 'Johnson, Robert', 'The Future of Technology', 'Tech Books Inc.', '2024', url='https://techbooks.com/future')
|
| 67 |
+
print(apa_citation)
|
| 68 |
+
'''
|