-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHarvardRefGen.py
2134 lines (1826 loc) · 124 KB
/
HarvardRefGen.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
"""
Manchester Harvard Reference Generator
This code will create GUI windows to select a source to format in Manchester Harvard
Reference style. Fields will be created to enter the appropriate information. When genereate
reference is chosen the code will append a file called references.docx with numbered and
formatted references generated from the inputs. Ensure the file is not open while attempting
to generate references. Also ensure you follow the example entry formatting, only putting
punctuation if shown in the example input and capitalising as shown in the example input
to make the output correctly formatted.
ISBN search is a trial feature that allows you to search the ISBN of a book and the software
will attempt to autofill the formatted values. This will not always be 100% accurate so it
is recommended that you check the fetched data to ensure it is accurate and correctly
formatted for use in generating the reference. Data is fetched from google books and
formatted before entry but if the google books metadata is incorrectly stored online then
formatting will not be correct. This feature requires internet connection to function.
A lot of this code is very repetitive in functions so one example of each will be fully
commented to explain proccesses but in interest of comment efficiency not all will be.
Joshua Utting
30/08/2019
"""
#imports list
from tkinter import *
from docx import Document
from docx.shared import Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
from bs4 import BeautifulSoup
import requests
import numpy as np
from PIL import Image,ImageTk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
try: #attempt to open a file called references.docx
document = Document('references.docx')
length = len(document.paragraphs) #if file opens find the number of paragraphs (i.e. references)
count = length #set count to start from one after the last number in the list
except:
document = Document() #if file does not exist create a new file
count=0 #set count to 0 to start reference numbering from 1
#define word document text style as Times New Roman 12pt
style = document.styles['Normal']
font = style.font
font.name = 'Times New Roman'
font.size = Pt(12)
def hasNumbers(inputString):
return any(char.isdigit() for char in inputString) #check if there is a number in the inputstring
def suffix(d):
return 'th' if 11<=d<=13 else {1:'st',2:'nd',3:'rd'}.get(d%10, 'th') #for the edition number find the appropriate suffix
#function to search an entered isbn number and autofill the form basedon webscraped data
def isbnsearch(isbnvar,authorvar,yearvar,titlevar,subtitlevar,editionvar,pubplacevar,publishervar):
try:
isbn = isbnvar.get() #get isbn entry
url = 'https://isbndb.com/book/' + isbn #specify the url to search
#attempt to access the webpage containing information using headers to make site think browser is accessing
response = requests.get(url, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html1 = response.text #store the source code of the page as a string
soup = BeautifulSoup(html1, 'html.parser') #parse the string using a html parser
edition = '' #define edition blank by default
subtitle = '' #define subtitle blank by default
labels = soup.find_all('tr') #find rows of info
for i in range(0,len(labels)):
#if the row containts the words 'Full Title' split the row to extract title info, also if there is a subtitle split
#the title where subtitle begins and update subtitle value, else it will be left blank
if('Full Title ' in labels[i].text):
splitup = labels[i].text.split('Full Title')
title = ' '.join(splitup[1:])
title = title.strip()
title = title.capitalize()
if(':' in title):
newsplit = title.split(':')
title = newsplit[0]
subtitle = newsplit[1]
subtitle = subtitle.strip()
subtitle = subtitle.lower()
#if the row containts the words 'Publisher' split the row to extract publisher
elif('Publisher ' in labels[i].text):
splitup = labels[i].text.split('Publisher ')
publisher = ' '.join(splitup[1:])
publisher = publisher.strip()
#if the row containts the words 'Authors' split the row to extract authors info
elif('Authors ' in labels[i].text):
splitup = labels[i].text.split('Authors ')
string = ' '.join(splitup[1:])
string = string.rstrip()
splitup = string.strip('\n')
splitup = splitup.replace('\n',',')
splitup = splitup.strip()
authors = splitup.split(',')
#if the row containts the words 'Edition' split the row to extract edition info
elif('Edition ' in labels[i].text):
splitup = labels[i].text.split('Edition ')
string = ' '.join(splitup[1:])
ending = suffix(int(string))
edition = str(string+ending)
edition = edition.replace(' ','')
edition = edition+' edn'
edition = edition.strip()
#if the row containts the words 'Publish Date' split the row to extract publish date info
elif('Publish Date ' in labels[i].text):
splitup = labels[i].text.split('Publish Date ')
publishdate = ' '.join(splitup[1:])
publishdate = publishdate.strip()
else:
pass
#if edition is still blank default to first edition
if(edition == ''):
edition = '1st edn'
else:
pass
#check how many authors there are and format authors list accordingly
if(len(authors)==1): #if there is one split their name up and store in format Surname, Initial.
split = authors[0].split(' ')
final = len(split)
surname = split[final-1]
firstname = split[0]
initial = firstname[0]+'.'
formattedauthors = surname+', '+initial
elif(len(authors)==2): #if there is two split their names up and store in format Surname, Initial. and Surname, Initial.
split = authors
author1 = split[0]
author2 = split[1]
author1 = author1.split(' ')
author2 = author2.split(' ')
final1 = len(author1)
final2 = len(author2)
surname1 = author1[final1-1]
surname2 = author2[final2-1]
firstname1 = author1[0]
firstname2 = author2[0]
initial1 = firstname1[0]+'.'
initial2 = firstname2[0]+'.'
formattedauthors = surname1+', '+initial1+' and '+surname2+', '+initial2
elif(len(authors)>=3): #if there is three split their names up and store in format Surname, Initial.,... and Surname, Initial.
formattedauthors = ''
split = authors
for i in range(0,len(split)):
newauthor = split[i]
subsplit = newauthor.split(' ')
final = len(subsplit)
surname = subsplit[final-1]
firstname = subsplit[0]
initial = firstname[0]+'.'
if(i<len(split)-1):
formattedauthors = formattedauthors+surname+', '+initial+', '
else:
formattedauthors = formattedauthors+'and '+surname+', '+initial
try: #try and find the publisher location from their wikipedia page
pubsearch = publisher #last unfound value is publisher location not found on about page, store a copy incase of fail
pubsearch = pubsearch.replace(' ','_') #replace any spaces in publisher string with _
url='https://en.wikipedia.org/wiki/'+pubsearch #store url string as wikipedia page of publisher
#send request to the site also sending a header to be treated as a headed browser
response = requests.get(url, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html4 = response.text #store page source as string
soup = BeautifulSoup(html4, 'html.parser') #parse string with html parser
results2 = soup.find("td",attrs={"class":"label"}) #find all instances of td tag with the class label
place = results2.text #get the text of the contents of this tag for the publisher location
newplace = place.split(',') #split publisher location on comma as it will usually give format city,state,country
pubplace = newplace[0] #store publisher location as city element
except: #if wikipedia fails try and extract from google
try: #search google and attempt to find publisher location from default search page
url = 'https://google.com/search?q='+publisher
response = requests.get(url, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html5 = response.text #store page source as string
soup = BeautifulSoup(html5, 'html.parser') #parse string with html parser
tablevals = soup.find_all('a',attrs={'class':'fl'})
for i in range(0,len(tablevals)):
if(tablevals[i].text=='Headquarters'):
pubplace = tablevals[i+1].text
break
else:
pass
except: #if this fails store publisher location as blank
pubplace = '' #if fails store publisher location as blank
try:
titlevar.set(title) #set the title variable of entry form to the title string
except:
pass
try:
yearvar.set(publishdate) #set the year variable of entry form to the year string
except:
pass
try:
authorvar.set(formattedauthors) #set the author variable of the entry form to the formattedauthor string
except:
pass
try:
editionvar.set(edition) #set the edition variable of the entry field to the edition string
except:
pass
try:
publishervar.set(publisher) #set the publisher variable of the entry field to the publisher string
except:
pass
try:
subtitlevar.set(subtitle) #set the subtitle variable of the entry field to the subtitle string
except:
pass
try:
pubplacevar.set(pubplace) #set the publisher location variable of the entry field to the pubplace string
except:
pass
except: #if improved method of isbn search fails revert to old method
try: #provide a catch if this fails anywhere
a = np.array([]) #create array of links
isbn = isbnvar.get() #get the entered isbn string
urlstring = ('https://www.google.com/search?tbm=bks&q=' + isbn) #use url of google book search of isbn value
#send request to the site also sending a header to be treated as a headed browser
response = requests.get(urlstring, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html1 = response.text #store the source code of the page as a string
soup = BeautifulSoup(html1, 'html.parser') #parse the string using a html parser
results = soup.find_all("div",attrs={"class":"r"}) #find all div tags with the class r (this tag stores results of search)
for result in results:
links = result.find_all('a') #find any instance of a link tag in each result of first search
for link in links:
a = np.append(a,link.get('href')) #for each tag store the link string
for i in range(0,a.size-1): #search the array of links
if(isbn in str(a[i])):
linkno = i #if the searched isbn is in the link then store which link to use, used to skip ads
break #break loop when found
else:
pass
bookurl = a[linkno] #store new url string as link to the book's page on google books
#send request to the site also sending a header to be treated as a headed browser
bookresponse = requests.get(bookurl, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html2 = bookresponse.text #store the source code of this page as a string
soup = BeautifulSoup(html2, 'html.parser') #parse this string using a html parser
try: #check to see if in the about page of the book or on the first page, need about page for metadata
results1 = soup.find('a',attrs={'id':'sidebar-atb-link'}) #search for any links stored in a sidebar, should not find any if on about page
newlink = results1.get('href') #if instance found of sidebar link get the link of this about page
#send request to the site also sending a header to be treated as a headed browser
bookresponse2 = requests.get(newlink, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html3 = bookresponse2.text #store the source code of this page as a string
soup = BeautifulSoup(html3, 'html.parser') #parse the string using a html parser
except:
soup = BeautifulSoup(html2, 'html.parser') #if on the about page already parse the original page using html parser
results = soup.find_all('td',attrs={'class':'metadata_label'}) #search for all td tags with class metadata_label
metadatalabels = np.array([]) #create empty array of metadatalabels
metadatavalues = np.array([]) #create empty array of metadatavalues
for result in results:
metadatalabels = np.append(metadatalabels,result.text) #store the text of all metadatalabels in array
metadatalabels = metadatalabels[:-1] #remove final label (export citation label)
results = soup.find_all('td',attrs={'class':'metadata_value'}) #search for all td tags with class metadata_value
for result in results:
datavals = result.find_all('span',attrs={'dir':'ltr'}) #search for all span tags with dir=ltr in these td classes
for val in datavals:
metadatavalues = np.append(metadatavalues,(val.text)) #store the text of the metadatavalues in array
metadatavalues = metadatavalues[:-3] #remove the last three metadatavalues (three options to export citation)
for i in range(0,len(metadatavalues)-1): #loop through metadatavalues
if(hasNumbers(metadatavalues[i])==True): #if numbers in element
attempt = metadatavalues[i].split(',') #try splitting the element by comma
attempt[1] = attempt[1].lstrip() #remove the white space at the start of second element
if(len(attempt[1])==4): #if the second element of the attempt is a year
success = i #store the value
break #break loop
else:
pass
else:
pass
if('Edition' not in metadatalabels): #if edition is missing
metadatalabels = metadatalabels[:-3] #remove the next three metadatalabels
metadatavalues = metadatavalues[0:success+1] #replace metadatavalues with values from 0 to the success count
else: #if edition is present
metadatalabels = metadatalabels[:-2] #remove the next two metadatalabels
metadatavalues = metadatavalues[0:success+1] #replace metadatavalues with values from 0 to the success count
if(len(metadatalabels)==3): #check if 3 labels, meaning eidtion not found
numauthors = int(len(metadatavalues)-len(metadatalabels)+1) #number of authors is the difference between the number of values and number of labels + 1
#extra note on above: author is the only one to have multiple values for a single label hence subtitution method works
title = str(metadatavalues[0]).lower() #set title variable as the first metadatavalue in lowercase
title = title.capitalize() #capitalize first letter of title
if(':' in title): #check to see if there is a semicolon in the title (indicating subtitle)
title2 = title.split(':') #split the title at the semicolon
title = title2[0] #overwrite title as the first element of the split
subtitle = str(title2[1]).lower() #store subtitle as second element of split in lowercase
subtitle = subtitle.lstrip() #remove the space at the start of the subtitle string
else:
subtitle='' #if no colon set subtitle as blank
authors = metadatavalues[1:numauthors+1] #set authors as the second metadatavalue to the element of number of authors + 1 (as the array started from 0)
edn = '' #set edition as blank as it is not listed
pubandyear = metadatavalues[numauthors+1] #publisher and year listed in the same value, set this as the element after authors as edition tag is missing
try:
pubyearsplit = pubandyear.split(',') #attempt to split the publisher and published year by the comma
publisher = pubyearsplit[0] #set the publisher as the first element of the split
year = pubyearsplit[1].lstrip() #set the published year as the second element of the strip removing space at start
except:
publisher = pubandyear #if fails set publisher to the original metadatavalue
year='' #set year to blank
else: #if there is not 6 metadatalabels (empirically means there will be 7)
for i in range(0,len(metadatavalues)): #complicated loop process over the number of metadatavalues
if(metadatavalues[i]=='illustrated' or hasNumbers(metadatavalues[i])==True): #empirically the edition will always be listed as illustrated or be the first tag to have a number in it and will be the tag after authors
#continuation of above: as a results this value can be used to determine the number of authors
numauthors = int(len(metadatavalues[1:i])) #number of authors is the number of metadatavalues after title and beofre this edition value
title = str(metadatavalues[0]).lower() #set title as the first metadatavalue in lowercase
title = title.capitalize() #capitalize first letter of title string
if(':' in title): #check to see if there is a semicolon in the title (indicating subtitle)
title2 = title.split(':') #split the title at the semicolon
title = title2[0] #overwrite title as the first element of the split
subtitle = str(title2[1]).lower() #store subtitle as second element of split in lowercase
subtitle = subtitle.lstrip() #remove the space at the start of the subtitle string
else:
subtitle='' #if no colon set subtitle as blank
authors = metadatavalues[1:numauthors+1] #set authors as the second metadatavalue to the element of number of authors + 1 (as the array started from 0)
print(authors)
edn = metadatavalues[numauthors+1] #set edition as the metadatavalue following the final author
try: #check a case for if the edition has a number and unrelated text string like 'illustrated'
splitup = edn.split(',') #these options will be comma separated so split at a comma
for i in range(0,len(splitup)): #loop over number of items in split
if(hasNumbers(splitup[i])==True): #check if the element has a number in it
edn = splitup[i] #if yes store edition as the text of that element from the splitup (now a number)
break #break loop to carry on
else:
pass
try:
ending = suffix(int(edn)) #find a suffix for the edition based on the suffix function (e.g. th,nd,rd)
edn = edn+ending+' edn' #store edition as the number plus suffic plus ' edn'
except:
edn = '1st edn' #if edition still came back as illustrated replace it with 1st edition
except:
pass #if this check fails leave as the scraped value
pubandyear = metadatavalues[numauthors+2] #store variable publisher and published year as metadatavalues from the final author + 2
try:
pubyearsplit = pubandyear.split(',') #attempt to split publisher and published year string at comma as they are comma separated
publisher = pubyearsplit[0] #set publisher as first element of the split
year = pubyearsplit[1].lstrip() #set published year as the second element of the split and remove space at start of string
except:
publisher = pubandyear #if fails store publisher as the original scraped string
year='' #set year to blank
else:
pass
break #break the loop as all useful values are stored somewhere now
else:
pass #if not on edition value then pass
newauthor = [] #set blank list for formatted authors
if(numauthors==1): #if there is 1 author
try:
authorslist = authors #store a copy incase of fail
author1 = str(authorslist[0]).split(' ') #split the author string by space to get name split in to elements
l1 = len(author1) #store number of elements in author name
newauthor.append(author1[l1-1]+ ', ' + author1[l1-2][0]+'.') #append newauthor list as '[author surname], [intiial].'
formattedauthor = newauthor[0] #set formattedauthor as the first element of newauthor
except:
formattedauthor = authors #if fails store formnattedauthor as scraped author value
elif(numauthors==2): #if there is 2 authors
try:
authorslist = authors #store a copy incase of fail
author1 = str(authorslist[0]).split(' ') #split the first author's name in list by space
l1 = len(author1) #store number of elements in first author name
author2 = str(authorslist[1]).split(' ') #split the second author's name in list by space
l2 = len(author2) #store number of elements in second author name
newauthor.append(author1[l1-1]+ ', ' + author1[l1-2][0]+'.') #append newauthor list as '[author 1 surname], [intiial].'
newauthor.append(author2[l2-1]+ ', ' + author2[l2-2][0]+'.') #append newauthor list as '[author 2 surname], [intiial].'
formattedauthor = newauthor[0]+' and '+newauthor[1] #store formatted author as first element of newauthor ' and ' second element of newauthor
except:
formattedauthor=authors #if fails store formattedauthor as scraped author value
elif(numauthors>=3): #if 3 or more authors
try:
formattedauthor='' #try setting formattedauthor blank
authorslist = authors #store a copy incase of fail
alist = [] #create authorlist
lt = [] #create author name length list
for i in range(0,numauthors): #loop over the number of authors
alist.append(str(authorslist[i]).split(' ')) #append author list with space split author names
lt.append(len(str(authorslist[i]).split(' '))) #append author name length list with number of elements in author name
newauthor.append(alist[i][lt[i]-1]+', '+alist[i][lt[i]-2][0]+'.') #append newauthor with each '[author surname], [intial].'
for i in range(0,len(newauthor)-1): #loop over all but the final author
formattedauthor = formattedauthor+str(newauthor[i])+', ' #add each new author to formattedauthor string with a comma and space after
formattedauthor = str(formattedauthor).rstrip(', ')+' and '+str(newauthor[len(newauthor)-1]) #to finish the string remove the last ', ' and replace with ' and ' [final newauthor element]
except:
formattedauthor = authors #if fails store formattedauthor as scraped authos value
try:
pubsearch = publisher #last unfound value is publisher location not found on about page, store a copy incase of fail
pubsearch = pubsearch.replace(' ','_') #replace any spaces in publisher string with _
url='https://en.wikipedia.org/wiki/'+pubsearch #store url string as wikipedia page of publisher
#send request to the site also sending a header to be treated as a headed browser
response = requests.get(url, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
html4 = response.text #store page source as string
soup = BeautifulSoup(html4, 'html.parser') #parse string with html parser
results2 = soup.find("td",attrs={"class":"label"}) #find all instances of td tag with the class label
place = results2.text #get the text of the contents of this tag for the publisher location
newplace = place.split(',') #split publisher location on comma as it will usually give format city,state,country
pubplace = newplace[0] #store publisher location as city element
except:
try:
url = 'https://google.com/search?q='+publisher
response = requests.get(url, headers={'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'})
#print('here')
html5 = response.text #store page source as string
soup = BeautifulSoup(html5, 'html.parser') #parse string with html parser
tablevals = soup.find_all('a',attrs={'class':'fl'})
for i in range(0,len(tablevals)):
#print(tablevals[i].text)
if(tablevals[i].text=='Headquarters'):
pubplace = tablevals[i+1].text
break
else:
pass
except:
pubplace = '' #if fails store publisher location as blank
try:
titlevar.set(title) #set the title variable of entry form to the title string
except:
pass
try:
yearvar.set(year) #set the year variable of entry form to the year string
except:
pass
try:
authorvar.set(formattedauthor) #set the author variable of the entry form to the formattedauthor string
except:
pass
try:
editionvar.set(edn) #set the edition variable of the entry field to the edn string
except:
pass
try:
publishervar.set(publisher) #set the publisher variable of the entry field to the publisher string
except:
pass
try:
subtitlevar.set(subtitle) #set the subtitle variable of the entry field to the subtitle string
except:
pass
try:
pubplacevar.set(pubplace) #set the publisher location variable of the entry field to the pubplace string
except:
pass
except: #if isbn search has failed
isbnfail = Tk() #open a tkinter window
#create text label informing search has failed and to try again, pack in window
infolabel = Label(isbnfail,text='ISBN not found. If this is your first time seeing this message please try again.\nTry with and without a hyphen after the first three digits.\nEnsure that you try both the ISBN-13 and ISBN-10 code for the book as one usually works if the other does not.\nIf the problem persists through both this ISBN is not compatible with the search and will have to be entered manually.').pack()
okbutton = Button(isbnfail,text='Ok',command=lambda: isbnfail.destroy()).pack() #create ok button to close window and pack in window
isbnfail.mainloop() #keep window displaying
def searchreferences(referenceframe,searchterms):
global archivevar
searchtermvals = searchterms.get()
words = searchtermvals.split(' ')
file = open('archivedreferences.csv','r')
lines = []
for line in file:
splitup = line.split(',',1)
lines.append([splitup[0],splitup[1]])
file.close()
score = [0]*len(lines)
for i in range(0,len(lines)):
lines[i][0] = lines[i][0].split(',',1)
for j in range(0,len(words)):
if(words[j] in lines[i][1]):
score[i]+=1
else:
pass
matches = []
for i in range(0,len(score)):
if(score[i]>0):
matches.append([score[i],lines[i][0],lines[i][1]])
if(matches!=[]):
sortedlist = sorted(matches,key=lambda x: x[0])
else:
if(referenceframe.grid_slaves(row=3,column=0)!=[]):
referenceframe.grid_slaves(row=3,column=0)[0].grid_forget()
else:
pass
if(referenceframe.grid_slaves(row=2,column=2)!=[]):
referenceframe.grid_slaves(row=2,column=2)[0].grid_forget()
else:
pass
if(referenceframe.grid_slaves(row=2,column=1)!=[]):
referenceframe.grid_slaves(row=2,column=1)[0].grid_forget()
else:
pass
if(referenceframe.grid_slaves(row=2,column=0)!=[]):
referenceframe.grid_slaves(row=2,column=0)[0].grid_forget()
else:
pass
failedlabel = Label(referenceframe,text='No Results Found').grid(row=2,column=1)
return
for sublist in sortedlist:
del sublist[0]
for i in range(0,len(sortedlist)):
try:
sortedlist[i] = [sortedlist[i][0][0],sortedlist[i][1]]
except:
pass
if(referenceframe.grid_slaves(row=3,column=0)!=[]):
referenceframe.grid_slaves(row=3,column=0)[0].grid_forget()
else:
pass
if(referenceframe.grid_slaves(row=2,column=2)!=[]):
referenceframe.grid_slaves(row=2,column=2)[0].grid_forget()
else:
pass
if(referenceframe.grid_slaves(row=2,column=1)!=[]):
referenceframe.grid_slaves(row=2,column=1)[0].grid_forget()
else:
pass
if(referenceframe.grid_slaves(row=2,column=0)!=[]):
referenceframe.grid_slaves(row=2,column=0)[0].grid_forget()
else:
pass
choices = sortedlist
archivevar = StringVar()
archivevar.set(choices[0])
droplabel = Label(referenceframe,text='Results: ').grid(row=2,column=0) #define label for drop menu and pack it to the first row and first column
dropmenu = OptionMenu(referenceframe,archivevar,*choices)
dropmenu.grid(row=2,column=1) #define drop down menu with the previously defined choices and pack to first row and second column
dropmenu.config(wraplength=500)
choiceconfirmbutton = Button(referenceframe,text='Confirm',command=lambda: genfromarchive(referenceframe)).grid(row=2,column=2)
def genfromarchive(referenceframe):
global count, archivevar
count+=1
archivevarget = archivevar.get()
archivedargs = archivevarget.strip(')')
archivedargs = archivedargs.strip('(')
splitup = archivedargs.split(',',1)
splitup = splitup[1].rstrip()
referencestring = str(splitup[2:-3])
if('*' in referencestring):
referencestring = referencestring.split('*')
p = document.add_paragraph("[%s] " % count) #add a new paragraph to document starting with count value e.g reference [3]
p.style = document.styles['Normal'] #write paragraph in previously defined font style
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
for i in range(0,len(referencestring)):
if(i%2==0):
p.add_run(referencestring[i])
else:
p.add_run(referencestring[i]).italic = True
document.save('references.docx')
else:
p = document.add_paragraph("[%s] " % count) #add a new paragraph to document starting with count value e.g reference [3]
p.style = document.styles['Normal'] #write paragraph in previously defined font style
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run(referencestring)
document.save('references.docx')
success = Label(referenceframe,text=('Reference [%s] Successfully Generated' % count)).grid(row=3,column=0,columnspan=3) #create a label at the bottom of the window informing reference [number] added successfully
#define function to get the choice from the drop down and call the appropriate reference window
def getchoice(*choices):
global reftpyechoice, reftypevar, count, searchframe
reftypechoice = reftypevar.get() #get the value of the drop down
searchframe.destroy()
if(reftypechoice=='Book'): #if the value is book etc.
bookwin() #call the bookwindow function to show the entry fields for a book etc
elif(reftypechoice=='Website'):
webwin()
elif(reftypechoice=='Journal (printed)'):
journal1win()
elif(reftypechoice=='Journal (electronic)'):
journal2win()
elif(reftypechoice=='Lecturer Handout'):
lechandoutwin()
elif(reftypechoice=='Thesis'):
thesiswin()
elif(reftypechoice=='Presentation'):
presentwin()
elif(reftypechoice=='Chapter From Edited Book'):
editbookchapterwin()
elif(reftypechoice=='Edited Book'):
editedbookwin()
elif(reftypechoice=='Software'):
softwarewin()
elif(reftypechoice=='Illustration'):
illustrationwin()
elif(reftypechoice=='E-Book'):
ebookwin()
elif(reftypechoice=='Report From Organisation'):
organisationreportwin()
elif(reftypechoice=='Self-Citation'):
selfcitationwin()
elif(reftypechoice=='Government/Corporate Publications'):
govpubswin()
elif(reftypechoice=='Custom'):
customwin()
#define the book genating reference function
#these generation functions are called by the relevant sourcewin functions below, e.g. bookwin()
def bookgen(authorstring,yearstring,titlestring,subtitlestring,editionstring,pubplacestring,publisherstring,referenceframe):
global count
count=count+1 #add one to the count to increase the number in the reference list
#get the values of each of the inputs of the book window entry fields
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
subtitle = subtitlestring.get()
edition = editionstring.get()
pubplace = pubplacestring.get()
publisher = publisherstring.get()
if(subtitle!=''): #check if there has been an entry in the subtitle window, if so:
newsubtitlestring = subtitle + '.' #add full stop to the end of subtitle
subtitle = newsubtitlestring #overwrite subtitle
newtitlestring = title + ': ' #add colon to the end of title
title = newtitlestring+subtitle #new title is in format title: subtitle.
else:
newtitlestring = title + '.' #if subtitle is empty add full stop to the end of title
title = newtitlestring #new title is in format title.
p = document.add_paragraph("[%s] " % count) #add a new paragraph to document starting with count value e.g reference [3]
p.style = document.styles['Normal'] #write paragraph in previously defined font style
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY #justify aligning of paragraph as per required for UoM reports
p.add_run("%s (%s). " % (author,year)) #add the title and year in brackets to the reference
p.add_run(title).italic = True #add the title to the paragraph in italics
p.add_run(" %s. %s: %s." % (edition,pubplace,publisher)) #add the edition. publishier location: publisher name. to the paragraph
document.save('references.docx') #save the appending to references.docx
file = open('archivedreferences.csv','a')
referencestring = "Book,%s (%s). *%s* %s. %s: %s.\n" % (author,year,title,edition,pubplace,publisher)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=9,column=0,columnspan=2) #create a label at the bottom of the window informing reference [number] added successfully
#define the web reference generating function
#works as bookgen but all formatting matches that required for websites
def webgen(authorstring,yearstring,titlestring,urlstring,accessstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
url = urlstring.get()
access = accessstring.get()
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). " % (author,year))
p.add_run(title).italic = True
p.add_run(". Available at: %s, (Accessed: %s)." % (url,access))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Website,%s (%s). *%s*. Available at: %s, (Accessed: %s).\n" % (author,year,title,url,access)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=8,column=0,columnspan=2)
#define the printed journal reference generating function
#works as bookgen but all formatting matches that required for printed journals
def journal1gen(authorstring,yearstring,titlearticlestring,titlestring,volumestring,issuestring,pagestring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
titlearticle = titlearticlestring.get()
title = titlestring.get()
volume = volumestring.get()
issue = issuestring.get()
page = pagestring.get()
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). ‘%s’, " % (author,year,titlearticle))
p.add_run(title).italic = True
p.add_run(", %s(%s), pp. %s." % (volume,issue,page))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Printed Journal,%s (%s). ‘%s’, *%s*, %s(%s), pp. %s.\n" % (author,year,titlearticle,title,volume,issue,page)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=8,column=0,columnspan=2)
#define the electronic journal reference generating function
#works as bookgen but all formatting matches that required for electronic journals
def journal2gen(authorstring,yearstring,titlearticlestring,titlestring,volumestring,issuestring,pagestring,urlstring,accessstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
titlearticle = titlearticlestring.get()
title = titlestring.get()
volume = volumestring.get()
issue = issuestring.get()
page = pagestring.get()
url = urlstring.get()
access = accessstring.get()
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). ‘%s’, " % (author,year,titlearticle))
p.add_run(title).italic = True
p.add_run(", %s(%s), pp. %s. [Online]. Available at: %s (Accessed: %s)." % (volume,issue,page,url,access))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Electronic Journal,%s (%s). ‘%s’, *%s*, %s(%s), pp. %s. [Online]. Available at: %s (Accessed: %s).\n" % (author,year,titlearticle,title,volume,issue,page,url,access)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=10,column=0,columnspan=2)
#define the lecturer handout reference generating function
#works as bookgen but all formatting matches that required for lecturer handouts
def lechandoutgen(authorstring,yearstring,titlestring,codestring,modtitlestring,institutionstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
code = codestring.get()
modtitle = modtitlestring.get()
institution = institutionstring.get()
unitname = code + ': ' + modtitle
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). ‘%s’, " % (author,year,title))
p.add_run(unitname).italic = True
p.add_run(". %s. Unpublished." % (institution))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Lecturer Handout,%s (%s). ‘%s’, *%s*. %s. Unpublished.\n" % (author,year,title,unitname,institution)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=7,column=0,columnspan=2)
#define the thesis reference generating function
#works as bookgen but all formatting matches that required for theses
def thesisgen(authorstring,yearstring,titlestring,levelstring,institutionstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
level = levelstring.get()
institution = institutionstring.get()
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). " % (author,year))
p.add_run(title).italic = True
p.add_run(". %s. %s." % (level,institution))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Thesis,%s (%s). *%s*. %s. %s.\n" % (author,year,title,level,institution)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=6,column=0,columnspan=2)
#define the presentation reference generating function
#works as bookgen but all formatting matches that required for presentations
def presentgen(authorstring,yearstring,titlestring,codestring,modtitlestring,urlstring,accessstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
code = codestring.get()
modtitle = modtitlestring.get()
url = urlstring.get()
access = accessstring.get()
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). " % (author,year))
p.add_run(title).italic = True
p.add_run(" [presentation]. ")
p.add_run("%s: %s" % (code,modtitle)).italic = True
p.add_run(". Available at: %s (Accessed: %s)." % (url,access))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Presentation,%s (%s). *%s*. [presentation]. *%s: %s*. Available at: %s (Accessed: %s).\n" % (author,year,title,code,modtitle,url,access)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=8,column=0,columnspan=2)
#define the edited book reference generating function
#works as bookgen but all formatting matches that required for edited books
def editbookchaptergen(authorstring,yearstring,chapterstring,editorstring,titlestring,subtitlestring,pubplacestring,publisherstring,pagesstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
chapter = chapterstring.get()
editor = editorstring.get()
title = titlestring.get()
subtitle = subtitlestring.get()
pubplace = pubplacestring.get()
publisher = publisherstring.get()
pages = pagesstring.get()
noeds = int((1+len(editor.split(',')))/2)
if(noeds>=2):
edoreds = 'eds'
else:
edoreds = 'ed'
if(subtitle!=''): #check if there has been an entry in the subtitle window, if so:
newsubtitlestring = subtitle + '.' #add full stop to the end of subtitle
subtitle = newsubtitlestring #overwrite subtitle
newtitlestring = title + ': ' #add colon to the end of title
title = newtitlestring+subtitle #new title is in format title: subtitle.
else:
newtitlestring = title + '.' #if subtitle is empty add full stop to the end of title
title = newtitlestring #new title is in format title.
p = document.add_paragraph("[%s] " % count) #add a new paragraph to document starting with count value e.g reference [3]
p.style = document.styles['Normal'] #write paragraph in previously defined font style
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY #justify aligning of paragraph as per required for UoM reports
p.add_run("%s (%s). '%s', in %s (%s.) " % (author,year,chapter,editor,edoreds)) #add the title and year in brackets to the reference
p.add_run(title).italic = True #add the title to the paragraph in italics
p.add_run(" %s: %s, pp %s." % (pubplace,publisher,pages)) #add the edition. publishier location: publisher name. to the paragraph
document.save('references.docx') #save the appending to references.docx
file = open('archivedreferences.csv','a')
referencestring = "Chapter From An Edited Book,%s (%s). '%s', in %s (%s.) *%s* %s: %s, pp %s.\n" % (author,year,chapter,editor,edoreds,title,pubplace,publisher,pages)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=11,column=0,columnspan=2) #create a label at the bottom of the window informing reference [number] added successfully
def editedbookgen(authorstring,yearstring,titlestring,subtitlestring,editionstring,pubplacestring,publisherstring,referenceframe):
global count
count=count+1 #add one to the count to increase the number in the reference list
#get the values of each of the inputs of the book window entry fields
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
subtitle = subtitlestring.get()
edition = editionstring.get()
pubplace = pubplacestring.get()
publisher = publisherstring.get()
noeds = int((1+len(author.split(',')))/2)
if(noeds>=2):
edoreds = 'eds'
else:
edoreds = 'ed'
if(subtitle!=''): #check if there has been an entry in the subtitle window, if so:
newsubtitlestring = subtitle + '.' #add full stop to the end of subtitle
subtitle = newsubtitlestring #overwrite subtitle
newtitlestring = title + ': ' #add colon to the end of title
title = newtitlestring+subtitle #new title is in format title: subtitle.
else:
newtitlestring = title + '.' #if subtitle is empty add full stop to the end of title
title = newtitlestring #new title is in format title.
p = document.add_paragraph("[%s] " % count) #add a new paragraph to document starting with count value e.g reference [3]
p.style = document.styles['Normal'] #write paragraph in previously defined font style
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY #justify aligning of paragraph as per required for UoM reports
p.add_run("%s (%s.) (%s). " % (author,edoreds,year)) #add the title and year in brackets to the reference
p.add_run(title).italic = True #add the title to the paragraph in italics
if(edition!=''):
p.add_run(" %s. %s: %s." % (edition,pubplace,publisher)) #add the edition. publishier location: publisher name. to the paragraph
else:
p.add_run(" %s: %s." % (pubplace,publisher)) #add the edition. publishier location: publisher name. to the paragraph
document.save('references.docx') #save the appending to references.docx
file = open('archivedreferences.csv','a')
if(edition!=''):
referencestring = "Edited Book,%s (%s.) (%s). *%s* %s. %s: %s.\n" % (author,edoreds,year,title,edition,pubplace,publisher)
else:
referencestring = "Edited Book,%s (%s.) (%s). *%s* %s: %s.\n" % (author,edoreds,year,title,pubplace,publisher)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=9,column=0,columnspan=2) #create a label at the bottom of the window informing reference [number] added successfully
def softwaregen(authorstring,yearstring,titlestring,versionstring,urlstring,accessstring,referenceframe):
global count
count=count+1
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
version = versionstring.get()
url = urlstring.get()
access = accessstring.get()
p = document.add_paragraph("[%s] " % count)
p.style = document.styles['Normal']
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
p.add_run("%s (%s). " % (author,year))
p.add_run(title).italic = True
p.add_run(" (%s) [Computer Program]. Available at: %s (Accessed: %s)." % (version,url,access))
document.save('references.docx')
file = open('archivedreferences.csv','a')
referencestring = "Software,%s (%s). *%s*. (%s) [Computer Program]. Available at: %s (Accessed: %s).\n" % (author,year,title,version,url,access)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=7,column=0,columnspan=2)
def illustrationgen(authorstring,yearstring,titlestring,subtitlestring,pubplacestring,publisherstring,pagestring,urlstring,accessstring,typestring,referenceframe):
global count
count=count+1 #add one to the count to increase the number in the reference list
#get the values of each of the inputs of the book window entry fields
author = authorstring.get()
year = yearstring.get()
title = titlestring.get()
subtitle = subtitlestring.get()
pubplace = pubplacestring.get()
publisher = publisherstring.get()
page = pagestring.get()
url = urlstring.get()
access = accessstring.get()
typem = typestring.get()
if(subtitle!=''): #check if there has been an entry in the subtitle window, if so:
newsubtitlestring = subtitle + '.' #add full stop to the end of subtitle
subtitle = newsubtitlestring #overwrite subtitle
newtitlestring = title + ': ' #add colon to the end of title
title = newtitlestring+subtitle #new title is in format title: subtitle.
else:
newtitlestring = title + '.' #if subtitle is empty add full stop to the end of title
title = newtitlestring #new title is in format title.
p = document.add_paragraph("[%s] " % count) #add a new paragraph to document starting with count value e.g reference [3]
p.style = document.styles['Normal'] #write paragraph in previously defined font style
p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY #justify aligning of paragraph as per required for UoM reports
p.add_run("%s (%s). " % (author,year)) #add the title and year in brackets to the reference
p.add_run(title).italic = True #add the title to the paragraph in italics
if(page!=''):
p.add_run(" [%s]. %s: %s. pp. %s" % (typem,pubplace,publisher,page)) #add the edition. publishier location: publisher name. to the paragraph
else:
p.add_run(" [%s]. Available at: %s (Accessed: %s)" % (typem,url,access)) #add the edition. publishier location: publisher name. to the paragraph
document.save('references.docx') #save the appending to references.docx
file = open('archivedreferences.csv','a')
if(page!=''):
referencestring = "Illustration,%s (%s). *%s* [%s]. %s: %s. pp. %s\n" % (author,year,title,typem,pubplace,publisher,page)
else:
referencestring = "Illustration,%s (%s). *%s* [%s]. Available at: %s (Accessed: %s)\n" % (author,year,title,typem,url,access)
file.write(referencestring)
file.close()
success = Label(referenceframe,text=('Reference [%s] Successfully Generated And Archived' % count)).grid(row=11,column=0,columnspan=2) #create a label at the bottom of the window informing reference [number] added successfully
def ebookgen(authorstring,yearstring,titlestring,subtitlestring,editionstring,providerstring,urlstring,referenceframe):