Package: opentraveldata
OpenTravelData (OPTD) Data Wrapper - Python BindingsPython wrapper around OpenTravelData (OPTD) data sets, for instance
to be used by Python software needing to access OPTD data.ReferencesPyPi artifacts:https://pypi.org/project/opentraveldata/OpenTravelData (OPTD):Source code on GitHub:https://github.com/opentraveldata/opentraveldataDocker Cloud repository:https://cloud.docker.com/u/opentraveldata/repository/docker/opentraveldata/quality-assuranceThis Python-wrapper Git repository:https://github.com/opentraveldata/python-opentraveldataOPTD data archive:POR (Points of Reference)):https://www2.transport-search.org/data/optd/por/CI/CD deliveries:https://www2.transport-search.org/data/optd/cicd/OPTD Quality Assurance (QA):Sourcce code on GitHub:https://github.com/opentraveldata/quality-assuranceQuality Assurance (QA) reports:https://www2.transport-search.org/data/optd/qa/PythonHow-to install Python virtual environment withpyenvandpipenvHow to package modules for PythonPyPi - Deployment with Travis CIPyPi Travis CI providerdpl v2dpl v1UsageLaunch a Python interpreter:$python>>>Import theopentraveldatalibrary:>>>importopentraveldataSpecify a variable, saymyOPTD, as a handle on the OPTD libraryWith the default local directory for the data files,
that is/tmp/opentraveldata>>>myOPTD=opentraveldata.OpenTravelData()If you do not have access rights for writing into that directory,
initialize theOpenTravelDataobject with a directory on which
you have writing access rights:>>>myOPTD=opentraveldata.OpenTravelData(local_dir='/directory-on-which-you-have-writing-access-rights')Display some information about theOpenTravelDataobject:>>>myOPTDOpenTravelData:LocalIATA/ICAOPORfile:/tmp/opentraveldata/optd_por_public_all.csvLocalUN/LOCODEPORfile:/tmp/opentraveldata/optd_por_unlc.csvDisplay the expected location of the data filesFor the main (IATA/ICAO) POR (points of reference) data file:>>>myOPTD.localIATAPORFilepath()'/tmp/opentraveldata/optd_por_public_all.csv'For the UN/LOCODE POR (points of reference) data file:>>>myOPTD.localUNLCPORFilepath()'/tmp/opentraveldata/optd_por_unlc.csv'Display the source URL of the data filesFor the main (IATA/ICAO) POR (points of reference) data file:>>>myOPTD.iataPORFileURL()'https://github.com/opentraveldata/opentraveldata/blob/master/opentraveldata/optd_por_public_all.csv?raw=true'For the UN/LOCODE POR (points of reference) data file:>>>myOPTD.unlcPORFileURL()'https://github.com/opentraveldata/opentraveldata/blob/master/opentraveldata/optd_por_unlc.csv?raw=true'Download the latest data files (to be done once in a while; it takes
a few seconds, depending on the network bandwidth):>>>myOPTD.downloadFilesIfNeeded()Trigger an exception if the data files have not been properly downloaded:>>>myOPTD.assumeFilesExist()Check that the data files have been properly downloaded, and that their
sizes are as expected (40 to 50 MB for the IATA/ICAO data file and 4 to 5 MB
for the UN/LOCODE data file):>>>myOPTD.validateFileSizes()TrueDisplay the sizes of the data filesIn Bytes:>>>myOPTD.fileSizes()(44432069,4956451)In MB:>>>myOPTD.humanFileSizes()('42.37 MB','4.73 MB')Display the headers of the data filesIATA/ICAO data file:>>>myOPTD.extractIATAPORFileHeader()'iata_code^icao_code^faa_code^is_geonames^geoname_id^envelope_id^name^asciiname^latitude^longitude^fclass^fcode^page_rank^date_from^date_until^comment^country_code^cc2^country_name^continent_name^adm1_code^adm1_name_utf^adm1_name_ascii^adm2_code^adm2_name_utf^adm2_name_ascii^adm3_code^adm4_code^population^elevation^gtopo30^timezone^gmt_offset^dst_offset^raw_offset^moddate^city_code_list^city_name_list^city_detail_list^tvl_por_list^iso31662^location_type^wiki_link^alt_name_section^wac^wac_name^ccy_code^unlc_list^uic_list^geoname_lat^geoname_lon'UN/LOCODE data file:>>>myOPTD.extractUNLCPORFileHeader()'unlocode^latitude^longitude^geonames_id^iso31662_code^iso31662_name^feat_class^feat_code'Display the first few lines (here, 3 lines) of the data files:>>>myOPTD.displayFilesHead(3)Headerofthe'/tmp/opentraveldata/optd_por_public_all.csv'fileiata_code,icao_code,faa_code,is_geonames,geoname_id,envelope_id,name,asciiname,latitude,longitude,fclass,fcode,page_rank,date_from,date_until,comment,country_code,cc2,country_name,continent_name,adm1_code,adm1_name_utf,adm1_name_ascii,adm2_code,adm2_name_utf,adm2_name_ascii,adm3_code,adm4_code,population,elevation,gtopo30,timezone,gmt_offset,dst_offset,raw_offset,moddate,city_code_list,city_name_list,city_detail_list,tvl_por_list,iso31662,location_type,wiki_link,alt_name_section,wac,wac_name,ccy_code,unlc_list,uic_list,geoname_lat,geoname_lon,,,Y,11085,,BīshehKolā,BishehKola,36.18604,53.16789,P,PPL,,,,,IR,,Iran,Asia,35,Māzandarān,Mazandaran,,,,,,0,,1168,Asia/Tehran,3.5,4.5,3.5,2012-01-16,,,,,,C,,fa|بيشهكلا|=fa|BīshehKolā|,632,Iran,IRR,IRBSM|,,,,,,Y,14645,,KūchBeMasjed-eSoleymān,KuchBeMasjed-eSoleyman,31.56667,49.53333,P,PPL,,,,,IR,,Iran,Asia,15,Khuzestan,Khuzestan,,,,,,0,,424,Asia/Tehran,3.5,4.5,3.5,2012-01-16,,,,,,C,,fa|KūchBeMasjed-eSoleymān|,632,Iran,IRR,IRQMJ|,,,Headerofthe'/tmp/opentraveldata/optd_por_unlc.csv'fileunlocode,latitude,longitude,geonames_id,iso31662_code,iso31662_name,feat_class,feat_codeADALV,42.50779,1.52109,3041563,,,P,PPLCADALV,42.51124,1.53358,7730819,,,S,AIRHParse the data files and load their content into internal Python
dictionaries:>>>myOPTD.extractPORSubsetFromOPTD()Retrieve the details for theIEVcode:>>>importpprintaspp>>>pp.pprint(myOPTD.getServingPORList('IEV')){'original':{'adm1_code':'12','adm1_name_utf':'Kyiv City','country_code':'UA','country_name':'Ukraine','envelope_id':'','geoname_id':703448,'iata_code':'IEV','location_type':'C','name':'Kyiv'},'tvl_list':[{'adm1_code':'12','adm1_name_utf':'Kyiv City','country_code':'UA','country_name':'Ukraine','envelope_id':'','geoname_id':6300960,'iata_code':'IEV','location_type':'A','name':'Kyiv Zhuliany International Airport'},{'adm1_code':'13','adm1_name_utf':'Kyiv','country_code':'UA','country_name':'Ukraine','envelope_id':'','geoname_id':6300952,'iata_code':'KBP','location_type':'A','name':'Kyiv Boryspil International Airport'},{'adm1_code':'13','adm1_name_utf':'Kyiv','country_code':'UA','country_name':'Ukraine','envelope_id':'','geoname_id':8260936,'iata_code':'QOF','location_type':'B','name':'Darnytsia Bus Station'},{'adm1_code':'','adm1_name_utf':'','country_code':'UA','country_name':'Ukraine','envelope_id':'','geoname_id':0,'iata_code':'QOH','location_type':'B','name':'Kiev UA Hotel Rus'}]}Installation - configurationPythonReference: How-to install Python virtual environment withpyenvandpipenv:https://github.com/machine-learning-helpers/induction-python/tree/master/installation/virtual-envInstall Pyenv, Python 3.9.6,pipandpipenv:user@laptop$if[!-d${HOME}/.pyenv];thengitclonehttps://github.com/pyenv/pyenv.git${HOME}/.pyenv;elsepushd${HOME}/.pyenv&&gitpull&&popd;fiuser@laptop$cat>>~/.bashrc<< _EOF# Python# git clone https://github.com/pyenv/pyenv.git \${HOME}/.pyenvexport PATH="\${HOME}/.pyenv/shims:\${PATH}"eval "\$(pyenv init -)"eval "\$(pipenv --completion)"_EOFuser@laptop$.~/.bashrc
user@laptop$pyenvinstall3.9.6&&pyenvglobal3.9.6&&pipinstall-Upippipenv&&pyenvglobalClone the Git repository and install the Python virtual environment
(withpipenv):user@laptop$mkdir-p~/dev/geo&&\gitclonehttps://github.com/opentraveldata/python-opentraveldata.git~/dev/geo/python-opentraveldata
user@laptop$cd~/dev/geo/python-opentraveldata
user@laptop$pipenv--rm&&pipenvinstall&&pipenvinstall--dev
user@laptop$pipenvshell(python-opentraveldata-BScCAakO)$python--version
Python3.9.6(python-opentraveldata-BScCAakO)$exitPyPi credentials for Travis deploymentEncrypt the PyPi API token with the Travis command-line utility,
which stores the encryptedsecrettoken. As the project is managed
bytravis-ci.com, the--comoption has to be added in the command-line:user@laptop$travisencryptpypi-NotARealKey_Xo-adddeploy.password--com
user@laptop$gitadd.travis.ymlPackage and release the Python moduleLaunch thesetup.pyscript:user@laptop$rm-rfdist&&mkdirdist
user@laptop$pipenvrunpythonsetup.pysdistbdist_wheel
runningsdist
runningegg_info
creatingopentraveldata.egg-info
...
runningcheck
creatingopentraveldata-0.0.9
...
creatingdist
Creatingtararchive
removing'opentraveldata-0.0.9'(andeverythingunderit)runningbdist_wheel
...
creatingbuild
...
installingtobuild/bdist.macosx-10.15-x86_64/wheel
runninginstall
runninginstall_lib
...
runninginstall_egg_info
adding'opentraveldata/__init__.py'adding'opentraveldata/csvwriter.py'adding'opentraveldata/opentraveldata.py'adding'opentraveldata-0.0.9.dist-info/METADATA'adding'opentraveldata-0.0.9.dist-info/WHEEL'adding'opentraveldata-0.0.9.dist-info/top_level.txt'adding'opentraveldata-0.0.9.dist-info/RECORD'removingbuild/bdist.macosx-11.1-x86_64/wheel

