Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# <img src='https://0000.us/klatchat/app/files/neon_images/icons/neon_skill.png' card_color="#FF8600" width="50" style="vertical-align:bottom">{Malls parser skill neon}
# <img src='https://0000.us/klatchat/app/files/neon_images/icons/neon_skill.png' card_color="#FF8600" width="50" style="vertical-align:bottom">{Mall guide skill neon}
## Summary
Skill for mall parsing
Skill for guiding around the mall.

## Description
Skill parses mall web page and returns user name, location and work hours of requested shop, store
Skill parses mall web page and returns user: name, location and work hours of requested shop, store

## Examples
- where is apple?
Expand Down
285 changes: 107 additions & 178 deletions __init__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/all_locations.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Here are all possible shop locations.
All {{store_name}} locations are:
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/another_shop.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
What shop you are looking for?
What store are you looking for?
2 changes: 2 additions & 0 deletions locale/en-us/dialog/en/another_shop_locations.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This store has more locations.
There are more locations.
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/ask_more.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Do you want to get another shop info?
Do you want to get another store info?
1 change: 1 addition & 0 deletions locale/en-us/dialog/en/by_time_sorting.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sorting stores by time.
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/choose_selection.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Do you want to select store by work hours or location?
Do you want to sort stores by work hours or location?
1 change: 0 additions & 1 deletion locale/en-us/dialog/en/closed_now.dialog

This file was deleted.

2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/closing_minutes.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{shop_name}} is open now. Closes in {{wait_min}} minutes.
Closes in {{closing_minutes}} minutes.
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/finished.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Finished. Goodbye!
Ok. Goodbye!
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/found_shop.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I found {{name}} with hours {{hours}}. You can find this store on {{location}}.
{{name}}, work hours are {{hours}}. You can find this store {{on}} {{location}}. Store is {{open}}.
1 change: 1 addition & 0 deletions locale/en-us/dialog/en/more_shops_info.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do you want to get other {{shop_name}} locations info?
1 change: 0 additions & 1 deletion locale/en-us/dialog/en/more_than_one.dialog

This file was deleted.

2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/no_shop_on_level.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
There is no requested shop on your level. Here are all possible locations.
There is no requested store on your level. Here are all possible locations.
1 change: 0 additions & 1 deletion locale/en-us/dialog/en/no_shop_request.dialog

This file was deleted.

1 change: 0 additions & 1 deletion locale/en-us/dialog/en/open_now.dialog

This file was deleted.

2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/opening_hours.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{shop_name}} is closed now. Opens in {{wait_h}} hour and {{wait_min}} minutes'
Opens in {{wait_h}} hour and {{wait_min}} minutes.
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/opening_minutes.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{shop_name}} is closed now. Opens in {{wait_min}} minutes.
Opens in {{wait_min}} minutes.
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/shop_by_floor.dialog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Do you want to get shop info by floor?
Do you want to get store info by floor?
2 changes: 1 addition & 1 deletion locale/en-us/dialog/en/shop_not_found.dialog
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Sorry, this store doesn't exist in this mall. I am not sure I've understood what you said. Repeat, please.
Sorry, I can not find this shop. I am not sure I've understood what you said. Repeat, please.
Sorry, I can not find this store. I am not sure I've understood what you said. Repeat, please.
1 change: 1 addition & 0 deletions locale/en-us/dialog/en/shops_amount.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I found {{n}} {{loc_amount}} for {{store_name}}.
1 change: 1 addition & 0 deletions locale/en-us/dialog/en/shops_on_user_floor.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I found {{n}} {{store_name}} stores on your level.
1 change: 0 additions & 1 deletion locale/en-us/dialog/en/start_parsing.dialog

This file was deleted.

1 change: 0 additions & 1 deletion locale/en-us/dialog/en/stop.dialog

This file was deleted.

3 changes: 0 additions & 3 deletions locale/en-us/dialog/en/which_floor.dialog

This file was deleted.

1 change: 1 addition & 0 deletions mall_cache.json

Large diffs are not rendered by default.

45 changes: 11 additions & 34 deletions request_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
import os
import json

from datetime import datetime


class RequestHandler():

caching_file = ''

def find_cached_stores(user_request: str, url, file_path):
def find_cached_stores(user_request: str, url, dir_path):
"""
Check shop name existence in cache keys
Args:
Expand All @@ -62,12 +60,13 @@ def find_cached_stores(user_request: str, url, file_path):
{"name": "ABS stores", "time": "8am-10pm", "location": "2 level"}
]
"""
caching_file = file_path+'/cached_stores.json'
caching_file = os.path.join(dir_path, 'mall_cache.json')
if os.path.isfile(caching_file) == False:
LOG.info("Cache file doesn't exist")
caching_stores_in_mall(file_path, url)
return find_cached_stores(user_request, url, file_path)
caching_stores_in_mall(caching_file, url)
return find_cached_stores(user_request, url, caching_file)
else:
LOG.info("Cache file exists")
with open(caching_file, 'r', encoding='utf-8') as readfile:
data = json.load(readfile)
found_key = [key for key in data.keys()
Expand All @@ -77,12 +76,12 @@ def find_cached_stores(user_request: str, url, file_path):
if len(found_key) >=1 :
store_name = str(found_key[0])
LOG.info(f'Shop exists {data[store_name]}')
return data[store_name], data
return data[store_name]
else:
LOG.info("Shop doesn't exist in cache")
return None, data
return None

def caching_stores_in_mall(file_path, url):
def caching_stores_in_mall(caching_file, url):
"""
Creates caching file in the current class.
Creates empty dictionary for cache. Parses
Expand All @@ -102,7 +101,6 @@ def caching_stores_in_mall(file_path, url):
{"name": "ABS stores", "time": "8am-10pm", "location": "2 level"}
]}
"""
caching_file = file_path+'/cached_stores.json'
LOG.info(f'caching_file {caching_file}')
shop_cache = {}
soup = parse(url)
Expand Down Expand Up @@ -141,26 +139,6 @@ def existing_lang_check(user_lang: str, url):
LOG.info('This language is not supported')
return False, link

def curent_time_extraction():
"""
Defines current time in utc timezone
Format: hour:minutes part of day (1:23 pm)

Returns:
day_time (list): contains splited time
numerals and part of the day
day_time -> ['07:19', 'am']
hour (int): current hour
min (int): current minute
"""
now = datetime.now().time().strftime("%I:%M %p")
# now = datetime.today().strftime("%H:%M %p")
LOG.info(f'now {now}')
day_time = now.lower().split(' ')
exact_time = day_time[0].split(':')
hour, min = int(exact_time[0]), int(exact_time[1])
return day_time, hour, min

def location_format(location):
"""
Finds all digits in store's location and
Expand Down Expand Up @@ -204,7 +182,7 @@ def shop_selection_by_floors(user_request, found_shops):
"""
shops_by_floor = []
for shop in found_shops:
numbers = re.findall(r'\d+', shop['location'])
numbers = re.findall(r'\d+', shop[2]['location'])
if len(numbers) > 0:
numbers = numbers[0]
num = pronounce_number(int(numbers), ordinals=False)
Expand All @@ -227,7 +205,7 @@ def parse(url):
LOG.info("Failed url parsing")


def get_shop_data(url, user_request, file_path):
def get_shop_data(url, user_request, dir_path):
"""
Check existence of user's request store in cache
if shop was found returns list with shop info,
Expand All @@ -244,8 +222,7 @@ def get_shop_data(url, user_request, file_path):
: found_shops (list): found shops' info
"""
# search for store existence in cache
LOG.info(file_path)
found_shops, data = find_cached_stores(user_request, url, file_path)
found_shops = find_cached_stores(user_request, url, dir_path)
LOG.info(found_shops)
if found_shops:
LOG.info(f"found_shops: {found_shops}")
Expand Down
12 changes: 6 additions & 6 deletions skill.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"title": "{Malls parser skill neon}",
"url": "https://github.com/NeonGeckoCom/skill-directory",
"summary": "Skill for mall parsing",
"short_description": "Skill for mall parsing",
"description": "Skill parses mall web page and returns user name, location and work hours of requested shop, store",
"title": "{Mall guide skill neon}",
"url": "https://github.com/NeonGeckoCom/mall_guide_skill",
"summary": "Skill for guiding around the mall.",
"short_description": "Skill for guiding around the mall.",
"description": "Skill parses mall web page and returns user: name, location and work hours of requested shop, store",
"examples": [
"where is apple?",
"where can i find abc stores?"
Expand Down Expand Up @@ -43,7 +43,7 @@
"NeonGeckoCom",
"NeonMariia"
],
"skillname": "skill-directory",
"skillname": "mall_guide_skill",
"authorname": "NeonGeckoCom",
"foldername": null
}
36 changes: 12 additions & 24 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,22 @@ def setUpClass(cls) -> None:
cls.skill.speak = Mock()
cls.skill.speak_dialog = Mock()

