-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathezcitev2.py
1181 lines (892 loc) · 49.7 KB
/
ezcitev2.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
ezCite Version 2.0.0 (GUI VERSION)
By Leodeng & Allen Wang
Leo's Website & Email: leosblog.xyz | [email protected]
HELP WANTED: help pls bro i need fixed code without any errors and pls send the email as well moneyyy wil be 1000000000usd haha just kiding were using u 4 free lol haha troll my CODE IS DRIVING ME CRAZYYYYYYYYY :)))(((())))(((())))(((())))
ahem... 'ello mate! oops, ok, here we go... hello stranger, if you are seeing this right now we have an official code license (MIT License)!
"""
"""
MIT LICENSE (MIT)
Copyright ©2022 The Interstellar Programmers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
"""
,%%%%%%%%,
,%%/\%%%%/\%%
,%%%\c "" J/%%%
%. %%%%/ o o \%%%
`%%. %%%% _ |%%%
`%% `%%%%(__Y__)%%'
// ;%%%%`\-/%%%'
(( / `%%%%%%%'
\\ .' |
\\ / \ | |
\\/ ) | |
\ /_ | |__
(___________))))))) 攻城湿
_ _
| | ___ ___ __| | ___ _ __ __ _
| | / _ \/ _ \ / _` |/ _ \ '_ \ / _` |
| |__| __/ (_) | (_| | __/ | | | (_| |
|_____\___|\___/ \__,_|\___|_| |_|\__, |
|___/
_
__ _ _ __ __| |
/ _` | '_ \ / _` |
| (_| | | | | (_| |
\__,_|_| |_|\__,_|
_ _ _ __ __
/ \ | | | ___ _ __ \ \ / /_ _ _ __ __ _
/ _ \ | | |/ _ \ '_ \ \ \ /\ / / _` | '_ \ / _` |
/ ___ \| | | __/ | | | \ V V / (_| | | | | (_| |
/_/ \_\_|_|\___|_| |_| \_/\_/ \__,_|_| |_|\__, |
|___/
__ _ _ __ _ ____ _ __
/ / / \ | |/ / / \ / ___| _ __ ___ ___| | _\ \
| | / _ \ | ' / / _ \ \___ \| '_ \ / _ \ / __| |/ /| |
| |/ ___ \ _| . \ _ / ___ \ ___) | |_) | (_) | (__| < | |
| /_/ \_(_)_|\_(_)_/ \_\ |____/| .__/ \___/ \___|_|\_\| |
\_\ |_| /_/
"""
"""
,----------------, ,---------,
,-----------------------, ," ,"|
," ,"| ," ," |
+-----------------------+ | ," ," |
| .-----------------. | | +---------+ |
| | | | | | -==----'| |
| | I LOVE DOS! | | | | | |
| | Bad command or | | |/----|`---= | |
| | C:\>_ | | | ,/|==== ooo | ;
| | | | | // |(((( [33]| ,"
| `-----------------' |," .;'| |(((( | ,"
+-----------------------+ ;; | | |,"
/_)______________(_/ //' | +---------+
___________________________/___ `,
/ oooooooooooooooo .o. oooo /, \,"-----------
/ ==ooooooooooooooo==.o. ooo= // ,`\--{)B ,"
/_==__==========__==_ooo__ooo=_/' /___________,"
"""
"""
___====-_ _-====___
_--^^^#####// \\#####^^^--_
_-^##########// ( ) \\##########^-_
-############// |\^^/| \\############-
_/############// (@::@) \\############\_
/#############(( \\// ))#############\
-###############\\ (oo) //###############-
-#################\\ / VV \ //#################-
-###################\\/ \//###################-
_#/|##########/\######( /\ )######/\##########|\#_
|/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
` |/ V V ` V \#\| | | |/#/ V ' V V \| '
` ` ` ` / | | | | \ ' ' ' '
( | | | | )
__\ | | | | /__
(vvv(VVV)(VVV)vvv)
神兽保佑
代码无BUG!
"""
#LIBRARY Imports
from tkinter import *
from tkinter import messagebox
import tkinter as tk
import webbrowser
import os
import requests
from bs4 import BeautifulSoup
import time
import csv
from datetime import datetime
from datetime import date
import json
from scrtext import credsmusic
from pygame import mixer
#Define GUI size and window title
window = tk.Tk()
window.configure(background='#3b3b4a')
window.title('ezCite Version 2.0.0')
cwd_settings = os.getcwd() + r'/assets/settings.json'
cwd_icon = os.getcwd() + r'/assets/images/appicon.png'
cwd_bt = os.getcwd() + r'/assets/images/button_help-faq.png'
cwd_bt1 = os.getcwd() + r'/assets/images/button_about-the-devs.png'
cwd_bt2 = os.getcwd() + r'/assets/images/button_settings.png'
cwd_bt3 = os.getcwd() + r'/assets/images/button_mla-website-citation.png'
cwd_bt4 = os.getcwd() + r'/assets/images/button_mla-book-citation.png'
cwd_bt5 = os.getcwd() + r'/assets/images/button_apa-website-citation.png'
cwd_bt6 = os.getcwd() + r'/assets/images/button_apa-book-citation.png'
cwd_submit = os.getcwd() + r'/assets/images/button_submit.png'
cwd_sound = os.getcwd() + r'/assets/images/button_sound.png'
cwd_creds = os.getcwd() + r'/assets/images/button_credits.png'
cwd_theme = os.getcwd() + r'/assets/images/button_theme.png'
cwd_save = os.getcwd() + r'/assets/images/button_save.png'
cwd_errorlog = os.getcwd() + r'/assets/errorlog.txt'
cwdbtclick1 = os.getcwd() + r'/assets/sound/b_click_variation1.wav'
today = datetime.now()
errorlogtime = today.strftime("%Y-%m-%d at %X")
def writeerrorlog(e):
#APPEND MODE
errorlogstr = str(e)
file1 = open(cwd_errorlog, "a")
file1.write("\n[ERROR:]\n")
file1.write(e)
file1.write("\n[LOG TIME: ")
file1.write(errorlogtime)
file1.write("]\n")
file1.close()
try:
#Read Settings JSON file
with open(cwd_settings, 'r') as openfile:
# Reading from json file
settingsjson = json.load(openfile)
#INITALIZE SETTINGS
settings_colortheme = settingsjson['colortheme']
settings_soundeffectvolume = settingsjson['soundeffectvol']
settings_randmsoundeffects = settingsjson['randomsoundeffects']
except Exception as e:
writeerrorlog(e)
mixer.init()
mixer.music.load(cwdbtclick1)
print("Sound EFFECT VOLUME json string: ", settings_soundeffectvolume)
if settings_soundeffectvolume == 1.0:
print("Volume set: 0.0")
mixer.music.set_volume(0.0)
if settings_soundeffectvolume >= 10.0:
print("Volume set: 0.1")
mixer.music.set_volume(0.1)
if settings_soundeffectvolume >= 20.0:
print("Volume set: 0.2")
mixer.music.set_volume(0.2)
if settings_soundeffectvolume >= 30.0:
print("Volume set: 0.3")
mixer.music.set_volume(0.3)
if settings_soundeffectvolume >= 40.0:
print("Volume set: 0.4")
mixer.music.set_volume(0.4)
if settings_soundeffectvolume >= 50.0:
print("Volume set: 0.5")
mixer.music.set_volume(0.5)
if settings_soundeffectvolume >= 60.0:
print("Volume set: 0.6")
mixer.music.set_volume(0.6)
if settings_soundeffectvolume >= 70.0:
print("Volume set: 0.7")
mixer.music.set_volume(0.7)
if settings_soundeffectvolume >= 80.0:
print("Volume set: 0.8")
mixer.music.set_volume(0.8)
if settings_soundeffectvolume >= 90.0:
print("Volume set: 0.9")
mixer.music.set_volume(0.9)
if settings_soundeffectvolume >= 100.0:
print("Volume set: 1.0")
mixer.music.set_volume(1.0)
def bt1():
mixer.music.play()
window.geometry('545x770')
window.minsize(545, 770)
window.maxsize(545, 770)
#APP ICON
p1 = PhotoImage(file = cwd_icon)
window.iconphoto(False, p1)
#Titles
title = tk.Label(window, text='ezCite', bg='#3b3b4a', font=('Ubuntu Regular', 45), width=40, height=0, fg='#ffffff')
title.pack()
title1 = tk.Label(window, text='|--- The Ultimate Citation Generator ---|', bg='#3b3b4a', font=('Ubuntu Regular', 28),width=40, height=0, fg='#ffffff')
title1.pack()
#Global Variables
global mwc
mwc = ""
global el
el = ""
#CSV file config
fields = ['Date', 'Citation', 'Type']
os.system("cd ..")
os.system("cd ..")
os.system("cd ..")
fileplace = str(os.path.expanduser('~')) + "/Desktop"
filename = fileplace + "/ezcite_citations.csv"
print("ezCite Citations CSV FILE LOCATION: ", filename)
#CSV Saved File Date
today = date.today()
#Type of citation (Saved in CSV file)
typemlaweb = 'MLA8 Website Citation'
typemlabook = 'MLA8 Book Citation'
typeapabook = 'APA7 Book Citation'
typeapaweb = 'APA7 Website Citation'
#Open CSV for INITIATION: write first title row
try:
#If no file on desktop named "ezcite_citations.csv" create it
with open(filename,'x', newline ='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
except:
#If there is, open it
with open(filename,'a', newline ='') as csvfile:
csvwriter = csv.writer(csvfile)
pass
#Button 1 (HELP)
def helpec():
bt1()
webbrowser.open('https://leodeng.gitbook.io/ecwiki/getting-started/installation/installation-video')
click_btn= PhotoImage(file=cwd_bt)
b1 = tk.Button(image=click_btn, command = helpec, bg='#3b3b4a', border=100, activebackground='#3b3b4a', bd='0')
b1.pack(pady=10)
#Button 2 (About)
def abec():
bt1()
atd = Toplevel(window)
atd.title("ezCite Version 2.0.0 - About the Developers")
atd.geometry("1080x630")
atd.configure(background='#3b3b4a')
Label(atd,text ="About the Developers:", bg='#3b3b4a', font=('Ubuntu Regular', 40), width=40, height=2).pack()
Label(atd,text ="Hello Stranger! \n(Or maybe friend in this situation, ok if u know me dont look haha) \nI'm Leo! One of the developers of ezCite,\na 13 year old developer that likes to code(lol)\nI admire Linus Torvalds and also like to use ubuntu/fedora.\nI mainly code in: Python, HTML, Markdown, and CSS(a little)", bg='#3b3b4a', font=('Ubuntu Regular', 22), width=400, height=10).pack()
Label(atd,text ="Allen, a highly skilled design educator and specialist in digital design, robotics, and artificial intelligence. \nWith extensive experience in these fields, \nhe has developed a deep understanding of how to integrate these cutting-edge technologies into education. \nAllen is committed to using AI to revolutionize the way we approach education, \nwith a focus on developing innovative, \nAI-powered educational products that deliver more effective and personalized learning experiences. \nHis expertise in these areas makes him a valuable asset to the education industry, \nand his passion and dedication to the field ensure that he is always at the forefront of the latest developments and trends.\nDevelopment of educational products, \nbelieving that AI can bring more possibilities and innovation to education.\n Allen's passion and talent can bring more opportunities for students and the education industry.", bg='#3b3b4a', font=('Ubuntu Regular', 18), width=200, height=11).pack()
click_btn1= PhotoImage(file=cwd_bt1)
b2 = tk.Button(image=click_btn1, command = abec, borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
b2.pack(pady=10)
#Settings function buttons
click_btn_sound= PhotoImage(file=cwd_sound)
click_btn_creds= PhotoImage(file=cwd_creds)
click_btn_theme= PhotoImage(file=cwd_theme)
click_btn_save= PhotoImage(file=cwd_save)
#Button 3 (Settings)
def s():
bt1()
def soundprefs():
v1 = DoubleVar()
soundprefwindow = Toplevel(window)
soundprefwindow.title("ezCite Version 2.0.0 - Sound Preferences")
soundprefwindow.geometry("400x350")
soundprefwindow.configure(background='#3b3b4a')
Label(soundprefwindow,text ="ezCite Sound Preferences", bg='#3b3b4a', font=('Ubuntu Regular', 20), width=45, height=3).pack()
Label(soundprefwindow,text ="Sound Effects Volume (RESTART TO SEE CHANGES!)", bg='#3b3b4a', font=('Ubuntu Regular', 15), width=50, height=3).pack()
cv = "Current Volume: " + str(settings_soundeffectvolume)
Label(soundprefwindow,text = cv, bg='#3b3b4a', font=('Ubuntu Regular', 12), width=40, height=2).pack()
s1 = Scale(soundprefwindow, variable = v1, from_ = 1, to = 100, orient = HORIZONTAL)
def save():
settingsjson["soundeffectvol"] = v1.get()
jsonfile = open(cwd_settings, "w")
json.dump(settingsjson, jsonfile)
jsonfile.close()
pass
savese = Button(soundprefwindow, image=click_btn_save, command=save, borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
s1.pack(anchor = CENTER)
savese.pack(pady=15)
def themeprefs():
themeprefwindow = Toplevel(window)
themeprefwindow.title("ezCite Version 2.0.0 - Theme Preferences")
themeprefwindow.geometry("200x100")
themeprefwindow.configure(background='#3b3b4a')
Label(themeprefwindow,text ="COMING SOON", bg='#3b3b4a', font=('Ubuntu Regular', 20), width=40, height=3).pack()
def showcredits():
credsmusic()
p1 = PhotoImage(file = cwd_icon)
window.iconphoto(False, p1)
pref = Toplevel(window)
pref.title("ezCite Version 2.0.0 - Settings")
pref.geometry("400x500")
pref.configure(background='#3b3b4a')
Label(pref,text ="ezCite Preferences", bg='#3b3b4a', font=('Ubuntu Regular', 40), width=40, height=3).pack()
sound = Button(pref, image=click_btn_sound, command=soundprefs, borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
sound.pack(pady=15)
creds = Button(pref, image=click_btn_creds, command=showcredits, borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
creds.pack(pady=15)
music = Button(pref, image=click_btn_theme, command=themeprefs, borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
music.pack(pady=15)
click_btn2= PhotoImage(file=cwd_bt2)
b2 = tk.Button(image=click_btn2, command = s, borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
b2.pack(pady=10)
#SUBMIT BUTTON
click_btn_submit= PhotoImage(file=cwd_submit)
"""
__ __ _ _ ___ __ __ _ ____
| \/ | | / \ ( _ ) \ \ / /__| |__ / ___| ___ _ __
| |\/| | | / _ \ / _ \ \ \ /\ / / _ \ '_ \ | | _ / _ \ '_ \
| | | | |___ / ___ \ | (_) | \ V V / __/ |_) | | |_| | __/ | | |
|_| |_|_____/_/ \_\ \___/ \_/\_/ \___|_.__/ \____|\___|_| |_|
____ _____ _ _____ __
| __ )| ____| | / _ \ \ / /
| _ \| _| | | | | | \ \ /\ / /
| |_) | |___| |__| |_| |\ V V /
|____/|_____|_____\___/ \_/\_/
"""
#Button 4 (MLA 8 Website Citation)
def mla8web():
bt1()
mla8webwin = Toplevel(window)
mla8webwin.title("ezCite Version 2.0.0 - MLA 8 Website Citation")
mla8webwin.geometry("1200x600")
mla8webwin.minsize(1200, 600)
mla8webwin.maxsize(1200, 600)
mla8webwin.configure(background='#3b3b4a')
Label(mla8webwin,text ="ezCite - MLA 8 Website Citation Generator", bg='#3b3b4a', font=('Ubuntu Regular', 40), width=40, height=3, fg='#ffffff').pack()
Label(mla8webwin, text = 'Website (JSTOR is not supported)', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack()
entry = Entry(mla8webwin, font=('Ubuntu Regular',11))
entry.pack(ipadx= 400)
submit = Button(mla8webwin, image=click_btn_submit, command=lambda: get_mla8_web_citation(entry), borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
submit.pack(pady=30)
Label(mla8webwin, text = 'Citation Output (Copy&Paste Supported):', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack(pady=20)
T = Text(mla8webwin, height = 2, width = 105, font=('Ubuntu Regular', 18))
T.pack()
Label(mla8webwin, text = 'Note:\n If you forgot to Copy&Paste Your Citation, or want to copy 10 citations all together,then find the "ezcite_citations.csv" file in the directory(folder)\n that ezcite is in (Usually Desktop), then you will see a log of citations\n that you entered, with the output. :3', bg='#3b3b4a', font=('Ubuntu Regular', 17), fg='#ffffff').pack(pady=20)
def get_mla8_web_citation(entry):
try:
global mwc
mwc = entry.get()
reqs = requests.get(mwc)
entry.delete(0, 'end')
T.delete("1.0","end")
tic = time.perf_counter()
#reqs.content or .text (MUST USE reqs.content here, FOR CHINESE SUPPORT! DO NOT, EVER, CHANGE IT!)
soup = BeautifulSoup(reqs.content, 'html.parser')
#Find website title
for title in soup.find_all('title'):
title.get_text()
websitetitle = title.get_text()
link = mwc
#Citation date shown on-screen
citedate = today.strftime("%d %b. %Y.")
#Date recorded on CSV file
csv_citedate1 = today.strftime("%Y-%m-%d")
#Put Citation together in a variable
mla8_webcite_result = websitetitle + ". " + link + ". " + "Accessed " + citedate
#Print result to-screen (CONSOLE, users won't see that)
print(mla8_webcite_result)
#SHOW USERS ON-SCREEN:
T.insert(tk.END, mla8_webcite_result)
#Open CSV ('a' option doesn't delete anything when it restarts...)
with open(filename, 'a', newline ='') as csvfile:
csvwriter = csv.writer(csvfile)
#Write citation details (Date, Citation, Type)
mla8_webcite_csv = [[csv_citedate1,mla8_webcite_result,typemlaweb]]
#Write the details
csvwriter.writerows(mla8_webcite_csv)
except requests.exceptions.MissingSchema:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc + "\n\nError Code: requests.exceptions.MissingSchema\n\nCause: No Website Headers \n\nFix: WEBSITE HEADERS MUST CONTAIN https:// OR http://!!!"
messagebox.showerror(title=f"Error:", message=msgboxerror)
except requests.exceptions.InvalidSchema:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc + "\n\nError Code: requests.exceptions.InvalidSchema\n\nCause: Incorrect Website Headers \n\nFix: Check Website Headers (https:// or http://)"
messagebox.showerror(title=f"Error:", message=msgboxerror)
except requests.exceptions.InvalidURL:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc + "\n\nError Code: requests.exceptions.InvalidURL\n\nCause: No URL Provided \n\nFix: Provide URL"
messagebox.showerror(title=f"Error:", message=msgboxerror)
except requests.exceptions.ConnectionError:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc + "\n\nError Code: requests.exceptions.ConnectionError\n\nCause: Incorrectly Entered Website Address or Cannot Connect to Website\n\nFix: Provide Correct URL or Check Internet Connection"
messagebox.showerror(title=f"Error:", message=msgboxerror)
click_btn3= PhotoImage(file=cwd_bt3)
b2 = tk.Button(image=click_btn3, command = mla8web, borderwidth=0, bg='#00FFFF', activebackground='#00FFFF')
b2.pack(pady=10)
"""
__ __ _ _ ___ ____ _ ____
| \/ | | / \ ( _ ) | __ ) ___ ___ | | __ / ___| ___ _ __
| |\/| | | / _ \ / _ \ | _ \ / _ \ / _ \| |/ / | | _ / _ \ '_ \
| | | | |___ / ___ \ | (_) | | |_) | (_) | (_) | < | |_| | __/ | | |
|_| |_|_____/_/ \_\ \___/ |____/ \___/ \___/|_|\_\ \____|\___|_| |_|
____ _____ _ _____ __
| __ )| ____| | / _ \ \ / /
| _ \| _| | | | | | \ \ /\ / /
| |_) | |___| |__| |_| |\ V V /
|____/|_____|_____\___/ \_/\_/
"""
#Button 5 (MLA 8 Book Citation)
def mla8book():
bt1()
mla8bookwin = Toplevel(window)
mla8bookwin.title("ezCite Version 2.0.0 - MLA 8 Book Citation")
mla8bookwin.geometry("1200x600")
mla8bookwin.minsize(1200, 600)
mla8bookwin.maxsize(1200, 600)
mla8bookwin.configure(background='#3b3b4a')
Label(mla8bookwin,text ="ezCite - MLA 8 Book Citation Generator", bg='#3b3b4a', font=('Ubuntu Regular', 40), width=40, height=3, fg='#ffffff').pack()
Label(mla8bookwin, text = 'ISBN Number (Only enter 13 digit ISBN\'s)', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack()
entry = Entry(mla8bookwin, font=('Ubuntu Regular',11))
entry.pack(ipadx= 400)
submit = Button(mla8bookwin, image=click_btn_submit, command=lambda: get_mla8_book_citation(entry), borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
submit.pack(pady=30)
Label(mla8bookwin, text = 'Citation Output (Copy&Paste Supported):', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack(pady=20)
T = Text(mla8bookwin, height = 2, width = 105, font=('Ubuntu Regular', 18))
T.pack()
Label(mla8bookwin, text = 'Note:\n If you forgot to Copy&Paste Your Citation, or want to copy 10 citations all together,then find the "ezcite_citations.csv" file in the directory(folder)\n that ezcite is in (Usually Desktop), then you will see a log of citations\n that you entered, with the output. :3', bg='#3b3b4a', font=('Ubuntu Regular', 17), fg='#ffffff').pack(pady=20)
# function to remove middle name from full name
def remove_middle_name(full_name):
# split the full name into a list of words
name_words = full_name.split()
# check if the name has a middle name
if len(name_words) == 3:
# remove the middle name
name_words.pop(2)
# join the remaining words to form the updated name
updated_name = " ".join(name_words)
# return the updated name
return updated_name
def get_mla8_book_citation(entry):
mwc_mla8_book = entry.get()
isbn1 = "https://www.isbnsearcher.com/books/" + mwc_mla8_book
response = requests.get(isbn1, mwc_mla8_book)
# datetime object containing current date and time
now = datetime.now()
# function to remove middle name from full name
def remove_middle_name(full_name):
# split the full name into a list of words
name_words = full_name.split()
# check if the name has a middle name
if len(name_words) == 3:
# remove the middle name
name_words.pop(2)
# join the remaining words to form the updated name
updated_name = " ".join(name_words)
# return the updated name
return updated_name
authornameoutput = ""
if response.status_code == 200:
# Parse the HTML content using BeautifulSoup
html_content = response.content
soup = BeautifulSoup(html_content, 'html.parser')
# Find all the elements with class name "text-success"
authors = soup.find_all(class_="text-success")
for author in authors:
if "author" in str(author):
print("AUTHOR NAME IN TEXT-SUCCESS")
# Extract the author's name from the text content
author_name = author.text.strip()
# Reverse the order of the name parts (if applicable)
name_parts = author_name.split()
if len(name_parts) > 1 and len(name_parts) < 10:
author_name = name_parts[-1]+ ", " + " " + " ".join(name_parts[:-1])
# test the remove_middle_name function
name_with_middle = author_name
name_without_middle = remove_middle_name(name_with_middle)
#print(name_with_middle) # "John Michael Smith"
authornameoutput = name_without_middle
print(authornameoutput)
# dd/mm/YY H:M:S
# datetime object containing current date and time
now = datetime.now()
dt_string = now.strftime("%Y/%m/%d %H:%M:%S")
else:
print("AUTHOR NAME NOT IN TEXT-SUCCESS")
authors = soup.find_all(class_="col-8 col-sm-9 mb-1")[-1]
for author in authors:
# Extract the author's name from the text content
author_name = author.text.strip()
# Reverse the order of the name parts (if applicable)
name_parts = author_name.split()
if len(name_parts) > 1 and len(name_parts) < 10:
author_name = name_parts[-1]+ ", " + " " + " ".join(name_parts[:-1])
# test the remove_middle_name function
name_with_middle = author_name
name_without_middle = remove_middle_name(name_with_middle)
#print(name_with_middle) # "John Michael Smith"
authornameoutput = name_without_middle
print(authornameoutput)
# dd/mm/YY H:M:S
# datetime object containing current date and time
now = datetime.now()
dt_string = now.strftime("%Y/%m/%d %H:%M:%S")
# Print the author's name
#print(f"Author: {author_name}")
publishers = soup.find_all(class_="text-success")[-2]
for publisher in publishers:
if "publisher" in str(publisher):
# Extract the publisher's name from the text content
publisher = publisher.text.strip()
publishernameoutput = publisher + ", "
else:
publisher = publisher.text.strip()
publishernameoutput = publisher + ", "
# Print the publisher's name
#print(f"Author: {author_name}")
booknames = soup.find_all(class_="mb-4 fs-4")
for bookname in booknames:
# Extract the book's name from the text content
book_name = bookname.text.strip()
booknameoutput = book_name
pd = []
publishdates = soup.find_all(class_="col-8 col-sm-9 mb-1")
for publishdate in publishdates:
#print("Publish Date")
#Extract the book's name from the text content
publish_date = publishdate.text.strip()
PublishDateoutput = publish_date
pd.append(PublishDateoutput)
#DELETE ISBN ELEMENT 1 (Element '0')
pd.pop(0)
#DELETE ISBN ELEMENT 2 (When we have deleted isbn element 1, isbn element 2 is the new '0')
pd.pop(0)
#Replacing Unwanted Values in String
readlist = str(pd) #ENGLISH ALPHABET
readlist_NOLETTER = readlist.translate({ord(letter): None for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'})
readlist_NOSPACE = readlist_NOLETTER.replace("", "")
readlist_NOSYMBOL1 = readlist_NOSPACE.replace("'", "")
readlist_NOSYMBOL2 = readlist_NOSYMBOL1.replace(",", "")
readlist_NOSYMBOL3 = readlist_NOSYMBOL2.replace("[", "")
readlist_NOSYMBOL4 = readlist_NOSYMBOL3.replace("]", "")
readlist_NOSYMBOL5 = readlist_NOSYMBOL4.replace("n", "")
readlist_NOSYMBOL6 = readlist_NOSYMBOL5.replace(".", "")
readlist_OUTPUT = readlist_NOSYMBOL6
#Retrieve number from string
res = [str(i) for i in readlist_OUTPUT.split()]
res.pop(0)
PUBLISH_DATE_OUTPUT = str(res)
res_NOSYMBOL1 = PUBLISH_DATE_OUTPUT.replace("'", "")
res_NOSYMBOL2 = res_NOSYMBOL1.replace(",", "")
res_NOSYMBOL3 = res_NOSYMBOL2.replace("[", "")
res_NOSYMBOL4 = res_NOSYMBOL3.replace("]", "")
publishdateoutput = res_NOSYMBOL4
MLA8_BOOK_CITATION_OUTPUT = authornameoutput + ". " + booknameoutput + ". " + publishernameoutput + publishdateoutput + "."
#print("\n\n\n\n", MLA8_BOOK_CITATION_OUTPUT, "\n\n\n")
mla8_bookcite_result = MLA8_BOOK_CITATION_OUTPUT #"[LOG: " + dt_string + "]: \n\n" + "Citation Output: " + MLA8_BOOK_CITATION_OUTPUT + "\n\n\n" + "Raw Data: " + "\n" + str(readlist_OUTPUT) + "\n" + str(pd) + "\n"
#SHOW USERS ON-SCREEN:
T.delete("1.0","end")
T.insert(tk.END, mla8_bookcite_result)
#Open CSV ('a' option doesn't delete anything when it restarts...)
csv_citedate1 = today.strftime("%Y-%m-%d")
with open(filename, 'a', newline ='') as csvfile:
csvwriter = csv.writer(csvfile)
#Write citation details (Date, Citation, Type)
mla8_bookcite_csv = [[csv_citedate1,mla8_bookcite_result,typemlabook]]
#Write the details
csvwriter.writerows(mla8_bookcite_csv)
else:
res_sc = {response.status_code}
T.delete("1.0","end")
T.insert(tk.END, f"{response.status_code}")
e = "Failed to retrieve ISBN Number from isbnsearcher.com\nStatus code: " + str(res_sc) + "\nCitation Format: MLA 8 Book Citation\nUser Input: " + str(mwc_mla8_book)
writeerrorlog(str(e))
messagebox.showerror(title=f"Error: {response.status_code}", message=f"Failed to retrieve ISBN Number from 'isbnsearcher.com'\n Status code: {response.status_code}\n\nPossible Error Codes:\n\n404 - ISBN Number Not Found\n1020 - Access Denied (Check if a Proxy is open)")
click_btn4= PhotoImage(file=cwd_bt4)
b2 = tk.Button(image=click_btn4, command = mla8book, borderwidth=0, bg='#00FFFF', activebackground='#00FFFF')
b2.pack(pady=10)
"""
_ ____ _ _____ __ __ _ ____
/ \ | _ \ / \ |___ | \ \ / /__| |__ / ___| ___ _ __
/ _ \ | |_) / _ \ / / \ \ /\ / / _ \ '_ \ | | _ / _ \ '_ \
/ ___ \| __/ ___ \ / / \ V V / __/ |_) | | |_| | __/ | | |
/_/ \_\_| /_/ \_\ /_/ \_/\_/ \___|_.__/ \____|\___|_| |_|
____ _____ _ _____ __
| __ )| ____| | / _ \ \ / /
| _ \| _| | | | | | \ \ /\ / /
| |_) | |___| |__| |_| |\ V V /
|____/|_____|_____\___/ \_/\_/
"""
#Button 6 (APA 7 Website Citation)
def apa7web():
bt1()
apa7webwin = Toplevel(window)
apa7webwin.title("ezCite Version 2.0.0 - APA 7 Website Citation")
apa7webwin.geometry("1200x600")
apa7webwin.minsize(1200, 600)
apa7webwin.maxsize(1200, 600)
apa7webwin.configure(background='#3b3b4a')
Label(apa7webwin,text ="ezCite - APA 7 Website Citation Generator", bg='#3b3b4a', font=('Ubuntu Regular', 40), width=40, height=3, fg='#ffffff').pack()
Label(apa7webwin, text = 'Website (JSTOR is not supported)', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack()
entry = Entry(apa7webwin, font=('Ubuntu Regular',11))
entry.pack(ipadx= 400)
submit = Button(apa7webwin, image=click_btn_submit, command=lambda: get_apa7_web_citation(entry), borderwidth=0, bg='#00FFFF', activebackground='#00FFFF')
submit.pack(pady=30)
Label(apa7webwin, text = 'Citation Output (Copy&Paste Supported):', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack(pady=20)
T = Text(apa7webwin, height = 2, width = 105, font=('Ubuntu Regular', 18))
T.pack()
Label(apa7webwin, text = 'Note:\n If you forgot to Copy&Paste Your Citation, or want to copy 10 citations all together,then find the "ezcite_citations.csv" file in the directory(folder)\n that ezcite is in (Usually Desktop), then you will see a log of citations\n that you entered, with the output. :3', bg='#3b3b4a', font=('Ubuntu Regular', 17), fg='#ffffff').pack(pady=20)
def get_apa7_web_citation(entry):
try:
global mwc_apa7
mwc_apa7 = entry.get()
reqs = requests.get(mwc_apa7)
entry.delete(0, 'end')
T.delete("1.0","end")
#reqs.content or .text (MUST USE req.content here, FOR CHINESE SUPPORT! DO NOT, EVER, CHANGE IT!)
soup = BeautifulSoup(reqs.content, 'html.parser')
#Find website title
for title in soup.find_all('title'):
title.get_text()
websitetitle_apa_website = title.get_text()
link_apa_website = mwc_apa7
#Citation date shown on-screen
citedate_apa_website = today.strftime("%b %d, %Y,")
#Date recorded on CSV file
csv_citedate_apa_website = today.strftime("%Y-%m-%d")
#Put Citation together in a variable
apa7_webcite_result = "(n.d.). " + websitetitle_apa_website + "." + " Retrieved " + citedate_apa_website + " " + mwc_apa7
#Print result to-screen (CONSOLE, users won't see that)
print(apa7_webcite_result)
#SHOW USERS ON-SCREEN:
T.insert(tk.END, apa7_webcite_result)
#Open CSV ('a' option doesn't delete anything when it restarts...)
with open(filename, 'a', newline ='') as csvfile:
csvwriter = csv.writer(csvfile)
#Write citation details (Date, Citation, Type)
apa7_webcite_csv = [[csv_citedate_apa_website,apa7_webcite_result,typeapaweb]]
#Write the details
csvwriter.writerows(apa7_webcite_csv)
except requests.exceptions.MissingSchema:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc_apa7
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc_apa7 + "\n\nError Code: requests.exceptions.MissingSchema\n\nCause: No Website Headers \n\nFix: WEBSITE HEADERS MUST CONTAIN https:// OR http://!!!"
messagebox.showerror(title=f"Error:", message=msgboxerror)
except requests.exceptions.InvalidSchema:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc_apa7
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc_apa7 + "\n\nError Code: requests.exceptions.InvalidSchema\n\nCause: Incorrect Website Headers \n\nFix: Check Website Headers (https:// or http://)"
messagebox.showerror(title=f"Error:", message=msgboxerror)
except requests.exceptions.InvalidURL:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc_apa7
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc_apa7 + "\n\nError Code: requests.exceptions.InvalidURL\n\nCause: No URL Provided \n\nFix: Provide URL"
messagebox.showerror(title=f"Error:", message=msgboxerror)
except requests.exceptions.ConnectionError:
T.delete("1.0","end")
T.insert(tk.END, f"FAILED")
e = "Failed to retrieve Website Citation from: " + mwc_apa7
writeerrorlog(str(e))
msgboxerror = "Failed to retrieve Website Citation from:" + mwc + "\n\nError Code: requests.exceptions.ConnectionError\n\nCause: Incorrectly Entered Website Address or Cannot Connect to Website\n\nFix: Provide Correct URL or Check Internet Connection"
messagebox.showerror(title=f"Error:", message=msgboxerror)
click_btn5= PhotoImage(file=cwd_bt5)
b2 = tk.Button(image=click_btn5, command = apa7web, borderwidth=0, bg='#00FFFF', activebackground='#00FFFF')
b2.pack(pady=10)
"""
_ ____ _ _____ ____ _ ____
/ \ | _ \ / \ |___ | | __ ) ___ ___ | | __ / ___| ___ _ __
/ _ \ | |_) / _ \ / / | _ \ / _ \ / _ \| |/ / | | _ / _ \ '_ \
/ ___ \| __/ ___ \ / / | |_) | (_) | (_) | < | |_| | __/ | | |
/_/ \_\_| /_/ \_\ /_/ |____/ \___/ \___/|_|\_\ \____|\___|_| |_|
____ _____ _ _____ __
| __ )| ____| | / _ \ \ / /
| _ \| _| | | | | | \ \ /\ / /
| |_) | |___| |__| |_| |\ V V /
|____/|_____|_____\___/ \_/\_/
"""
#Button 7 (APA 7 Book Citation)
def apa7book():
bt1()
mla8bookwin = Toplevel(window)
mla8bookwin.title("ezCite Version 2.0.0 - APA 7 Book Citation")
mla8bookwin.geometry("1200x600")
mla8bookwin.minsize(1200, 600)
mla8bookwin.maxsize(1200, 600)
mla8bookwin.configure(background='#3b3b4a')
Label(mla8bookwin,text ="ezCite - APA 7 Book Citation Generator", bg='#3b3b4a', font=('Ubuntu Regular', 40), width=40, height=3, fg='#ffffff').pack()
Label(mla8bookwin, text = 'ISBN Number (Only enter 13 digit ISBN\'s)', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack()
entry = Entry(mla8bookwin, font=('Ubuntu Regular',11))
entry.pack(ipadx= 400)
submit = Button(mla8bookwin, image=click_btn_submit, command=lambda: get_apa7_book_citation(entry), borderwidth=0, bg='#3b3b4a', activebackground='#3b3b4a')
submit.pack(pady=30)
Label(mla8bookwin, text = 'Citation Output (Copy&Paste Supported):', bg='#3b3b4a', font=('Ubuntu Regular', 24), fg='#ffffff').pack(pady=20)
T = Text(mla8bookwin, height = 2, width = 105, font=('Ubuntu Regular', 18))
T.pack()
Label(mla8bookwin, text = 'Note:\n If you forgot to Copy&Paste Your Citation, or want to copy 10 citations all together,then find the "ezcite_citations.csv" file in the directory(folder)\n that ezcite is in (Usually Desktop), then you will see a log of citations\n that you entered, with the output. :3', bg='#3b3b4a', font=('Ubuntu Regular', 17), fg='#ffffff').pack(pady=20)
def get_apa7_book_citation(entry):
mwc_apa7_book = entry.get()
isbn1 = "https://www.isbnsearcher.com/books/" + mwc_apa7_book
response = requests.get(isbn1, mwc_apa7_book)
# datetime object containing current date and time
now = datetime.now()
authornameoutput = ""
if response.status_code == 200:
# Parse the HTML content using BeautifulSoup
html_content = response.content
soup = BeautifulSoup(html_content, 'html.parser')
AN = []
AN2 = []
# Find all the elements with class name "text-success"
authors = soup.find_all(class_="text-success")
for author in authors:
if "author" in str(author):
print("AUTHOR NAME IN TEXT-SUCCESS")
# Extract the author's name from the text content
author_name = author.text.strip()
# Reverse the order of the name parts (if applicable)
name_parts = author_name.split()
if len(name_parts) > 1:
author_LAST_name = name_parts[-1]
AN.append(author_LAST_name)
author_FIRST_name = "".join(name_parts[:-1])
AN.append(author_FIRST_name)
# test the remove_middle_name function
# name_with_middle = author_name
#name_without_middle = remove_middle_name(name_with_middle)
#print(name_with_middle) # "John Michael Smith"
#Put author name in 'AN' list
print(AN)
#authornameoutput = AN
#print(authornameoutput)
# dd/mm/YY H:M:S
# datetime object containing current date and time
now = datetime.now()
dt_string = now.strftime("%Y/%m/%d %H:%M:%S")
break
else:
print("AUTHOR NAME NOT IN TEXT-SUCCESS")
authors = soup.find_all(class_="col-8 col-sm-9 mb-1")[-1]
for author in authors:
# Extract the author's name from the text content
author_name = author.text.strip()
# Reverse the order of the name parts (if applicable)
name_parts = author_name.split()
if len(name_parts) > 1:
author_LAST_name = name_parts[-1]
#Put Author name into List "AN2" (For APA7 Citation Format : Last Name, First Name Letter)
AN2.append(author_LAST_name)
time.sleep(0.5)
author_FIRST_name = "".join(name_parts[:-1])
AN2.append(author_FIRST_name)
# test the remove_middle_name function
name_with_middle = author_name
#name_without_middle = remove_middle_name(name_with_middle)
print(name_with_middle) # "John Michael Smith"
#authornameoutput = name_without_middle