-
Notifications
You must be signed in to change notification settings - Fork 9
Substitute words loaded from separate file, new additions #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
44168c4
067ea98
0466edd
3950f1d
253ee54
1d0ac90
a583284
a1a92ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -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 = """ | ||||||||||||||
|
|
@@ -35,55 +33,16 @@ | |||||||||||||
| Documentation here: https://arrr.readthedocs.io/en/latest/ | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| #: MAJOR, MINOR, RELEASE, STATUS [alpha, beta, final], VERSION | ||||||||||||||
| _VERSION = (1, 0, 3) | ||||||||||||||
|
|
||||||||||||||
| _VERSION = (1, 1, 0) | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| #: 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: | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. So me wonder what cap’n be thinkin’. Be fine to keep this simple if |
||||||||||||||
| 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. | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| _PIRATE_PHRASES = [ | ||||||||||||||
|
|
@@ -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, | ||||||||||||||
|
|
@@ -161,6 +128,10 @@ def main(arrrgv=None): | |||||||||||||
| "Summat went awry, me lovely! Arrr..." | ||||||||||||||
| ) | ||||||||||||||
|
Comment on lines
128
to
129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| if __name__ == "__main__": | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.