Skip to content

Commit

Permalink
Update to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Aug 13, 2021
1 parent 4fbb520 commit 09018d8
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/fortune/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import time

import strfile
import rot13

# Version string used by the what(1) and ident(1) commands:
ID = "@(#) $Id: fortune - print a random, hopefully interesting, adage v1.0.0 (August 11, 2021) by Hubert Tournier $"
ID = "@(#) $Id: fortune - print a random, hopefully interesting, adage v1.0.2 (August 13, 2021) by Hubert Tournier $"

# Default parameters. Can be overcome by environment variables, then command line options
parameters = {
Expand Down Expand Up @@ -555,7 +556,7 @@ def search_for_pattern(fortune_files):
continue

if file["Header"]["rotated flag"]:
fortune = rot13(fortune)
fortune = rot13.rot(fortune)

if parameters["Ignore case"]:
results = re.search(parameters["Pattern"], fortune, flags=re.IGNORECASE)
Expand Down Expand Up @@ -592,24 +593,6 @@ def select_fortune_file(fortune_files):
return None


################################################################################
def rot13(fortune):
"""Return the ROT13 version of the given fortune"""
# TODO:
# To be moved one day in a future rot13 command/library
rotated_fortune = ""
for character in fortune:
if character.isalpha():
if character.isupper():
rotated_fortune += chr(ord('A') + (ord(character) - ord('A') + 13) % 26)
else:
rotated_fortune += chr(ord('a') + (ord(character) - ord('a') + 13) % 26)
else:
rotated_fortune += character

return rotated_fortune


################################################################################
def select_fortune(file):
"""Randomly choose a fortune from a fortune file"""
Expand Down Expand Up @@ -643,7 +626,7 @@ def select_fortune(file):
continue

if file["Header"]["rotated flag"]:
return rot13(fortune)
return rot13.rot(fortune)

return fortune

Expand Down

0 comments on commit 09018d8

Please sign in to comment.