* Add extract-install make target
* Make README more descriptive
* Change all occurences of 'fortune' to 'phrase'
* Update comments at start of files
cp phrases.py /usr/local/bin
cp phrases /usr/share/phrases/
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/
uninstall:
rm /usr/local/bin/phrases.py
rm -r /usr/share/phrases/
-Get latin famous phrases in your terminal!
+Get Latin famous phrases in your terminal!
-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
+`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.
-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
-# Tool to extract famous phrases from wikipedia
+# Extract Latin famous phrases from wikipedia
+# Armaan Bhojwani 2020
+
from bs4 import BeautifulSoup
import requests
from bs4 import BeautifulSoup
import requests
-# Display famous phrases in the terminal
+# Display Latin famous phrases in the terminal
# Armaan Bhojwani 2020
import random
# Armaan Bhojwani 2020
import random
-def _random_int(start, end):
# Use system random if available, otherwise, use Python's
# Use system random if available, otherwise, use Python's
+def _random_int(start, end):
try:
r = random.SystemRandom()
except:
try:
r = random.SystemRandom()
except:
return r.randint(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'^%$')
contents = f.read()
lines = [line.rstrip() for line in contents.split('\n')]
delim = re.compile(r'^%$')
cur = []
def save_if_nonempty(buf):
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):
for line in lines:
if delim.match(line):
if cur:
save_if_nonempty(cur)
if cur:
save_if_nonempty(cur)
-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]
- print(get_random_fortune("/usr/share/phrases/phrases"))
+ print(get_random_phrase("/usr/share/phrases/phrases"))