Skip to content

Commit c64a1db

Browse files
committed
Add safe for work lyrics option
1 parent b748204 commit c64a1db

File tree

4 files changed

+163
-8
lines changed

4 files changed

+163
-8
lines changed

src/lancer/entry.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def parse_args(args):
4646
action="store",
4747
required=True,
4848
metavar="./FILE_PATH.py")
49+
parser.add_argument(
50+
"-s",
51+
"--sfw",
52+
dest="sfw",
53+
help="Generate comments that are safe for work.",
54+
action="store_true")
4955
parser.add_argument(
5056
"-y",
5157
"--yolo",
@@ -66,7 +72,7 @@ def setup_logging(loglevel):
6672
format=logformat, datefmt="%Y-%m-%d %H:%M:%S")
6773

6874

69-
def lance(file : Path = "./file.py", yolo : bool = False):
75+
def lance(file: Path = "./file.py", sfw: bool = False, yolo: bool = False):
7076
"""[summary]
7177
Takes a file and lances it.
7278
@@ -76,14 +82,16 @@ def lance(file : Path = "./file.py", yolo : bool = False):
7682
7783
Keyword Arguments:
7884
file {Path} -- File to be lanced (default: {"./file.py"})
85+
sfw {bool} -- Generate comments that are safe for work if true (default: {False})
7986
yolo {bool} -- Overwrites original if true (default: {False})
8087
"""
8188
# turn file into path if not already
8289
file = Path(file)
8390

8491
# initiate "fixers"
85-
variabel_fixer = VariableFixer()
92+
variable_fixer = VariableFixer()
8693
comment_fixer = CommentFixer()
94+
comment_fixer.sfw = sfw
8795

8896
# first fix comments
8997
comment_fixer.fix(file)
@@ -92,7 +100,7 @@ def lance(file : Path = "./file.py", yolo : bool = False):
92100
fixed_file = comment_fixer.__output__
93101

94102
# applying variable fixer
95-
variabel_fixer.fix(fixed_file)
103+
variable_fixer.fix(fixed_file)
96104

