Giter Club home page Giter Club logo

gb2260.py's Introduction

GB/T 2260 Build Status Coverage Status PyPI Version Wheel Status

GB2260

The Python implementation for looking up the Chinese administrative divisions.

Installation

$ pip install GB2260

Basic Usage

The way to look up a administrative division by its GB2260 code is the basic interface gb2260.get(code):

>>> import gb2260
>>>
>>> division = gb2260.get(360426)
>>> print(division)
<gb2260.Division 360426 江西省/九江市/德安县>

The data of a division is accessible to interfaces as following:

>>> division.code
u'360426'
>>> division.name
u'德安县'
>>> division.is_county
True
>>> division.is_province
False
>>> division.is_prefecture
False
>>> print(division.province)
<gb2260.Division 360000 江西省>
>>> print(division.prefecture)
<gb2260.Division 360400 江西省/九江市>
>>> print(division.county)
<gb2260.Division 360426 江西省/九江市/德安县>

The hierarchic divisions could be generated with a iterator method:

>>> division.stack()
<generator object stack at 0x103e26a50>
>>> for current in division.stack():
...     print(u'{0} {1}'.format(current.name, current.code))
江西省 360000
九江市 360400
德安县 360426

The other way to look up a administrative division by its GB2260 name or its alias is gb2260.query(name):

>>> import gb2260
>>>
>>> print(gb2260.query('吴江'))
<GB2260 320509 江苏省/苏州市/吴江区>
>>> print(gb2260.query('吴江市'))
<GB2260-2011 320584 江苏省/苏州市/吴江市>
>>>
>>> print(gb2260.query('鼓楼', higher_code = 410000))
<GB2260 410204 河南省/开封市/鼓楼区>
>>> print(gb2260.query('鼓楼', higher_code = 350000))
<GB2260 350102 福建省/福州市/鼓楼区>
>>> print(gb2260.query('鼓楼', higher_code = 320300))
<GB2260 320302 江苏省/徐州市/鼓楼区>
>>> print(gb2260.query('鼓楼', higher_code = 320100))
<GB2260 320106 江苏省/南京市/鼓楼区>
>>>
>>> print(gb2260.query('开封'))
<GB2260 410224 河南省/开封市/开封县>
>>> print(gb2260.query('开封', is_prefecture=True))
<GB2260 410200 河南省/开封市>

Issues

If you want to report bugs or request features, please create issues on GitHub Issues.

External Links

gb2260.py's People

Contributors

lepture avatar tonyseek avatar winsweet avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.