Package: opencity
opencityopencityis an interface for theopen data portal of Constance. It allows you to directly inspect, download, and work with the available data. This package can be easily used by practitioners, members of the civil society, and academics. Technically, it relies on the DKAN API.Install using pip. For potential problems see the theInstallation and Problems part.pipinstallopencityInstallationPotential problemsCapabilitiesClass OpenCityPropertiesFunctionsshow_dataget_datasave_dataExamplesshow_dataget_datasave_dataAuthor informationInstallationpipinstallopencityPotential problemsGeoPandasWhen installing the opencity package on aWindowscomputer, you might run into trouble during the installation due to the package requirementgeopandas.
This package is necessary for reading in spatial data, which is available for some of the data sets.
Please trythis towardsdatascience articlefor assistance in installinggeopandasand then try to install opencity again.tk / tkinterThe show_data method has one option to show meta data of available data-sets in a popup window.
If you want to use this feature and run into errors (e.g.There is an error with your Tkinter installation, use terminal=True to show the information anyway)
seethis AskUbuntu Questionorthis StackOverflow Question.However, you can always use theterminal=Trueparameter to display the same information in the terminal.SSL: CERTIFICATE_VERIFY_FAILEDFor later versions of Python onmacOS, certificates are not pre-installed which seems to cause this error:urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)Seethis StackOverflow Questionfor a solution.Capabilitiesget an overview of data sets viashow_data()load data directly into Python viaget_data()download data sets onto your local machine viasave_data()Generally, each functionality can be filtered by names and tags of the different data sets.classopencity.OpenCity(cf = None)class with several features described in the followingProperties :formatslist of Strings specifying formatscfreference to configuration file containing all relevant information(various) helper classesreference to various files containing helper classesFunctions :show_data()get_data()save_data()Each functionality is described in the following in detail.OpenCity.show_data(data=[], tag=False, overview=False, meta=False, terminal=False)displays an overview of the available and indicated data sets to the terminal or as a popupParameters:data: list of Strings, default: empty listcontaining names or tagstag: Boolean, default: Falseset to True if data list contains tagsoverview: Boolean, default: Falseset to True if a short overview of the data sets (title, short name, tags) is desired in the consolemeta: Boolean, default: Falseset to True if more detailed information on the data sets is desired
depending on parameter 'terminal'terminal: Boolean, default: Falseset to True if meta data should be printed in the console instead of a popupReturns: voidOpenCity.get_data(data=[], tag=False, meta=False)retrieves the indicated data from theopen data portal of ConstanceParameters:data: list of Strings, default: empty listcontaining names or tagstag: Boolean, default: Falseset to True if data list contains tagsmeta : Boolean, default: Falseset to True if meta data should be returnedReturns:pandas.DataFrame| dict containingpandas.DataFramesOpenCity.save_data(data, tag=False, folder="", suppress=False)saves the indicated data to the local diskParameters:data: list of Stringscontaining names or tagstag: Boolean, default: Falseset to True if data list contains tagsfolder: String, default: emptyIf you want to save the data to a different folder than the one from which you are executing the python file, indicate the respective folder here (use either forward slashes '/' or double backward slashes '\')suppress: Boolean, default: Falseset to True if you want to suppress the initial question asking whether you really want to downloadReturns: voidExamplesIn the following, we use<shortname>as a placeholder for the actual shortnames of each data set. To find out about the actual shortnames, you can useopen_city.show_data(overview = True)and check the second column.As a placeholder for the actual tags we use<Tag>. To find out about all the available tags, you can useopen_city.show_data().At first: create an instance of the class OpenCityfromopencityimportopencityasocfromopencityimportconfigasconfpath="<path>"# specify path herecf=conf.Config(PKG_FOLDER=path)open_city=oc.OpenCity(cf=cf)Alternatively you can init an OpenCity object without specifying a path - the file holding all current datasets will then be stored in the current working directory:fromopencityimportopencityasocopen_city=oc.OpenCity()show_data()show the total number of available data sets and their tagsopen_city.show_data()show an overview# of all available data sets:open_city.show_data(overview=True)# of all indicated data sets:open_city.show_data(overview=True,data=["<shortname>"])#indicate one or several data sets as a list of Strings, using their shortname# of all available data sets belonging to a certain tag:open_city.show_data(overview=True,data=["<Tag>"],tag=True)#indicate one or several tags as a list of Stringsshow meta data in a popup table# of all available data sets:open_city.show_data(meta=True)# of all indicated data sets:open_city.show_data(meta=True,data=["<shortname>"])#indicate one or several data sets as a list of Strings, using their shortname# of all available data sets belonging to a certain tag:open_city.show_data(meta=True,data=["<Tag>"],tag=True)#you could also indicate several tags hereshow meta data in the terminalopen_city.show_data(meta=True,terminal=True)#indicate one or several tags as a list of Stringsget_data()get data of a data setopen_city.get_data(data=["<shortname>"])#indicate one or several data sets as a list of Strings, using their shortnameThe output will look something like this:Loading data[+] Successfully loaded data set:        radverkehr_kampagne_stadtradeln_konstanz_2018_csv[+] Successfully loaded data set:        radverkehr_kampagne_stadtradeln_konstanz_2019_csv[+] Successfully loaded data set:        radverkehr_kampagne_stadtradeln_konstanz_2020_csvget data of a tagopen_city.get_data(data=["<Tag>"],tag=True)#indicate one or several tags as a list of StringsThe output will look something like this:Loading data[+] Successfully loaded data set:        einträge_im_mängelmelder_2017_csv[-] External Link:                       Einträge im Mängelmelder 2017                                                   					 Please visit https://konstanz.hub.arcgis.com/datasets/Konstanz::eintr%C3%A4ge-im-m%C3%A4ngelmelder-seit-dem-01-01-17[+] Successfully loaded data set:        außenwanderung_bei_stadtteil_von_2011_bis_2019_csv[+] Successfully loaded data set:        kindertagesbetreuung_einrichtungen_csv[+] Successfully loaded data set:        kindertagesbetreuung_einrichtungen_jsonget meta data of a data setopen_city.get_data(data=["<shortname>"],meta=True)#indicate one or several data sets as a list of Strings, using their shortnameThe output will look something like this:Loading data[+] Successfully loaded meta data of 6 data setsget meta data of a tagopen_city.get_data(data=["<Tag>"],tag=True,meta=True)#indicate one or several tags as a list of StringsThe output will look something like this:Loading data[+] Successfully loaded meta data of 16 data setssave_data()save data of a data setopen_city.save_data(data=["<shortname>"])#indicate one or several data sets as a list of Strings, using their shortnameAfter you confirm the check-back with ayand the saving was successful, you will see a progress bar in your console, indicating the status of downloading the files. When the saving process is finished, the output on your console will look something like this:[Saving Progress] : 100%|████████████████████████████████| 4/4 [00:15<00:00,  3.84s/it][+] Finished saving requested data to 'C:\Users\username\Downloads\test'.save data of a tagopen_city.save_data(data=["<Tag>"],tag=True)#indicate one or several tags as a list of Stringssave data to another folder than your project directorypath="C:/Users/example_path"#important to use either forward slashes or double backward slashes!open_city.save_data(data=["<shortname>"],folder=path)Found a bug?Open an issue including OS, package- and python version, executed code and error message!Author InformationBirke PfeifleRahkakavee BaskaranTilman KerlSilke HusseEmail:konstanz@correlaid.org