-{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Installation\nInstall the python client library using pip. See the [project page](https://pypi.org/project/tilt/)."},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip3 install tilt\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Basic usage\n\n1) Import the transparency information language binding/library.\n2) Create your first object, e.g. a Data Protection Officer with their contact details.\n3) Continue creating your objects, i.e. a Controller and its Representative.\n4) ... (add all other fields, not shown in here) ..."},{"metadata":{"trusted":true},"cell_type":"code","source":"from tilt import tilt\n\ndpo = tilt.DataProtectionOfficer(name='Max Ninjaturtle', address='21 Jump Street', country='DE', email='jane@mycompany.com', phone='0142 43333')\nprint(dpo.to_dict())\n# {'address': '21 Jump Street', 'country': 'DE', 'email': 'jane@mycompany.com', 'name': 'Max Ninjaturtle', 'phone': '0142 43333'}\n\n\nr = tilt.ControllerRepresentative(name='Maxi Müller', email='maxi@mail.com', phone=None)\nc = tilt.Controller(name='MyCompany', address='Straße des 17. Juni', country='DE', division='Main', representative=r)\nprint(c.to_dict())\n# {'address': 'Straße des 17. Juni', 'country': 'DE', 'division': 'Main', 'name': 'MyCompany', 'representative': {'email': 'maxi@mail.com', 'name': 'Maxi Müller', 'phone': None}}","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Import existing documents\nIn order to import exisiting tilt documents (we call them instances), you can use your favorite HTTP client or load from your local disk. Then you can use the native python objects and do any manipulations as you like.[](http://)"},{"metadata":{"trusted":true},"cell_type":"code","source":"import json\nimport requests\n\nfile = requests.get('https://raw.githubusercontent.com/Transparency-Information-Language/schema/master/tilt.json')\ninstance = tilt.tilt_from_dict(json.loads(file.content))\n\nprint(instance.controller.to_dict())\n# {'address': 'Wolfsburger Ring 2, 38440 Berlin', 'country': 'DE', 'division': 'Product line e-mobility', 'name': 'Green Company AG', 'representative': {'email': 'contact@greencompany.de', 'name': 'Jane Super', 'phone': '0049 151 1234 5678'}}\n\nfor element in list(instance.data_disclosed):\n for recipient in element.recipients:\n print(recipient.category)\n# Marketing content provider\n# Responsible Statistical Institutes\n\n\ninstance.controller.name = 'Yellow Company Ltd.'\nprint(instance.controller.to_dict())\n# {'address': 'Wolfsburger Ring 2, 38440 Berlin', 'country': 'DE', 'division': 'Product line e-mobility', 'name': 'Yellow Company Ltd.', 'representative': {'email': 'contact@greencompany.de', 'name': 'Jane Super', 'phone': '0049 151 1234 5678'}}","execution_count":59,"outputs":[{"output_type":"stream","text":"{'address': 'Wolfsburger Ring 2, 38440 Berlin', 'country': 'DE', 'division': 'Product line e-mobility', 'name': 'Green Company AG', 'representative': {'email': 'contact@greencompany.de', 'name': 'Jane Super', 'phone': '0049 151 1234 5678'}}\nMarketing content provider\nResponsible Statistical Institutes\n{'address': 'Wolfsburger Ring 2, 38440 Berlin', 'country': 'DE', 'division': 'Product line e-mobility', 'name': 'Yellow Company Ltd.', 'representative': {'email': 'contact@greencompany.de', 'name': 'Jane Super', 'phone': '0049 151 1234 5678'}}\n","name":"stdout"}]},{"metadata":{},"cell_type":"markdown","source":"## Create new documents from scratch\nIn the example below we are using standard libraries (e.g. sha256 or datetime) in order to create formatted strings. All objects have `from_dict()` and `to_dict()` functions which help you to build or export them."},{"metadata":{"trusted":true},"cell_type":"code","source":"from hashlib import sha256\nfrom datetime import datetime\n\nresult = {}\nresult[\"_hash\"] = sha256('<insert hashable content here>'.encode('utf-8')).hexdigest()\nresult[\"_id\"] = '<your-id-01>'\nresult[\"created\"] = '2020-10-02T22:08:12.510696'\nresult[\"language\"] = 'en'\nresult[\"modified\"] = datetime.now().isoformat()\nresult[\"name\"] = 'Green Compancy SE'\nresult[\"status\"] = 'active'\nresult[\"url\"] = 'https://greencompany.implementation.cloud'\nresult[\"version\"] = 42\n\nmeta = tilt.Meta.from_dict(result)\n\nprint(meta)\n# <tilt.tilt.Meta object at 0x7fef287928d0>\n\nprint(meta.to_dict())\n# {'_hash': 'bd8f3c314b73d85175c8ccf15b4b8d26348beca96c9df39ba98fa5dda3f60fcc', '_id': '<your-id-01>', 'created': '2020-10-02T22:08:12.510696', 'language': 'en', 'modified': '2020-07-27T15:14:35.689606', 'name': 'Green Compancy SE', 'status': 'active', 'url': 'https://greencompany.implementation.cloud', 'version': 42}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.7.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":4}
0 commit comments