-
Notifications
You must be signed in to change notification settings - Fork 2
/
website.py
249 lines (241 loc) · 9.05 KB
/
website.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
from other_funcs import author_split, citation_format, date_fix
class Website:
def __init__(
self,
title,
authors,
container,
date_published,
url,
accessed,
publisher
):
self.title = title
if authors != "":
self.authors = author_split(authors)
else:
self.authors = []
self.container = container
self.url = url
if accessed != "":
self.accessed = accessed
accessed = date_fix(accessed)
if len(accessed) == 3:
self.ac_month = accessed[0]
self.ac_day = accessed[1]
self.ac_year = accessed[2]
elif len(accessed) == 2:
self.ac_month = accessed[0]
self.ac_year = accessed[1]
else:
self.ac_year = accessed[0]
else:
self.accessed = ""
self.publisher = publisher
if date_published != "":
date_published = date_fix(date_published)
if len(date_published) == 3:
self.month = date_published[0]
self.day = date_published[1]
self.year = date_published[2]
elif len(date_published) == 2:
self.month = date_published[0]
self.year = date_published[1]
else:
self.year = date_published[0]
else:
self.year = ""
def mla(self) -> str:
"""Builds citation string for MLA Style Citation."""
citation = ""
# Add multiple authors
if self.authors != []:
if len(self.authors) == 1:
citation += f"{self.authors[0][0]}, {self.authors[0][1]}. "
if self.title != "":
citation += f'"{self.title}." '
if self.container != "":
citation += f"<em>{self.container}</em>, "
if self.publisher != "":
citation += f"{self.publisher}, "
if self.year != "":
citation += f"{self.year}, "
else:
citation += "(n.d.). "
if self.url != "":
citation += f"{self.url}. "
if self.ac_year != "":
try:
citation += f"Accessed {self.ac_day} {self.ac_month}. {self.ac_year}. "
except AttributeError:
try:
citation += f"Accessed {self.ac_month}. {self.ac_year}. "
except AttributeError:
citation += f"Accessed {self.ac_year}. "
citation.strip()
citation = citation_format(citation)
return citation
def apa(self) -> str:
"""Builds citation string for APA Style Citation."""
citation = ""
# Add multiple authors
if self.authors != []:
if len(self.authors) == 1:
citation += f"{self.authors[0][0]}, {self.authors[0][1][0]}. "
elif len(self.authors) == 2:
citation += f"{self.authors[0][0]}, {self.authors[0][1][0]}., & {self.authors[1][0]}, {self.authors[1][1][0]}. "
else:
for i in range(0, len(self.authors)):
if i != (len(self.authors) - 1):
citation += f"{self.authors[i][0]}, {self.authors[i][1][0]}., "
else:
citation += f"& {self.authors[i][0]}, {self.authors[i][1][0]}. "
elif self.publisher != "":
citation += f"{self.publisher}. "
if self.year != "":
try:
citation += f"({self.year}, {self.month} {self.day}). "
except AttributeError:
try:
citation += f"({self.year}, {self.month}). "
except AttributeError:
citation += f"({self.year}). "
else:
citation += "(n.d.). "
if self.title != "":
citation += f"<em>{self.title}</em>. "
if self.container != "":
citation += f"{self.container}. "
if self.ac_year != "":
try:
citation += f"Retrieved {self.ac_month}, {self.ac_day}, {self.ac_year}, "
except AttributeError:
try:
citation += f"Retrieved {self.ac_month} {self.ac_year}, "
except AttributeError:
citation += f"Retrieved {self.year}, "
if self.url != "":
if self.ac_year != "":
citation += f"from {self.url} "
else:
citation += f"{self.url} "
citation.strip()
citation = citation_format(citation)
return citation
def chicago(self) -> str:
"""Builds citation string for Chicago Style Citation."""
citation = ""
if self.authors == []:
# Add multiple authors
if len(self.authors) == 1:
citation += f"{self.authors[0][0]}, {self.authors[0][1]}. "
if self.title != "":
citation += f'"{self.title}." '
if self.container != "":
citation += f"{self.container}. "
if self.publisher != "":
citation += f"{self.publisher}. "
# Fix the date, yeesh! (Good here [i think])
if self.year != "":
try:
citation += f"{self.month} {self.day}, {self.year}. "
except AttributeError:
try:
citation += f"{self.month} {self.year}. "
except AttributeError:
citation += f"{self.year}. "
if self.url != "":
citation += f"{self.url}. "
citation = citation.strip()
citation = citation_format(citation)
return citation
def output(self):
"""Outputs user entered information."""
"""
self.title = title
if authors != "":
self.authors = author_split(authors)
self.container = container
self.url = url
if accessed != "":
self.accessed = date_fix(accessed)
if len(accessed) == 3:
self.ac_month = accessed[0]
self.ac_day = accessed[1]
self.ac_year = accessed[2]
elif len(accessed) == 2:
self.ac_month = accessed[0]
self.ac_year = accessed[1]
else:
self.ac_year = accessed[0]
self.date_published = date_fix(date_published)
self.publisher = publisher
if len(date_published) == 3:
self.month = date_published[0]
self.day = date_published[1]
self.year = date_published[2]
elif len(date_published) == 2:
self.month = date_published[0]
self.year = date_published[1]
else:
self.year = date_published[0]
"""
print(f"Title: {self.title}")
print("Author(s): ", end="")
if len(self.authors) == 0:
print("N/A")
elif len(self.authors) == 1:
print(f"{self.authors[0][1]} {self.authors[0][0]}")
else:
author_string = ""
for i in range(0, len(self.authors) - 1):
author_string += f"{self.authors[i][1]} {self.authors[i][0]}, "
author_string += f"{self.authors[len(self.authors) - 1][1]} {self.authors[len(self.authors) - 1][0]}"
print(author_string)
if self.accessed != "":
try:
print(f"Access date: {self.ac_month} {self.ac_day}, {self.ac_year}")
except AttributeError:
try:
print(f"Access date: {self.ac_month} {self.ac_year}")
except AttributeError:
print(f"Access date: {self.ac_year}")
else:
print("Accessed: N/A")
if self.container != "":
print(f"Website: {self.container}")
else:
print("Website: N/A")
print("Publisher: ", end="")
if self.publisher != "":
print(f"{self.publisher}")
else:
print("N/A")
print("URL/DOI: ", end="")
if self.url != "":
print(f"{self.url}")
else:
print("N/A")
print("Publication date: ", end="")
if self.year != "":
try:
print(f"{self.month} {self.day}, {self.year}")
except AttributeError:
try:
print(f"{self.month} {self.year}")
except AttributeError:
print(f"{self.year}")
def web_ask(sources) -> None:
"""Prompts for inputting information about a Web Article source."""
title = input("Website article title?: ")
authors = input(
"Authors? (First and last name; separate each full name by comma): "
)
container = input("Website name?: ")
publisher = input("Publisher?: ")
url = input("Website URL?: ")
accessed = input("Date accessed? (MM, DD, YYYY; MM, YYYY;, or YYYY): ")
date_published = input("Date published? (MM, DD, YYYY; MM, YYYY;, or YYYY): ")
sources.append(
Website(title, authors, container, date_published, url, accessed, publisher)
)