Skip to content

Commit 107e727

Browse files
authored
Merge pull request #29 from software-students-fall2023/fixes
Fixes
2 parents 9e2a237 + 5bf8e0f commit 107e727

File tree

6 files changed

+49
-39
lines changed

6 files changed

+49
-39
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include src/pyrizz/data *

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,45 @@ In this function, you can retreive any random pickup line from a specific catego
3434
```
3535
from pyrizz import pyrizz
3636
37-
print(pyrizz.get_random_categoryy_line('romantic'))
38-
print(pyrizz.get_random_categoryy_line('clever'))
39-
print(pyrizz.get_random_categoryy_line('geeky'))
40-
print(pyrizz.get_random_categoryy_line('dev'))
37+
print(pyrizz.get_random_category_line('romantic'))
38+
print(pyrizz.get_random_category_line('clever'))
39+
print(pyrizz.get_random_category_line('geeky'))
40+
print(pyrizz.get_random_category_line('dev'))
4141
```
4242

43-
### get_ai_line(keyword)
43+
### get_ai_line(keyword, your_openai_key)
4444

45-
In this function, you can retreive a generated pickup line using openai based on any keyword that you suggest. In this example, it would output a Shakespearean pickup line:
45+
In this function, you can retreive a generated pickup line using openai gpt-3.5 model based on any keyword that you suggest. In this example, it would output a Shakespearean pickup line:
4646

4747
```
4848
from pyrizz import pyrizz
49+
import openai
4950
50-
print(pyrizz.get_ai_line('shakespeare'))
51+
openai.api_key = "..."
52+
print(pyrizz.get_ai_line("Shakespeare", openai))
5153
```
5254

53-
### rate_line(pickup_line)
55+
### rate_line(pickup_line, your_openai_key)
5456

55-
In this function, you can rate your very own pickup line out of 10 using openai. Simply type your pickup line and a rating will output:
57+
In this function, you can rate your very own pickup line out of 10 using openai gpt-3.5 model. Simply type your pickup line and a rating will output:
5658

5759
```
5860
from pyrizz import pyrizz
61+
import openai
5962
60-
print(pyrizz.rate_line('Are you from Tennesse? Cause you're the only 10 I see.'))
63+
openai.api_key = "..."
64+
print(pyrizz.rate_line('Are you from Tennesse? Cause you're the only 10 I see.', openai))
6165
```
6266

67+
Note: Please make sure you are using `openai==0.28.1`.
6368
### create_line(template_number, words)
6469

6570
In this function, if you're new to pickup lines, you can create your very own pickup using some of our templates!
66-
- **template_number** - You need to input a template number (0-39). You can find out the templates by calling the list_templates() function: `print(pyrizz.list_templates())`. This way you can see how the templates look like, how many words you need to include and which one you like!
71+
- **template_number** - You need to input a template number (0-39). You can find out the templates by calling the list_templates() function: `templates = pyrizz.list_templates()`. This way you can see how the templates look like, how many words you need to include and which one you like! You can print these templates like this:
72+
```
73+
for idx, template in enumerate(templates, 1):
74+
print(f"Template {idx}: {template}")
75+
```
6776
- **words** - You need to input a list of all the words, for example if you need to input 2 words: `words = ["word1", "word2"]`
6877

