Comments (4)
Hi @nagaharish! Thanks for reporting this.
As you discovered, Telangana are registered at database, but MaxMind (the db provider) don't put an acronym for it (like "MH" for Maharashtra, "GJ" for Gujarat and so on).
As you probably know, by opening the GeoLite2-City-Locations-en.csv
file (you can discover where this file are located by running CS::CSV_FN_FULL
at console) and searching for "Telangana" (in my PC its located at line 5409), you will see that the field immediately at its left (the acronym code for the state) is blank (I'm just explaining this here for documentational purposes).
I think they don't put an acronym because its a relatively new state and (I presume) there's not an official acronym for it - but I'm just speculating. The problem is that city-state don't expect a record with an empty acronym.
I've thinking in 3 approaches to solve this:
a) hardcode this state in the gem (maybe a yaml file with a lookup table).
b) automatically generate an acronym if there's no acronym provided (using some "acronymizer" algorithm) - but this can lead to misleading acronyms
c) use the full name of the state as the acronym
What I will do it's a mix of "a" and "c". I will put an lookup table (states-acronyms.yaml
) for the cases where the acronyms are empty. If there's no acronym at MaxMind db neither in this lookup table, CS will use the full name of state.
from city-state.
done! I've created a db/states-replace.yml
file, which can be used in cases like this. Hereafter it can be used to translate names too.
CS.states(:in)
# => {:AN=>"Union Territory of Andaman and Nicobar Islands", :AP=>"Andhra Pradesh", :AR=>"Arunachal Pradesh", :AS=>"Assam", :BR=>"Bihar", :CH=>"Chandigarh", :CT=>"State of Chhattisgarh", :DD=>"Daman and Diu", :DL=>"National Capital Territory of Delhi", :DN=>"Dadra and Nagar Haveli", :GA=>"Goa", :GJ=>"Gujarat", :HP=>"State of Himachal Pradesh", :HR=>"Haryana", :JH=>"State of Jharkhand", :JK=>"Kashmir", :KA=>"Karnataka", :KL=>"Kerala", :LD=>"Laccadives", :MH=>"Maharashtra", :ML=>"Meghalaya", :MN=>"Manipur", :MP=>"Madhya Pradesh", :MZ=>"Mizoram", :NL=>"Nagaland", :OR=>"Odisha", :PB=>"State of Punjab", :PY=>"Union Territory of Puducherry", :RJ=>"Rajasthan", :SK=>"Sikkim", :TG=>"Telangana", :TN=>"Tamil Nadu", :TR=>"Tripura", :UL=>"Uttarakhand", :UP=>"Uttar Pradesh", :WB=>"West Bengal"}
CS.cities(:tg, :in)
# => ["Adilabad", "Balanagar", "Bhongir", "Bodhan", "Gudur", "Hyderabad", "Karimnagar", "Khammam", "Kottagudem", "Mancherial", "Medak", "Medchal", "Nalgonda", "Narsapur", "Nizamabad", "Paloncha", "Patancheru", "Patelguda", "Pochampalli", "Secunderabad", "Shadnagar", "Suriapet", "Uppal", "Vikarabad", "Warangal"]
PS: don't forget to update the gem (bundle update
)
PS II: if doesn't works after update, try to update the database with CS.update
from city-state.
Hi, Thanks a lot for adding this. Actually telangana is our state hence I could trace it.
May be we can check more states like this and if any balnk is there we can use the states-replace.yml file.
from city-state.
This one does not work for me when I'm using the latest version
running it on rails console:
CS.cities(:tg, :in)
=> []
This happens when I run cs.update. After running it, I looked at your gem folder and found it contains states and cities files and somehow your implementation is failing and TG is not being accepted.
from city-state.
Related Issues (20)
- New Feature Request; zipcode should also be there with cities.
- How to change db data locally?
- Some cities are not showing for some states HOT 1
- Unable to update from Rails console, changes lost after closing console HOT 1
- Ability to query cities by country name in addition to country code HOT 1
- Invalid data for GB HOT 1
- broken link
- NoMethodError: undefined method `present?' for :US:Symbol HOT 1
- missing city Surat
- Is there a plan to include timezone in?
- Singapore cities are missing but present in MaxMind DB HOT 2
- Typo correction "Tithari" should be changed to "Ithari" for Nepal HOT 2
- Failed to open TCP connection to geolite.maxmind.com:80 (getaddrinfo: No address associated with hostname) (SocketError) HOT 4
- Renaming a city or Delete city HOT 3
- How to access cities when tthere is no states present for a countrry.
- Permission errors on deploy
- "No such file or directory @ rb_sysopen <url>" when attempting update
- Not working with ruby 3.2 HOT 5
- Cannot list all existing cities to check if certain city exists or not right away
- Error "Did you mean? exist?" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from city-state.