{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import uuid" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def is_valid_uuid(value):\n", " try:\n", " uuid.UUID(value, version=4)\n", " return True\n", " except ValueError:\n", " return False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "isValid = is_valid_uuid(\"f2a8f8f8-f8f8-f8f8-f8f8-f8f8f8f8f8f8\")\n", "print(isValid)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "isValid = is_valid_uuid(\"x2a8f8f8-f8f8-f8f8-f8f8-f8f8f8f8f8f8f\")\n", "print(isValid)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "More examples" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from controller.WoT_Hive_Controller import WoT_Hive_Controller" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "controller = WoT_Hive_Controller()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\"id\":\"079637bb-87d5-4fef-9704-d556364d90ba\",\"securityDefinitions\":{\"nosec_sc\":{\"scheme\":\"nosec\"}},\"description\":\"test description\",\"properties\":{\"KnowledgeGraph\":{\"forms\":[{\"href\":\"https://data.cogito.linkeddata.es/resources/079637bb-87d5-4fef-9704-d556364d90ba\",\"type\":\"text/turtle\"}]},\"ValueInGraph\":{\"forms\":[{\"href\":\"http://data.cogito.iot.linkeddata.es/resources/Project_079637bb-87d5-4fef-9704-d556364d90ba\",\"type\":\"text/turtle\"},{\"href\":\"http://data.cogito.iot.linkeddata.es/resources/Project_079637bb-87d5-4fef-9704-d556364d90bb\",\"type\":\"text/turtle\"}]}},\"title\":\"test1\",\"types\":\"https://cogito.iot.linkeddata.es/def/facility#Project\",\"registration\":{\"created\":\"2022-06-23T11:33:13.537Z\",\"modified\":\"2022-06-23T11:33:13.544Z\"},\"@context\":[\"https://www.w3.org/2019/wot/td/v1\",{\"facility\":\"https://cogito.iot.linkeddata.es/def/facility#\"},\"https://w3c.github.io/wot-discovery/context/discovery-context.jsonld\"],\"security\":[\"nosec_sc\"]}'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id1 = \"079637bb-87d5-4fef-9704-d556364d90ba\"\n", "response = controller.get_td(id1)\n", "response" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "td = {\n", " \"@context\": [\n", " \"https://www.w3.org/2019/wot/td/v1\",\n", " {\n", " \"facility\": \"https://cogito.iot.linkeddata.es/def/facility#\"\n", " }\n", " ],\n", " \"title\": \"test1\",\n", " \"id\": \"079637bb-87d5-4fef-9704-d556364d90bb\",\n", " \"types\": \"https://cogito.iot.linkeddata.es/def/facility#Project\",\n", " \"description\": \"test description\",\n", " \"properties\": {\n", " \"KnowledgeGraph\": {\n", " \"forms\": [\n", " {\n", " \"href\": \"https://data.cogito.linkeddata.es/resources/079637bb-87d5-4fef-9704-d556364d90bb\",\n", " \"type\": \"text/turtle\"\n", " }\n", " ]\n", " },\n", " \"ValueInGraph\": {\n", " \"forms\": [\n", " {\n", " \"href\": \"http://data.cogito.iot.linkeddata.es/resources/Project_079637bb-87d5-4fef-9704-d556364d90ba\",\n", " \"type\": \"text/turtle\"\n", " },\n", " {\n", " \"href\": \"http://data.cogito.iot.linkeddata.es/resources/Project_079637bb-87d5-4fef-9704-d556364d90bb\",\n", " \"type\": \"text/turtle\"\n", " }\n", " ]\n", " }\n", " },\n", " \"actions\": {},\n", " \"events\": {},\n", " \"links\": [],\n", " \"security\": [\n", " \"nosec_sc\"\n", " ],\n", " \"securityDefinitions\": {\n", " \"nosec_sc\": {\n", " \"scheme\": \"nosec\"\n", " }\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "id2 = \"079637bb-87d5-4fef-9704-d556364d90bb\"\n", "controller.post_td(id2, td)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "link = {\n", " \"rel\" : \"facility:hasIFC\",\n", " \"href\" : \"http://localhost:9000/api/things/079637bb-87d5-4fef-9704-d556364d90bb\",\n", " \"type\" : \"application/td+json\"\n", "}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "controller.update_td(id1, link)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hello'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hello = \"hello\"\n", "hello.capitalize()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.9 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.9" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } } }, "nbformat": 4, "nbformat_minor": 2 }