user@laptop$ls-lFhdist/
total136-rw-r--r--1userstaff14KAug518:52opentraveldata-0.0.9-py3-none-any.whl
-rw-r--r--1userstaff52KAug518:52opentraveldata-0.0.9.tar.gzUpload/release the Python packages onto thePyPi test repository:user@laptop$PYPIURL="https://test.pypi.org"user@laptop$pipenvruntwineupload-u__token__--repository-url${PYPIURL}/legacy/dist/*
Uploadingdistributionstohttps://test.pypi.org/legacy/
Uploadingopentraveldata-0.0.9-py3-none-any.whl100%|█████████████████████████████████████████████████████████████████████|23.7k/23.7k[00:01<00:00,13.5kB/s]Uploadingopentraveldata-0.0.9.tar.gz100%|█████████████████████████████████████████████████████████████████████|44.3k/44.3k[00:01<00:00,41.2kB/s]Viewat:https://test.pypi.org/project/opentraveldata/0.0.9/Upload/release the Python packages onto thePyPi repository:user@laptop$PYPIURL="https://pypi.org"user@laptop$pipenvrunkeyringset${PYPIURL}/__token__
Passwordfor'__token__'in'${PYPIURL}/':
user@laptop$pipenvruntwineupload-u__token__--non-interactivedist/*
Uploadingdistributionstohttps://upload.pypi.org/legacy/
Uploadingopentraveldata-0.0.9-py3-none-any.whl100%|██████████████████████████████████████████████████████████████████████|23.7k/23.7k[00:01<00:00,15.2kB/s]Uploadingopentraveldata-0.0.9.tar.gz100%|██████████████████████████████████████████████████████████████████████|44.3k/44.3k[00:01<00:00,44.7kB/s]Viewat:
https://pypi.org/project/opentraveldata/0.0.9/Test the Python modulePytestLaunch the test:$pipenvrunpytesttest_optd-csvwriter.py=======================testsessionstarts=============================platformdarwin--Python3.9.5,pytest-5.3.5,py-1.8.1,pluggy-0.13.1
rootdir:~/dev/geo/python-opentraveldata
collected3itemstest_optd-csvwriter.py.[33%]test_optd-serving-por.py..[100%]===============================3passedin2.58s=======================_________________________________summary_____________________________Tox$pipenvruntox
.packagerecreate:~/dev/geo/python-opentraveldata/.tox/.package
.packageinstalldeps:setuptools>=35.0.2,setuptools_scm>=2.0.0,<3py39create:~/dev/geo/python-opentraveldata/.tox/py39
py39installdeps:pytest
py39inst:~/dev/geo/python-opentraveldata/.tox/.tmp/package/1/opentraveldata-0.0.9.tar.gz
py39installed:attrs==19.3.0,certifi==2019.11.28,chardet==3.0.4,idna==2.9,more-itertools==8.2.0,opentraveldata==0.0.9,packaging==20.3,pluggy==0.13.1,py==1.8.1,pyparsing==2.4.6,pytest==5.3.5,python-dateutil==2.8.1,pytz==2019.3,requests==2.23.0,six==1.14.0,urllib3==1.25.8,wcwidth==0.1.8
py39run-test-pre:PYTHONHASHSEED='3773488260'py39run-test:commands[0]|pytest=======================testsessionstarts=============================platformdarwin--Python3.9.5,pytest-5.3.5,py-1.8.1,pluggy-0.13.1
cachedir:.tox/py39/.pytest_cache
rootdir:~/dev/geo/python-opentraveldata
collected3itemstest_optd-csvwriter.py.[33%]test_optd-serving-por.py..[100%]===============================3passedin2.58s=======================_________________________________summary_____________________________py39:commandssucceededcongratulations:)