6978
This function returns your line with some lovely ASCII art as well! Enjoy!

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "pyrizz"
77
description = "A package where users can receive pick up lines, rate pickup lines and add pickup lines"
8-
version = "0.0.91"
8+
version = "1.0.5"
99
authors = [
1010
{ name="Aditya Pandhare", email="[email protected]" },
1111
{ name="Anzhelika Nastashchuk", email="[email protected]" },
@@ -33,3 +33,6 @@ dev = ["pytest"]
3333

3434
[project.scripts]
3535
pyrizz = "pyrizz.__main__:main"
36+
37+
[tool.setuptools.package-data]
38+
"pyrizz" = ["data/*"]

src/pyrizz/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pyrizz as pyrizz
1+
import pyrizz.pyrizz as pyrizz
22
import openai
33

44
"""Main function for PyRizz."""
@@ -77,7 +77,9 @@ def main():
7777

7878
elif user_input == "6":
7979
print("Here are the available templates:")
80-
pyrizz.list_templates()
80+
templates = pyrizz.list_templates()
81+
for idx, template in enumerate(templates, 1):
82+
print(f"Template {idx}: {template}")
8183

8284
elif user_input == "7":
8385
print("Please enter your API key.")

src/pyrizz/pyrizz.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import random
33
import pathlib
4-
import json
54
from pyrizz.pickuplines import pickuplines
65
from pyrizz.templates import templates
76

@@ -66,8 +65,13 @@ def load_ascii_art(filename):
6665
with open(filename, 'r', encoding='utf-8') as file:
6766
content = file.read()
6867
ascii_art_pieces = content.split('[End]')
69-
ascii_art_pieces = [piece.strip()[len('[Start]'):].strip() for piece in ascii_art_pieces if piece.strip()]
70-
return ascii_art_pieces
68+
cleaned_ascii_art_pieces = []
69+
for piece in ascii_art_pieces:
70+
if '[Start]' in piece:
71+
start_index = piece.find('[Start]') + len('[Start]')
72+
art_piece = piece[start_index:]
73+
cleaned_ascii_art_pieces.append(art_piece)
74+
return cleaned_ascii_art_pieces
7175

7276
def create_line(template_number, words):
7377
if not (0 <= template_number < len(templates)):
@@ -92,12 +96,16 @@ def create_line(template_number, words):
9296
return None, "Your line doesn't pass our checks. Sorry!"
9397

9498
def get_user_input_for_line():
95-
print("Choose a template number (0-{}):".format(len(templates)))
96-
template_number = int(input("> ")) - 1
99+
print("Choose a template number (0-{}):".format(len(templates) - 1))
100+
try:
101+
template_number = int(input("> "))
102+
except ValueError:
103+
print("Invalid input. Please enter an integer value.")
104+
return None, None
97105

98106
if template_number not in range(len(templates)):
99107
print("Invalid template number. Please choose a number between 0 and {}.".format(len(templates) - 1))
100-
return None, None
108+
return None, None
101109

102110
template_to_show = templates[template_number]
103111
placeholders_count = template_to_show.count("{}")
@@ -106,28 +114,21 @@ def get_user_input_for_line():
106114
print(template_to_show.format(*(['______'] * placeholders_count)))
107115

108116
print(f"Enter {placeholders_count} word(s) separated by commas to fill into the template:")
109-
words = input("> ").split(',')
110-
words = [word.strip() for word in words]
117+
words_input = input("> ")
118+
words = [word.strip() for word in words_input.split(',')]
119+
120+
if len(words) != placeholders_count:
121+
print(f"Incorrect number of words. You need to provide exactly {placeholders_count} word(s).")
122+
return None, None
111123

112124
return template_number, words
113125

114126
def is_line_valid(user_line):
115127
if len(user_line) > 140:
116128
print("Your pick-up line is too long.")
117129
return False
118-
119-
#if is_offensive(user_line):
120-
#return False
121130

122131
return True
123132

124-
#def is_offensive(text):
125-
# if profanity.contains_profanity(text):
126-
# return True
127-
# else:
128-
# return False
129-
130133
def list_templates():
131-
for idx, template in enumerate(templates, 1):
132-
print(f"Template {idx}: {template}")
133134
return templates

tests/test_pyrizz.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ def test_is_line_valid_length(self):
119119
long_line = "x" * 141
120120
assert not pyrizz.is_line_valid(long_line), "Expected the line to be flagged as too long."
121121

122-
@patch("builtins.input", side_effect=["1", "word1, word2"])
123-
def test_get_user_input_for_line(self, mock_input):
124-
template_number, words = pyrizz.get_user_input_for_line()
125-
assert template_number == 0
126-
assert words == ["word1", "word2"]
127-
128122
def test_create_line_invalid_template_number(self):
129123
_, message = pyrizz.create_line(999, ["word1", "word2"])
130124
assert message == "Template number out of range. Please choose between 0 and {}.".format(len(pyrizz.templates) - 1)

0 commit comments

Comments
 (0)