97105
# if yolo mode is true, substitute original
98106
if yolo:
@@ -107,7 +115,7 @@ def main(args):
107115
"""
108116
args = parse_args(args)
109117

110-
lance(file=args.file, yolo=args.yolo)
118+
lance(file=args.file, sfw=args.sfw, yolo=args.yolo)
111119

112120

113121
def run():

src/lancer/fixers/comments.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ class CommentFixer(object):
2727
def __init__(self):
2828
super(CommentFixer, self).__init__()
2929

30-
# Path to lyric file resource
30+
# Path to lyric file resources
3131
self.LYRIC_FILE = pkg_resources.resource_filename(
3232
__name__, "../resources/lyrics.txt")
3333

34+
self.SFW_LYRIC_FILE = pkg_resources.resource_filename(
35+
__name__, "../resources/sfw_lyrics.txt")
36+
37+
# Generate safe for work content (False by default)
38+
self.sfw = False
39+
3440
# Number of lyrics
3541
self.NUM_LYRICS = sum(1 for line in open(self.LYRIC_FILE))
3642

@@ -40,11 +46,12 @@ def __init__(self):
4046
def _get_lyric(self) -> str:
4147
"""Returns a random song lyric.
4248
43-
Gives one of many insightful Pitbull quotes.
49+
By default, gives one of many insightful Pitbull quotes.
50+
If self.sfw is True, return lyrics that are safe for work.
4451
"""
45-
52+
lyric_file = self.SFW_LYRIC_FILE if self.sfw else self.LYRIC_FILE
4653
# Open lyrics file and grab a random line
47-
with open(self.LYRIC_FILE) as f:
54+
with open(lyric_file) as f:
4855

4956
random_index = randint(0, self.NUM_LYRICS - 1)
5057

src/lancer/resources/sfw_lyrics.txt

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
On top of spaghetti all covered with cheese
2+
I lost my poor meatball when somebody sneezed
3+
It rolled off the table, it rolled on the floor
4+
And then my poor meatball rolled out of the door
5+
It rolled in the garden and under a bush
6+
And then my poor meatball was nothing but mush
7+
The mush was as tasty as tasty could be
8+
And early next summer it grew to a tree
9+
The tree was all covered with beautiful moss
10+
It grew great big meatballs and tomato sauce
11+
So if you eat spaghetti all covered with cheese
12+
Hold on to your meatball and don’t ever sneeze
13+
There was a little turtle his name was tiny Tim
14+
I put him in the bathtub to see if he could swim
15+
He drank up all the water, he ate up all the soap
16+
Now he’s in the bathtub with a bubble in his throat
17+
Bubble bubble bubble bubble bubble bubble bubble bubble POP!
18+
If all the raindrops were lemon drops and gumdrops
19+
So what a rain that would be
20+
Standing outside with my mouth open wide
21+
Ah, ah, ah, ah, ah, ah, ah, ah, ah, ah
22+
Oh, what a rain that would be
23+
If all the snowflakes were candy bars and milkshakes
24+
Oh, what a snow that would be
25+
If all the sunbeams were bubblegum and ice cream
26+
Oh, what a sun that would be!
27+
Standing outside, with my mouth open wide
28+
I’m bringing home my baby bumble bee
29+
Won’t my Mommy be so proud of me I’m bringing home my baby bumble bee – OUCH!! It stung me!!
30+
I’m squishin’ up my baby bumble bee
31+
Won’t my Mommy be so proud of me I’m squishin’ up my baby bumble bee – EW!! What a mess!!
32+
I’m lickin’ up my baby bumble bee
33+
Won’t my Mommy be so proud of me I’m lickin’ up my baby bumble bee – ICK!! I feel sick!!
34+
I’m throwin’ up my baby bumble bee
35+
Won’t my Mommy be so proud of me I’m throwin’ up my baby bumble bee – OH!! What a mess!!
36+
I’m wipin’ up my baby bumble bee
37+
Won’t my Mommy be so proud of me I’m wipin’ up my baby bumble bee – OOPS!! Mommy’s new towel!!
38+
I’m wringin’ out my baby bumble bee
39+
Won’t my Mommy be so proud of me I’m wringing out my baby bumble bee – Bye-Bye baby bumble bee!!
40+
Where is Thumbkin? Here I am! Here I am!
41+
How are you today, sir? Very well, I thank you
42+
Run away Run away Run away Run away
43+
Where is Pointer? Here I am! Here I am!
44+
Where is Middleman? Here I am! Here I am
45+
Where is Ringman? Here I am! Here I am!
46+
Where is Pinkie? Here I am! Here I am!
47+
Underwear, underwear, send a pair, send a pair, I can wear
48+
For I left mine lying, on a line a drying
49+
And now I need them they’re not there
50+
Underwear, underwear, get a pair, get a pair, anywhere
51+
The bugle’s blowing, I must be going
52+
For I’ve got to get there if I have to go there bare
53+
The cows in the barn go moo moo moo
54+
moo moo moo moo moo moo moo moo moo moo moo moo
55+
All day long the ducks in the pond go quack quack quack
56+
quack quack quack quack quack quack
57+
All day long the pigs in the pen go oink oink oink
58+
oink oink oink oink oink oink oink oink oink oink
59+
The pigs in the barn go oink oink oink
60+
The sheep in the field go baa baa baa
61+
baa baa baa baa baa baa
62+
One, two, three, four, five
63+
Once I caught a fish alive
64+
Six, seven, eight, nine, ten
65+
Then I let it go again
66+
Why did you let it go?
67+
Because it bit my finger so
68+
Which finger did it bite?
69+
The little finger on my right!
70+
Open them, shut them (open and shut fists)
71+
Give a little clap
72+
Lay them in your lap
73+
Creep them, creep them,
74+
Creep them, creep them
75+
Right up to your chin (walk hands up body to chin)
76+
Open wide your little mouth but do not put them in
77+
Roll them, roll them, roll them, roll them just like this
78+
Shake them, shake them
79+
Blow a little kiss!
80+
One, two, buckle my shoe
81+
Three, four, shut the door
82+
Five, six, pick up sticks
83+
Seven, eight, lay them straight
84+
Nine, ten, begin again
85+
Now everybody sing with me
86+
Okay everybody, one more time
87+
Nine, ten, that’s the end
88+
That’s the end I did it
89+
I have ten little fingers
90+
and they all belong to me I can make them do things
91+
Do you want to see?
92+
I can close them up tight
93+
I can open them wide
94+
I can put them together
95+
I can make them hide
96+
I can make them fly high
97+
I can make them go low
98+
I can fold them like this and hold them just so
99+
Hickory dickory dock
100+
The mouse went up the clock
101+
The clock struck one
102+
The mouse went down
103+
Tick tock, tick tock, tick tock, tick tock
104+
Teddy Bear Teddy Bear touch the ground
105+
If you’re an elephant and you know it stomp your feet
106+
If you’re a monkey and you know it jump up and down
107+
If you’re a crocodile and you know it snap your jaws
108+
If you’re a lion and you know it give a roar
109+
Barney is a dinosaur from our imagination
110+
And when he's tall he's what we call a dinosaur sensation
111+
Barney's friends are big and small
112+
They come from lots of places
113+
After school they meet to play
114+
And sing with happy faces
115+
Barney shows us lots of things
116+
Like how to play pretend
117+
ABC's, and 123's
118+
And how to be a friend
119+
Barney comes to play with us
120+
Whenever we may need him
121+
Barney can be your friend too
122+
If you just make-believe him

tests/test_CommentFixer.py

+18
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,21 @@ def test_get_lyric(self):
8080
assert lyric[:2] == "# "
8181

8282
assert self.fixer.NUM_LYRICS > 100
83+
84+
def test_get_sfw_lyric(self):
85+
"""Test random sfw lyric generation.
86+
"""
87+
self.fixer.sfw = True
88+
lyric = self.fixer._get_lyric()
89+
90+
assert isinstance(lyric, str)
91+
assert len(lyric) > 2
92+
93+
another_lyric = self.fixer._get_lyric()
94+
95+
assert lyric != another_lyric
96+
97+
# make sure comment starts with "# "
98+
assert lyric[:2] == "# "
99+
100+
assert self.fixer.NUM_LYRICS > 100

0 commit comments

Comments
 (0)