{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating records with date, time and timestamp fields " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08) \n", "[Clang 6.0 (clang-600.0.57)]\n" ] } ], "source": [ "import sys\n", "print(sys.version)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's first import fmrest, its FileMakerError and requests." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.4.0\n" ] } ], "source": [ "import fmrest\n", "print(fmrest.__version__)\n", "from fmrest.exceptions import FileMakerError\n", "import requests\n", "requests.packages.urllib3.disable_warnings()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now access the FMS and log in." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n" ] } ], "source": [ "fms = fmrest.Server('https://10.10.10.10', # https://filemaker.example.org\n", " user='fmsrest',\n", " password='fmsrest',\n", " database='testdatabase', # Using a test database\n", " # The test database contains one table and one layout, \n", " # both are named 'datatypes'\n", " layout='datatypes', \n", " # if you are testing without cert/domain \n", " # you may need the parameter verify_ssl=False here.\n", " verify_ssl=False\n", ")\n", "\n", "print(fms)\n", "\n", "fms.login()\n", "print(fms)\n", "print()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before writing anything to the database, we create an empty record." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "43\n" ] } ], "source": [ "new_data = {} # empty dict\n", "empty_record = fms.create_record( new_data ) \n", "print(empty_record)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The table in the test database contains five fields, one for every field type FM provides, i.e. text, number, date, time and timestamp.\n", "\n", "UTF-8 text can also include some characters / code points in the private areas, like the apple-sign (  ).\n", "\n", "Date does not accept the ISO 8601 format though, instead use 'MM/dd/yyyy'.\n", "\n", "The same applies to the date part in timestamps.\n", "\n", "In order to check via the API itself, get . This will return - at the time of this writing - \"dateFormat\":\"MM/dd/yyyy\", \"timeFormat\":\"HH:mm:ss\", \"timeStampFormat\":\"MM/dd/yyyy HH:mm:ss\".\n", "\n", "Apparently, FM accepts time and the time part of a timestamp in two formats. Either use a 24h format or an AM/PM alternative (see below)." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "44\n" ] } ], "source": [ "new_data_2 = {\n", " 'mytext': ' Ͼ Ͽ ༺ ༻ ༼  ༽ ༾ ༿ ᐸ ᐳ ⎨ ⎬ ❮ ❯ ⫷ ⫸ ⸨ ⸩ ﹤ ﹥ < >   ', \n", " 'mynum': 1234567, \n", " 'mydate': '02/22/2022', # month/day/year, with leading zero\n", " 'mytime': '9:15:55', # 24h format, no 'AM/PM', see above\n", " 'mystamp': '02/22/2022 21:15:55', # no 'AM/PM', see above\n", "}\n", "new_record_2 = fms.create_record(new_data_2)\n", "print(new_record_2)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Slightly different input here. We pass a number as a string, a date without a leading zero and we use an AM/PM alternative for the date." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "45\n" ] } ], "source": [ "new_data_3 = {\n", " 'mytext': 'Любви, мира и счастья!', \n", " 'mynum': '667', \n", " 'mydate': '2/22/2022', # month/day/year, no leading zero\n", " 'mytime': '9:15:55 AM', # use 'AM/PM' format\n", " 'mystamp': '2/22/2022 9:15:55 PM', # use 'AM/PM'\n", "}\n", "new_record_3 = fms.create_record(new_data_3)\n", "print(new_record_3)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Related issue #42 is here: https://github.com/davidhamann/python-fmrest/issues/42#issuecomment-1039211158 ." ] } ], "metadata": { "interpreter": { "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" }, "kernelspec": { "display_name": "Python 3.7.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.7.9" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }