#!//Users/dtomlinson/.virtualenvs/emojis-3.7.3/bin/python
import emojis
import argparse
from texttable import Texttable

parser = argparse.ArgumentParser(description="""
    emoji lookup script to be ran on the shell
""")

parser.add_argument('emoji', type=str,
                    help=(
                        'full path to list of files. leave blank'
                        ' to run in current directory. the results will be'
                        ' placed in this folder if specified.'
                    ),
                    )

args = parser.parse_args()

emoji = vars(args)['emoji']

t = Texttable()

# t.add_row(['tag/alias', 'emoji'])

searchOne = [y for y in [x for x in emojis.db.get_tags()] if emoji in y]

emojiResults = []

emojiResults.append((['tag/alias', 'emoji']))

for item in searchOne:
    listOne = [x for x in emojis.db.get_emojis_by_tag(item)]
    counter = 0
    for i in range(0, len(listOne)):
        if counter == 3:
            break
        # print(f'{listOne[i][0][0]} - {listOne[i][1]}')
        emojiResults.append([(listOne[i][0][0]).strip(), (listOne[i][1]).strip()])
        # counter += 1

for alias, emojiAlias in zip(
        emojis.db.get_emoji_aliases().keys(),
        emojis.db.get_emoji_aliases().values()
):
    if emoji in alias:
        emojiResults.append([alias.strip(), emojiAlias.strip()])

# print(emojiResults)

t.add_rows(emojiResults)

if len(emojiResults) - 1 == 0:
    print(f'I found {len(emojiResults)-1} emojis for {emoji}! 😢')
else:
    print(f'I found {len(emojiResults)-1} emojis for {emoji}! 🥳')

print(t.draw())