# TODO: Put any skill method overrides here
# Override gui show to test passed arguments
cls.skill.gui.show_image = Mock()

def setUp(self):
self.skill.speak.reset_mock()
self.skill.speak_dialog.reset_mock()

# TODO: Put any cleanup here that runs before each test case

@classmethod
def tearDownClass(cls) -> None:
shutil.rmtree(cls.test_fs)

def test_en_skill_init(self):
self.skill.ask_yesno = Mock(return_value="yes")
self.skill.gui._pages2uri = Mock()
self.skill._start_mall_parser_prompt(
Message('test', {'utterance': 'find ABC stores',
'shop': 'ABC stores',
Message('test', {'utterance': 'find Apple',
'shop': 'Apple',
'lang': 'en-us'},
{'context_key': 'MallParsing'})
)
Expand All @@ -92,27 +90,17 @@ def test_en_skill_init(self):
{'context_key': 'MallParsing'})
self.skill.user_request_handling(message)

def test_en_time_extraction(self):
shop_info = [{'name': 'ABC Stores', 'hours': '9am – 9pm', 'location': 'Street Level 1, near Centerstage', 'logo': 'https://gizmostorageprod.blob.core.windows.net/tenant-logos/1615937914061-abcstores.png'},
{'name': 'ABC Stores', 'hours': '10am – 8pm', 'location': 'Street Level 1, in the Ewa Wing', 'logo': 'https://gizmostorageprod.blob.core.windows.net/tenant-logos/1615937946329-abcstores.png'}]
day_time, hour, min = ['10:15', 'am'], 10, 15
result_shops = self.skill.open_shops_search(shop_info, day_time, hour, min)
self.assertEqual(shop_info, result_shops)

day_time, hour, min = ['9:15', 'am'], 9, 15
result_shops = self.skill.open_shops_search(shop_info, day_time, hour, min)
self.assertEqual(shop_info[0], result_shops[0])
def test_find_shop(self):
mall_link = "https://www.alamoanacenter.com/en/directory/"

# def test_en_time_extraction(self):
# shop_info = [{'name': 'ABC Stores', 'hours': '9am – 9pm', 'location': 'Street Level 1, near Centerstage', 'logo': 'https://gizmostorageprod.blob.core.windows.net/tenant-logos/1615937914061-abcstores.png'},
# {'name': 'ABC Stores', 'hours': '10am – 8pm', 'location': 'Street Level 1, in the Ewa Wing', 'logo': 'https://gizmostorageprod.blob.core.windows.net/tenant-logos/1615937946329-abcstores.png'},
# {'name': 'ABC Stores', 'hours': '10am – 9pm', 'location': 'Street Level 1, in the Ewa Wing', 'logo': 'https://gizmostorageprod.blob.core.windows.net/tenant-logos/1615937946329-abcstores.png'}]
user_request = 'starbucks'
new_count, user_request = self.skill.find_shop(user_request, mall_link)
self.assertEqual(new_count, 3)

# day_time, hour, min = ['9:15', 'pm'], 9, 15
# print(self.skill.time_calculation(shop_info, False, day_time, hour, min))
user_request = 'bubble'
new_count, user_request = self.skill.find_shop(user_request, mall_link)
self.assertEqual(new_count, 1)

# day_time, hour, min = ['8:15', 'pm'], 8, 15
# print(self.skill.time_calculation(shop_info, False, day_time, hour, min))


if __name__ == '__main__':
Expand Down
Loading