- Notifications
You must be signed in to change notification settings - Fork13
A package consisting of all Tanzania locations from region to streets in an easily accessible way
License
Kalebu/mtaa
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A package consisting of all Tanzania locations from region to streets in a easy accessible way made bykalebu
Mtaa package is result of organizedjson of all the locations in Tanzania, As I was looking for data about these locations data I came across repotanzania-location-db, It consists of locations data organized intoregions, whereby each region has its own csv file. So I wrote a script to transform all the locations from csv into a singleJson and from there package came.
If you wanna give a look at the script or interested about building your Json from a similar kind of raw data here isJson Transformer script.
Use pip to install it just as shown below;
pip install mtaa
The library is very straight forward, at the very top of the library is country which is tanzania and at the very bottoms are places in a given street, here is a sample;
>>>frommtaaimporttanzania>>>tanzania['Shinyanga','Mara','Dar-es-salaam','Kilimanjaro','Kagera','Tanga','Mwanza','Tabora','Kigoma','Pwani','Ruvuma','Mtwara','Morogoro','Rukwa','Katavi','Simiyu','Geita','Arusha','Iringa','Mbeya','Njombe','Manyara','Lindi','Singida','Songwe','Dodoma']>>>tanzania.Mbeya.districts['Mbeya cbd','Mbeya','Rungwe','Mbarali','Kyela', 'Chunya]>>>tanzania.Mbeya.districts.Rungwe.wards['ward_post_code','Bulyaga','Bagamoyo','Makandana','Msasani','Kawetele','Itagata','Ibigi','Kyimo','Suma','Masoko','Mpuguso','Malindo','Lufingo','Kiwira','Nkunga','Ikuti','Kisondela','Ilima','Bujela','Masukulu','Kisiba','Kabula','Lupata','Kambasegela','Kisegese','Itete','Lufilyo','Lwangwa','Mpombo','Isange','Kandete','Luteba','Isongole','Kinyala','Matwebe','Masebe','Swaya','Iponjola','Lupepo','Ndanto','Ntaba','Mpata']
>>>frommtaaimporttanzania>>> type(tanzania)<class'mtaa.Tanzania'>
As you can see the repr() being shown on of the REPL is of type <mtaa.Tanzania>, you can easily convert it into native python datatypes due to the fact its iteratable, as shown in the example below;
>>>frommtaaimporttanzania>>>list(tanzania)['Shinyanga','Mara','Dar-es-salaam','Kilimanjaro','Kagera','Tanga','Mwanza','Tabora','Kigoma','Pwani','Ruvuma','Mtwara','Morogoro','Rukwa','Katavi','Simiyu','Geita','Arusha','Iringa','Mbeya','Njombe','Manyara','Lindi','Singida','Songwe','Dodoma']
Since its Iterable that's means you can loop through it, but as string for Example;
>>>fordistrictintanzania.Mbeya.districts:...print(district)...MbeyacbdMbeyaRungweMbaraliKyelaChunya
In the above example we were able to retreive locations ofMbeya region because, Mbeya is a valid python identifier, when you try to accessDar-es-Salaam it will ofcourse raise you an error just as shown below;
>>>frommtaaimporttanzania>>>tanzania.Dar-es-salaamTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:'Tanzania'objecthasnoattribute'Dar'
To resolve this at anypoint where you a location name is an invalid identifier, use get_dict() instead of (.) operator to access it as shown in the example below;
>>>frommtaaimporttanzania>>>tanzania.get('Dar-es-salaam').districts['Ilala cbd','Ilala','Kinondoni','Temeke','Ubungo','Kigamboni']
Lets you want to extract no just names in a ward but the whole ward and its deeper roots, to do this use the tree () at any given instance with exception of places in streets which are just list;
Here an example (Some places in Tanzania)
>>>home=tanzania.Mbeya.districts.Rungwe.wards.Kiwira.tree()>>>print(home){'ward_post_code':'53515','streets': {'Mpandapanda': ['Ipoma','Kiwira kati','Mpandapanda','Ilongoboto','Isange'],'Kikota': ['Lukwego','Lubwe',"Kang'eng'e",'Ilamba','Kikota','Ipande'],'Ibula': ['Kibumbe','Ibula','Kanyegele','Sanu - salala kalongo','Katela'],'Ilundo': ['Bujinga','Ibagha a','Buswema','Ibagha b','Kanyambala','Lusungo'],'Ilolo': ['Ibigi','Ilolo','Itekele','Masebe','Masugwa','Kisungu']}}
You can also access grouped locations such as all districts, wards and street as shown below;
>>>importmtaa>>>mtaa.wards......>>>len(mtaa.wards)3964>>>mtaa.districts......>>>len(mtaa.districts)158>>>mtaa.streets.....>>>len(mtaa.streets)16741
Incase you're from other languages than Python you might wanna take a look at these general purpose APIS
If you found this repository useful, give it a star so as the whole galaxy of developer can get to know it, you can also keep in touch with me ontwitter.
If you encounterissue with the usage of the package, feel free raise anissue so aswe can fix it as soon as possible(ASAP) or just reach me directly through email isaackeinstein(at)gmail.com.
If you have something to add I welcome pull requests on improvement , you're helpful contribution will be merged as soon as possible
All the location I used to build this repository, I got from an public repository titledtanzania-locations-db, I'm not responsible for any kind of misinformation in it, I tried to locate my home with it found its pretty accurate, so use it to your own risk
All the credits to ;
About
A package consisting of all Tanzania locations from region to streets in an easily accessible way