IndEcol / country_converter

The country converter (coco) - a Python package for converting country names between different classification schemes.
GNU General Public License v3.0
209 stars 71 forks source link

I write my telegram bot using this module and it can't find some countries #64

Closed TheBugYouCantFix closed 4 years ago

TheBugYouCantFix commented 4 years ago

Some of them work off the code.

1) e.g if I input US or USA to my bot it prints not found but if I input United States of America it works (the same issue with the UK) The error in my console is: WARNING:root: not found not found in regex

2) Also if I print South Korea it gives me the error that says: TypeError: can only concatenate str (not "list") to str
But it perfectly works with North Korea even when I call it DPRK (which is regarding the previous problem with the USA and the UK)

3) Furthermore, it doesn't work with Ireland. I am completely confused about this one since it's not an abbreviation and not 2 words long like South Korea. The error is completely the same as the first one: WARNING:root:not found not found in regex

I can provide you with my code if you want me to (just tell me about it)

It would be really nice if you could help me and solve all these issues or some of them

Thanks

konstantinstadler commented 4 years ago

Thanks for using country converter and giving feedback!

For the US and Korea I can not reproduce but I see the problem with UK:

In [1]: import country_converter as coco                                                                                                              

In [2]: coco.convert("US", to="short")                                                                                                                
Out[2]: 'United States'

In [3]: coco.convert("USA", to="short")                                                                                                               
Out[3]: 'United States'

In [4]: coco.convert("UK", to="short")                                                                                                                
WARNING:root:UK not found in ISO2
Out[4]: 'not found'

In [5]: coco.convert("GB", to="short")                                                                                                                
Out[5]: 'United Kingdom'

In [6]: coco.convert("KR", to="short")                                                                                                                
Out[6]: 'South Korea'

In [7]: coco.convert("Ireland", to="ISO2")                                                                                                            
Out[7]: 'IE'

The problem with UK is, that GB is the official ISO 2 code and if the code sees two letters it assumes ISO2. This however works:

In [12]: coco.convert("UK", src="regex", to="short")                                                                                                  
Out[12]: 'United Kingdom'

Perhaps I would need to see some code/minimal examples to fully understand the other issues (make sure you updated to the latest version as well). Principally, I am happy to help but I am on paternity leave until September so there might be some delays in my answers.

Best kst

TheBugYouCantFix commented 4 years ago

Thank you for your reply.

Here is the link for my telegram bot: t.me/CountryInfo_bot You can also see my whole code attached to this email

Hope you can help me

On Mon, Jul 27, 2020 at 3:47 PM Konstantin Stadler notifications@github.com wrote:

Thanks for using country converter and giving feedback!

For the US and Korea I can not reproduce but I see the problem with UK:

In [1]: import country_converter as coco

In [2]: coco.convert("US", to="short") Out[2]: 'United States'

In [3]: coco.convert("USA", to="short") Out[3]: 'United States'

In [4]: coco.convert("UK", to="short") WARNING:root:UK not found in ISO2 Out[4]: 'not found'

In [5]: coco.convert("GB", to="short") Out[5]: 'United Kingdom'

In [1]: import country_converter as coco

In [2]: coco.convert("US", to="short") Out[2]: 'United States'

In [3]: coco.convert("USA", to="short") Out[3]: 'United States'

In [4]: coco.convert("UK", to="short") WARNING:root:UK not found in ISO2 Out[4]: 'not found'

In [5]: coco.convert("GB", to="short") Out[5]: 'United Kingdom'

In [6]: coco.convert("KR", to="short") Out[6]: 'South Korea'

In [7]: coco.convert("Ireland", to="ISO2") Out[7]: 'IE'

The problem with UK is, that GB is the official ISO 2 code and if the code sees two letters it assumes ISO2. This however works:

In [12]: coco.convert("UK", src="regex", to="short") Out[12]: 'United Kingdom'

Perhaps I would need to see some code/minimal examples to fully understand the other issues (make sure you updated to the latest version as well). Principally, I am happy to help but I am on paternity leave until September so there might be some delays in my answers.

Best kst

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/konstantinstadler/country_converter/issues/64#issuecomment-664309434, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO3KT6PAATTVKX2HXHO62XLR5VLK3ANCNFSM4O5ZWVKQ .

import telebot import country_converter as cc

bot = telebot.TeleBot("1367232170:AAH014Ak7tJn3wAcyYwLfhvTNud-EA3Xvts")

@bot.message_handler(commands=['start']) def welcome(message): bot.send_message(message.chat.id, "Welcome, {0.first_name}! I am {1.first_name}.\n Input a country to get the information about it" .format(message.from_user, bot.get_me()), parse_mode='html')

@bot.message_handler(content_types=['text']) def ssss(message): x = cc.convert(names = message, to = 'name_short') bot.send_message(message.chat.id, "Official Name: "+cc.convert(names = x, to = 'name_official')+'\n' +"Continent: "+cc.convert(names = x, to = 'continent')+'\n'

bot.polling(none_stop=True)

konstantinstadler commented 4 years ago

Ok, this should be all fixed now in the current development version.

In [1]: import country_converter as coco                                                                                                                                                                             

In [2]: coco.convert('UK', src='regex')                                                                                                                                                                              
Out[2]: 'GBR'

In [3]: coco.convert('GB', src='regex')                                                                                                                                                                              
Out[3]: 'GBR'

In [4]: coco.convert('US', src='regex')                                                                                                                                                                              
Out[4]: 'USA'

In [5]: coco.convert('USA', src='regex')                                                                                                                                                                             
Out[5]: 'USA'

In [6]: coco.convert('Ireland', src='regex')                                                                                                                                                                         
Out[6]: 'IRL'

In [7]: coco.convert('Republic of Ireland', src='regex')                                                                                                                                                             
Out[7]: 'IRL'

In [8]: coco.convert('Macau', src='regex')                                                                                                                                                                           
Out[8]: 'MAC'

This is not on pypi yet, you can install the latest release candidate with

pip install git+https://github.com/konstantinstadler/country_converter --upgrade

Let me know if there any remaining issues

TheBugYouCantFix commented 4 years ago

Thank you a lot but I cannot download it with your link. Please, notify me when this version of country converter will be uploaded to pypi

Best regards

On Thu, Aug 20, 2020 at 6:06 PM Konstantin Stadler notifications@github.com wrote:

Closed #64 https://github.com/konstantinstadler/country_converter/issues/64.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/konstantinstadler/country_converter/issues/64#event-3675152450, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO3KT6OIV742BLOCU3IWED3SBUNUNANCNFSM4O5ZWVKQ .