]> git.armaanb.net Git - phrases.git/commitdiff
update formatting and convinience
authorArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Tue, 1 Dec 2020 15:25:23 +0000 (10:25 -0500)
committerArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Tue, 1 Dec 2020 15:25:23 +0000 (10:25 -0500)
  * Add extract-install make target
  * Make README more descriptive
  * Change all occurences of 'fortune' to 'phrase'
  * Update comments at start of files

Makefile
README.md
extract.py
phrases.py

index ac6d7edb188ef5cb5a6809301bf697d566f3f03c..9f3520be945d2dbae741c8dc1d97cbf9530de441 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,13 @@ install:
        cp phrases.py /usr/local/bin
        cp phrases /usr/share/phrases/
 
+extract-install:
+       ./extract.py
+       mkdir -p /usr/local/bin
+       mkdir -p /usr/share/phrases/
+       cp phrases.py /usr/local/bin
+       cp phrases /usr/share/phrases/
+
 uninstall:
        rm /usr/local/bin/phrases.py
        rm -r /usr/share/phrases/
index 6541458918ec0d27ea828353cd8669f79d9d3a59..66c0625b5b048d6b449e4f5bc23f901d52daea93 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,13 +1,16 @@
 # phrases
-Get latin famous phrases in your terminal!
+Get Latin famous phrases in your terminal!
 
 ## Source
-The Wikipedia page "[List of Latin phrases (full)](https://en.wikipedia.org/wiki/List_of_Latin_phrases_(full))". See the references [here](https://en.wikipedia.org/wiki/List_of_Latin_phrases_(full)#References) for more information
+The Wikipedia page "[List of Latin phrases (full)](https://en.wikipedia.org/wiki/List_of_Latin_phrases_(full))". See the references [here](https://en.wikipedia.org/wiki/List_of_Latin_phrases_(full)#References) for more information. There are currently 2225 phrases in the database
 
 ## Installation
-`sudo make`
+`sudo make` to install. Requires Python 3.
+`sudo make uninstall` to uninstall completely.
 
-If you want to run the `extract.py` script, then you need BeautifulSoup
+If you want to run the `extract.py` script, then you need the BeautifulSoup Python module. This is not needed for installation however, as this repository has a pre-extracted list of phrases [here](phrases). If the repository has not been updated in some time, then it may be prudent to run it again to get a fresh list. You can do this at install-time with `sudo make extract-install`. As this is run as root, make sure to install BeautifulSoup globally.
 
 ## License
-Phrases is MIT Licensed by [Armaan Bhojwani](https://armaanb.net), 2020. In part built on [fortune](https://github.com/bmc/fortune) by Brian M. Clapper
+Phrases is MIT Licensed by [Armaan Bhojwani](https://armaanb.net), 2020. See the LICENSE file for more information.
+
+In part built on [fortune](https://github.com/bmc/fortune) by Brian M. Clapper which is BSD licensed
index fa745300e64bdccdb8b1473f5bd4e218b8f8f57c..65f99143e2fca0bd24dc65ea8927633451540413 100755 (executable)
@@ -1,5 +1,7 @@
 #!/usr/bin/env python3
-# Tool to extract famous phrases from wikipedia
+# Extract Latin famous phrases from wikipedia
+# Armaan Bhojwani 2020
+
 from bs4 import BeautifulSoup
 import requests
 
index 93f8a2f84375f06bc4dcb98ed4f3914ba68f7f12..bcf3f7367128bfb9de2ba3f9f1e66af48f071eee 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-# Display famous phrases in the terminal
+# Display Latin famous phrases in the terminal
 # Armaan Bhojwani 2020
 
 import random
@@ -7,8 +7,8 @@ import os
 import sys
 import re
 
-def _random_int(start, end):
 # Use system random if available, otherwise, use Python's
+def _random_int(start, end):
     try:
         r = random.SystemRandom()
     except:
@@ -16,19 +16,20 @@ def _random_int(start, end):
 
     return r.randint(start, end)
 
-def _read_fortunes(fortune_file):
-    f = open(fortune_file, 'r')
+# Create list of phrases from phrase file
+def _read_phrases(phrase_file):
+    f = open(phrase_file, 'r')
     contents = f.read()
 
     lines = [line.rstrip() for line in contents.split('\n')]
     delim = re.compile(r'^%$')
-    fortunes = []
+    phrases = []
     cur = []
 
     def save_if_nonempty(buf):
-        fortune = '\n'.join(buf)
-        if fortune.strip():
-            fortunes.append(fortune)
+        phrase = '\n'.join(buf)
+        if phrase.strip():
+            phrases.append(phrase)
 
     for line in lines:
         if delim.match(line):
@@ -41,15 +42,17 @@ def _read_fortunes(fortune_file):
     if cur:
         save_if_nonempty(cur)
 
-    return fortunes
+    return phrases
 
-def get_random_fortune(fortune_file):
-    fortunes = list(_read_fortunes(fortune_file))
-    randomRecord = _random_int(0, len(fortunes) - 1)
-    randFortune = fortunes[randomRecord]
-    return randFortune.partition('\n')[0]
+# Return a random phrase from the phrases list
+def get_random_phrase(phrase_file):
+    phrases = list(_read_phrases(phrase_file))
+    randomRecord = _random_int(0, len(phrases) - 1)
+    randphrase = phrases[randomRecord]
+    return randphrase.partition('\n')[0]
 
+# Main program
 def main():
-    print(get_random_fortune("/usr/share/phrases/phrases"))
+    print(get_random_phrase("/usr/share/phrases/phrases"))
 
 main()