Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release History
===============

1.1.0
=====

* Words be now in a separate csv file fer convenience.
* Arrr will now get angry if you call it without any arguments. Hornswogglers 'are not welcome me lad.
* Correct treatment of punctuation and capitalization.
* Lots of shiny new additions, go check 'em out ye scurvy dog!

1.0.3
=====

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ clean:

tidy: clean
@echo "\nTidying code with black..."
black -l 79 arrr.py
black -l 79 arrr

docs: clean
$(MAKE) -C docs html
Expand Down
95 changes: 33 additions & 62 deletions arrr.py → arrr/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python

# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""
A module for turning plain English into Pirate speak. Arrr.

Expand All @@ -23,10 +21,10 @@
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.
"""
import argparse as arrrgparse # Geddit..? ;-)
import random
import sys

import random
import argparse as arrrgparse # Geddit..? ;-)
from csv import reader as helmsman # He be the only lad aboard who can read!

#: The help text to be shown when requested.
_HELP_TEXT = """
Expand All @@ -35,55 +33,16 @@
Documentation here: https://arrr.readthedocs.io/en/latest/
"""


#: MAJOR, MINOR, RELEASE, STATUS [alpha, beta, final], VERSION

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#: MAJOR, MINOR, RELEASE, STATUS [alpha, beta, final], VERSION
#: MAJOR, MINOR, RELEASE, STATUS [alpha, beta, final], VERSION

_VERSION = (1, 0, 3)

_VERSION = (1, 1, 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your editor be removing all them nice blank lines. Mates need restin betwen workin, ya know?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_VERSION = (1, 1, 0)
_VERSION = (1, 1, 0)


#: Defines English to Pirate-ish word substitutions.
_PIRATE_WORDS = {
"hello": "ahoy",
"hi": "arrr",
"my": "me",
"friend": "m'hearty",
"boy": "laddy",
"girl": "lassie",
"sir": "matey",
"miss": "proud beauty",
"stranger": "scurvy dog",
"boss": "foul blaggart",
"where": "whar",
"is": "be",
"the": "th'",
"you": "ye",
"old": "barnacle covered",
"happy": "grog-filled",
"nearby": "broadside",
"bathroom": "head",
"kitchen": "galley",
"pub": "fleabag inn",
"stop": "avast",
"yes": "aye",
"no": "nay",
"yay": "yo-ho-ho",
"money": "doubloons",
"treasure": "booty",
"strong": "heave-ho",
"take": "pillage",
"drink": "grog",
"idiot": "scallywag",
"sea": "briney deep",
"vote": "mutiny",
"song": "shanty",
"drunk": "three sheets to the wind",
"lol": "yo ho ho",
"talk": "parley",
"fail": "scupper",
"quickly": "smartly",
"captain": "cap'n",
"meeting": "parley with rum and cap'n",
}
_PIRATE_WORDS = dict()
with open('BLABBER.csv') as nonsense:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python landlubbers think it good practiss to eschew side effects at importin’ time, like openin’ and readin’ file.
That’s fine thinkin’ but it requires ye to go roundabout and add some init function like this here: https://github.com/python/cpython/blob/main/Lib/mimetypes.py#L336-L337

So me wonder what cap’n be thinkin’. Be fine to keep this simple if arrr be mainly a command-line program, not a module for other landlubbers to use.

for gibberish in helmsman(nonsense, delimiter=','):
_PIRATE_WORDS[gibberish[0]] = gibberish[1]

del nonsense, gibberish

#: A list of Pirate phrases to randomly insert before or after sentences.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#: A list of Pirate phrases to randomly insert before or after sentences.
#: A list of Pirate phrases to randomly insert before or after sentences.

_PIRATE_PHRASES = [
Expand Down Expand Up @@ -118,27 +77,35 @@ def translate(english):
"""
Take some English text and return a Pirate-ish version thereof.
"""
# Normalise a list of words (remove whitespace and make lowercase)
words = [w.lower() for w in english.split()]
# Put text inside a list of words
words = [w for w in english.split()]

result = list()
# Substitute some English words with Pirate equivalents.
result = [_PIRATE_WORDS.get(word, word) for word in words]
# Capitalize words that begin a sentence and potentially insert a pirate
# phrase with a chance of 1 in 5.
capitalize = True
for i, word in enumerate(result):
if capitalize:
result[i] = word.capitalize()
capitalize = False
if word.endswith((".", "!", "?", ":",)):
# It's a word that ends with a sentence ending character.
for i, word in enumerate(words):
c = ''
if word[-1] in [".", "!", "?", ":"]:
c = word[-1]
word = word[:-1]

res = _PIRATE_WORDS.get(word.lower(), word)
result.append((res.capitalize() if capitalize else res) + c)

if c != '':
capitalize = True
if random.randint(0, 5) == 0:
result.insert(i + 1, random.choice(_PIRATE_PHRASES))
result.append(random.choice(_PIRATE_PHRASES).capitalize())
else:
capitalize = False

return " ".join(result)


def main(arrrgv=None):
"""
"""
Entry point for the command line tool 'pirate'.

Will print help text if the optional first argument is "help". Otherwise,
Expand All @@ -161,6 +128,10 @@ def main(arrrgv=None):
"Summat went awry, me lovely! Arrr..."
)
Comment on lines 128 to 129

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Summat went awry, me lovely! Arrr..."
)
"Summat went awry, me lovely! Arrr...",
file=sys.stderr,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye should complain on tha stderr room laddie!

sys.exit(1)
else:
print(
"Ye filthy bilge rat, don't try to fool me! I will gut yer insides!"
)
Comment on lines +133 to +134

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Ye filthy bilge rat, don't try to fool me! I will gut yer insides!"
)
"Ye filthy bilge rat, don't try to fool me! I will gut yer insides!",
file=sys.stderr,
)
sys.exit(1)



if __name__ == "__main__":
Expand Down
Loading