Skip to content

Commit

Permalink
Make black
Browse files Browse the repository at this point in the history
  • Loading branch information
cb4b1fd915 committed Dec 4, 2023
1 parent f4f1d35 commit 078858e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
36 changes: 26 additions & 10 deletions mariusz/gnujdb.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import urllib.parse


TRIGGERS = {'jest moze', 'jest może', 'czy jest', 'czy mamy', 'mamy może', 'mamy moze', 'może mamy', 'moze mamy'}
TRIGGERS = {
"jest moze",
"jest może",
"czy jest",
"czy mamy",
"mamy może",
"mamy moze",
"może mamy",
"moze mamy",
}


def czymamy(message: str) -> str | None:
url = None
hsl_phrases = ('w spejse', 'w spejsie', 'w hackerspejsie', 'w hs-ie', 'w hs', 'w hsie', )
null_phrases = ('jakiś', 'jakis', 'może', 'moze', 'mamy')
text = message.lower().split('?')[0].strip()
if '?' in message and any(map(lambda x: x in text, hsl_phrases)):
replacements = ('jakiś')
hsl_phrases = (
"w spejse",
"w spejsie",
"w hackerspejsie",
"w hs-ie",
"w hs",
"w hsie",
)
null_phrases = ("jakiś", "jakis", "może", "moze", "mamy")
text = message.lower().split("?")[0].strip()
if "?" in message and any(map(lambda x: x in text, hsl_phrases)):
replacements = "jakiś"
for item in TRIGGERS:
text = text.replace(item, '')
text = text.replace(item, "")
for item in hsl_phrases:
text = text.replace(item, '')
text = text.replace(item, "")
for item in null_phrases:
text = text.replace(item, '')
url = 'https://g.hs-ldz.pl/search?query=' + urllib.parse.quote(text.strip())
text = text.replace(item, "")
url = "https://g.hs-ldz.pl/search?query=" + urllib.parse.quote(text.strip())
return url
37 changes: 25 additions & 12 deletions mariusz/test_gnujdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@


class TestCzyMamyGnuj(unittest.TestCase):

@parameterized.parameterized.expand([
('Mamy może czas na to?', None),
('Mamy może w hs-ie nożyce do metalu? ', 'https://g.hs-ldz.pl/search?query=no%C5%BCyce%20do%20metalu'),
('Mamy w hs-ie nożyce do metalu? ', 'https://g.hs-ldz.pl/search?query=no%C5%BCyce%20do%20metalu'),
('Mamy w hs-ie nożyce ? Bo szukałem cośtamcośtam.', 'https://g.hs-ldz.pl/search?query=no%C5%BCyce'),
('Czy jest na to czas?', None),
('Czy jest w hs miarka?', 'https://g.hs-ldz.pl/search?query=miarka'),
('Czy jest w hs miarka ', None),
('Mamy może miarkę w spejsie?', 'https://g.hs-ldz.pl/search?query=miark%C4%99'),
])
@parameterized.parameterized.expand(
[
("Mamy może czas na to?", None),
(
"Mamy może w hs-ie nożyce do metalu? ",
"https://g.hs-ldz.pl/search?query=no%C5%BCyce%20do%20metalu",
),
(
"Mamy w hs-ie nożyce do metalu? ",
"https://g.hs-ldz.pl/search?query=no%C5%BCyce%20do%20metalu",
),
(
"Mamy w hs-ie nożyce ? Bo szukałem cośtamcośtam.",
"https://g.hs-ldz.pl/search?query=no%C5%BCyce",
),
("Czy jest na to czas?", None),
("Czy jest w hs miarka?", "https://g.hs-ldz.pl/search?query=miarka"),
("Czy jest w hs miarka ", None),
(
"Mamy może miarkę w spejsie?",
"https://g.hs-ldz.pl/search?query=miark%C4%99",
),
]
)
def test_method(self, message, result):
self.assertEqual(czymamy(message), result)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()

0 comments on commit 078858e

Please sign in to comment.