From ae978c74d04c0b4f58325d96b5e55e57ee12ea86 Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Wed, 14 Aug 2024 16:14:34 -0400 Subject: [PATCH 1/7] Create testgit.py --- testgit.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 testgit.py diff --git a/testgit.py b/testgit.py new file mode 100644 index 0000000..1996421 --- /dev/null +++ b/testgit.py @@ -0,0 +1 @@ +This is just a test to be deleted \ No newline at end of file From a56b50f9a1e13a65a31bf95d12571dc93f176dd7 Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Wed, 14 Aug 2024 16:16:51 -0400 Subject: [PATCH 2/7] Delete testgit.py --- testgit.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 testgit.py diff --git a/testgit.py b/testgit.py deleted file mode 100644 index 1996421..0000000 --- a/testgit.py +++ /dev/null @@ -1 +0,0 @@ -This is just a test to be deleted \ No newline at end of file From 661ef113f4aa0f24d610146c2c43495630856888 Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Wed, 14 Aug 2024 17:31:39 -0400 Subject: [PATCH 3/7] HTML fixes Page listings no longer have both OL and UL, just OL; extraneous (though invisible) H3s in code removed. --- med2.2.2g.py => med2.2.3g.py | 52 +++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) rename med2.2.2g.py => med2.2.3g.py (72%) diff --git a/med2.2.2g.py b/med2.2.3g.py similarity index 72% rename from med2.2.2g.py rename to med2.2.3g.py index a613400..b5e65aa 100644 --- a/med2.2.2g.py +++ b/med2.2.3g.py @@ -36,6 +36,9 @@ v. 2.2G 12 Aug 2024 - different searches added -- "definition and notes" and "modern English word equivalent" - from this point version numbers are intended to match the standalone app + + v. 2.2.3G + - TBD """ # Search window contents @@ -95,48 +98,67 @@ file.write( "" + "\n" - + 'Middle English Dictionary open search results' + + 'Middle English Dictionary open search results' + + "\n" + + '' + "\n" - + '' + + '' + + "\n" + + '' + "\n" ) file.write( - '

Middle English Dictionary open search results for the word "' + '

Middle English Dictionary open search results for the word "' + str(search_term) - + '":

' + + '":' + "\n" ) - file.write("" + "" + "\n" + '

Page generated by MED Open Search. Software © Wendi Dunlap, 2013, 2024. The MED and all search results © University of Michigan.

' + "\n" From d87a51e304230f326003b99a82e1b84f07fa5a1a Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Wed, 14 Aug 2024 17:35:43 -0400 Subject: [PATCH 4/7] Another minor html fix Bolding words in word list. --- med2.2.3g.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/med2.2.3g.py b/med2.2.3g.py index b5e65aa..69ff877 100644 --- a/med2.2.3g.py +++ b/med2.2.3g.py @@ -36,9 +36,6 @@ v. 2.2G 12 Aug 2024 - different searches added -- "definition and notes" and "modern English word equivalent" - from this point version numbers are intended to match the standalone app - - v. 2.2.3G - - TBD """ # Search window contents @@ -141,7 +138,7 @@ if span_counter: span_counter.decompose() - file.write('
  • ' + "\n") + file.write('
  • ' + "\n") # Find the correct index number in the link index_number = re.search(r"MED\d\d\d\d\d", link_tag["href"]) @@ -151,7 +148,7 @@ link_tag["href"] = full_url file.write(str(link_tag)) - file.write("
  • " + "\n") + file.write("" + "\n") print("Added " + str(count + 1) + " to page") count += 1 From 03b0860119d5474b2e34dc8c8ddbb358e84b98c5 Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Sat, 17 Aug 2024 04:49:09 -0400 Subject: [PATCH 5/7] Create medg.py Simple rename. v 2.2.1, with fixes to html page and the ability to change the directory your results page gets saved to. --- medg.py | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 medg.py diff --git a/medg.py b/medg.py new file mode 100644 index 0000000..3ef6d39 --- /dev/null +++ b/medg.py @@ -0,0 +1,177 @@ +#!/Users/litlnemo/aProjects/coding/med/myenv/bin/python + +import PySimpleGUI as sg +import os +import requests +from bs4 import BeautifulSoup +import webbrowser +import re +from tkinter import filedialog + +"""med.py: A script for searching the Middle English Dictionary, + designed for use by those researching Medieval names. + + v. 1.0.1, 14 September 2013 + + v. 1.0.2, 30 September 2013: + - added loop, so you can search over and over again + - custom icon + - program now closes after you cancel search + - pages slightly prettier. + + v. 2.0, 8 August 2024: + - updated for Python 3 + - Pashua removed as it is no longer supported + - this means that for now this is command line only, sorry + - no loop at the moment + - cannot open pages with full open results... for now + - last version without GUI dialog box + + v. 2.0G, 10 Aug 2024: + - PySimpleGUI added + + v. 2.1, 11 Aug 2024 + - Standalone Mac app with Platypus + - changed deprecated "soup.find(text)" to "soup.find(string)" + + v. 2.2G 12 Aug 2024 + - different searches added -- "definition and notes" and "modern English word equivalent" + - from this point version numbers are intended to match the standalone app + + v. 2.2.1 17 Aug 2024 + - fixed visual stuff on the html results page + - now users can choose where to save the page +""" + +# Ask user where to save file +dirname = filedialog.askdirectory(title="Choose a folder for your results", message="Choose a folder for your results") + +# Search window contents +sg.theme('SystemDefaultForReal') +layout = [ [sg.Text('Enter search word: '), sg.InputText(key='searchword')], + [[sg.Radio('Headword & forms ', group_id=1, key='hnf', default=True), sg.Radio('Definition & notes ', key='dnn', group_id=1), sg.Radio('Modern English word equivalent', key='mdne', group_id=1)]], + [sg.Push(), sg.Button('Submit',visible=False, bind_return_key=True)] ] + +# Create the Window +window = sg.Window('MED Open Search', layout) + +# Event Loop to process "events" and get the "values" of the inputs +while True: + event, value = window.read() + if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel + break + + else: + search_term = value["searchword"] + + # formatting URL based on chosen type of search + # headword and forms search + + if value['hnf'] == True: + url = ( + "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary?utf8=✓&search_field=hnf&q=" + + search_term + ) + + # notes and definitions search + + elif value['dnn'] == True: + url = ( + "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary?utf8=✓&search_field=notes_and_def&q=" + + search_term + ) + + # modern english word equivalents search + + else: + url = ( + "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary?utf8=✓&search_field=oed&q=" + + search_term + ) + + # Get text of search results + + r = requests.get(url) + page_data = r.text + soup = BeautifulSoup(page_data, "html.parser") + count = 0 + + # Open file to write to, write HTML for top of page + + file_path = os.path.expanduser(f"{dirname}/medresults.html") + with open(file_path, "w", encoding="utf-8") as file: + file.write( + "" + + "\n" + + 'Middle English Dictionary open search results' + + "\n" + + '' + + "\n" + + '' + + "\n" + + '' + + "\n" + ) + file.write( + '

    Middle English Dictionary open search results for the word "' + + str(search_term) + + '":

    ' + + "\n" + ) + file.write("
      " + "\n") + + # Find relevant links, build LIs with them + + get_urls = soup.find_all("h3", class_="index_title document-title-heading col-md-12") + + if not get_urls: + print("Error! No results.") + file.write("
    1. " + "\n") + file.write("Sorry, no results!" + "\n") + file.write("
    2. " + "\n") + + for h3_tag in get_urls: + # Find the
      tag inside the

      + link_tag = h3_tag.find("a") + + # If there is no tag, continue to the next h3_tag + if not link_tag: + continue + + # Remove the h3 tag but keep its contents (specifically the tag) + h3_tag.unwrap() + + # Remove the span with the class "document-counter" if it exists + span_counter = h3_tag.find("span", class_="document-counter") + if span_counter: + span_counter.decompose() + + file.write('
    3. ' + "\n") + + # Find the correct index number in the link + index_number = re.search(r"MED\d\d\d\d\d", link_tag["href"]) + + if index_number: + full_url = "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary/" + index_number.group(0) + link_tag["href"] = full_url + + file.write(str(link_tag)) + file.write("
    4. " + "\n") + print("Added " + str(count + 1) + " to page") + count += 1 + + # Finish HTML and close 'er up! + + file.write( + "

    " + + "\n" + + '

    Page generated by MED Open Search. Software © Wendi Dunlap, 2013, 2024. The MED and all search results © University of Michigan.

    ' + + "\n" + + "" + ) + + html_url = "file://" + file_path + + webbrowser.open_new(html_url) + + \ No newline at end of file From c3afb67e0c37ff6e6786e61b29267a83ff07b2b5 Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Sat, 17 Aug 2024 04:53:23 -0400 Subject: [PATCH 6/7] Delete med2.2.3g.py -- duplicate --- med2.2.3g.py | 169 --------------------------------------------------- 1 file changed, 169 deletions(-) delete mode 100644 med2.2.3g.py diff --git a/med2.2.3g.py b/med2.2.3g.py deleted file mode 100644 index 69ff877..0000000 --- a/med2.2.3g.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/Users/litlnemo/aProjects/coding/med/myenv/bin/python - -import PySimpleGUI as sg -import os -import requests -from bs4 import BeautifulSoup -import webbrowser -import re - -"""med.py: A script for searching the Middle English Dictionary, - designed for use by those researching Medieval names. - - v. 1.0.1, 14 September 2013 - - v. 1.0.2, 30 September 2013: - - added loop, so you can search over and over again - - custom icon - - program now closes after you cancel search - - pages slightly prettier. - - v. 2.0, 8 August 2024: - - updated for Python 3 - - Pashua removed as it is no longer supported - - this means that for now this is command line only, sorry - - no loop at the moment - - cannot open pages with full open results... for now - - last version without GUI dialog box - - v. 2.0G, 10 Aug 2024: - - PySimpleGUI added - - v. 2.1, 11 Aug 2024 - - Standalone Mac app with Platypus - - changed deprecated "soup.find(text)" to "soup.find(string)" - - v. 2.2G 12 Aug 2024 - - different searches added -- "definition and notes" and "modern English word equivalent" - - from this point version numbers are intended to match the standalone app -""" - -# Search window contents -sg.theme('SystemDefaultForReal') -layout = [ [sg.Text('Enter search word: '), sg.InputText(key='searchword')], - [[sg.Radio('Headword & forms ', group_id=1, key='hnf', default=True), sg.Radio('Definition & notes ', key='dnn', group_id=1), sg.Radio('Modern English word equivalent', key='mdne', group_id=1)]], - [sg.Push(), sg.Button('Submit',visible=False, bind_return_key=True)] ] - -# Create the Window -window = sg.Window('MED Open Search', layout) - -# Event Loop to process "events" and get the "values" of the inputs -while True: - event, value = window.read() - if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel - break - - else: - search_term = value["searchword"] - - # formatting URL based on chosen type of search - # headword and forms search - - if value['hnf'] == True: - url = ( - "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary?utf8=✓&search_field=hnf&q=" - + search_term - ) - - # notes and definitions search - - elif value['dnn'] == True: - url = ( - "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary?utf8=✓&search_field=notes_and_def&q=" - + search_term - ) - - # modern english word equivalents search - - else: - url = ( - "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary?utf8=✓&search_field=oed&q=" - + search_term - ) - - # Get text of search results - - r = requests.get(url) - page_data = r.text - soup = BeautifulSoup(page_data, "html.parser") - count = 0 - - # Open file to write to, write HTML for top of page - - file_path = os.path.expanduser("~/Documents/medresults.html") - with open(file_path, "w", encoding="utf-8") as file: - file.write( - "" - + "\n" - + 'Middle English Dictionary open search results' - + "\n" - + '' - + "\n" - + '' - + "\n" - + '' - + "\n" - ) - file.write( - '

    Middle English Dictionary open search results for the word "' - + str(search_term) - + '":

    ' - + "\n" - ) - file.write("
      " + "\n") - - # Find relevant links, build LIs with them - - get_urls = soup.find_all("h3", class_="index_title document-title-heading col-md-12") - - if not get_urls: - print("Error! No results.") - file.write("
    1. " + "\n") - file.write("Sorry, no results!" + "\n") - file.write("
    2. " + "\n") - - for h3_tag in get_urls: - # Find the
      tag inside the

      - link_tag = h3_tag.find("a") - - # If there is no tag, continue to the next h3_tag - if not link_tag: - continue - - # Remove the h3 tag but keep its contents (specifically the tag) - h3_tag.unwrap() - - # Remove the span with the class "document-counter" if it exists - span_counter = h3_tag.find("span", class_="document-counter") - if span_counter: - span_counter.decompose() - - file.write('
    3. ' + "\n") - - # Find the correct index number in the link - index_number = re.search(r"MED\d\d\d\d\d", link_tag["href"]) - - if index_number: - full_url = "https://quod.lib.umich.edu/m/middle-english-dictionary/dictionary/" + index_number.group(0) - link_tag["href"] = full_url - - file.write(str(link_tag)) - file.write("
    4. " + "\n") - print("Added " + str(count + 1) + " to page") - count += 1 - - # Finish HTML and close 'er up! - - file.write( - "

    " - + "\n" - + '

    Page generated by MED Open Search. Software © Wendi Dunlap, 2013, 2024. The MED and all search results © University of Michigan.

    ' - + "\n" - + "" - ) - - html_url = "file://" + file_path - - webbrowser.open_new(html_url) - - \ No newline at end of file From b70408bdc9a3f009fb07ed4995707cf2f1ae59da Mon Sep 17 00:00:00 2001 From: Wendi Dunlap Date: Sat, 17 Aug 2024 05:03:58 -0400 Subject: [PATCH 7/7] Update medg.py Version number fix --- medg.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/medg.py b/medg.py index 3ef6d39..fee540d 100644 --- a/medg.py +++ b/medg.py @@ -1,5 +1,3 @@ -#!/Users/litlnemo/aProjects/coding/med/myenv/bin/python - import PySimpleGUI as sg import os import requests @@ -8,7 +6,8 @@ import re from tkinter import filedialog -"""med.py: A script for searching the Middle English Dictionary, +""" +med.py: A script for searching the Middle English Dictionary, designed for use by those researching Medieval names. v. 1.0.1, 14 September 2013 @@ -38,7 +37,7 @@ - different searches added -- "definition and notes" and "modern English word equivalent" - from this point version numbers are intended to match the standalone app - v. 2.2.1 17 Aug 2024 + v. 2.2.3 17 Aug 2024 - fixed visual stuff on the html results page - now users can choose where to save the page """