”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 在黑客马拉松中使用 Kintone 的技巧

在黑客马拉松中使用 Kintone 的技巧

发布于2024-11-08
浏览:829

Introduction

When you're participating in a hackathon, efficiency and quick iteration are key to success. One tool that can help you manage data efficiently is Kintone, a powerful no-code/low-code platform that allows you to create web-based databases with ease.

In this guide, we'll walk you through how to create a simple Kintone App to store scores for games, and demonstrate how to interact with the Kintone API using some local Python code.

Get your Kintone Environment

First we need to get our hands on a Kintone Environment!
Developers are entitled to use the Kintone Developer License - an environment that can be used for free for 1 year ❤

Get your Kintone Developer License by filling out the form.
https://kintone.dev/en/developer-license-registration-form/

Create your Kintone Database

Web Databases in Kintone are called "Apps".
Creating these Apps are easy in Kintone - you can drag-and-drop the fields that you need, without needing to code.

Tips for using Kintone in Hackathons

Follow the instructions on the following link to create a new App.
https://get.kintone.help/k/en/id/040133.html

These are the fields we will include in the Kintone App for this article:

Field Type Field Name Field Code
Text Player Name playername
Number Score score
Text Difficulty difficulty

The field layout should look like the following:

Tips for using Kintone in Hackathons

After that, proceed to the Settings tab, and generate an API Token that will be used for the authentication. Set the permissions for View records and Add records.

https://get.kintone.help/k/en/id/040471.html

Once this is done, save the settings, and click on the blue "Activate App" button.

Manually Input Some Data

Since there is no data yet inside the App, manually add in some data so that we have something to work with.
https://get.kintone.help/k/en/id/040715.html

Tips for using Kintone in Hackathons

Now we're ready to interact with the Web Database with some Python code!

Sample Python Code to Interact with Kintone

Now that your app is set up, let's look at how you can interact with the Kintone API using Python. We'll cover how to add a record, retrieve all records, and query records based on difficulty.

Get a Python environment ready on your local machine. Since we will be using the requests library to make our API calls, install the library with the following command:


pip install requests


1. Adding a Record to the Kintone App

Below is a sample Python script that adds a new record to the Kintone App.


import requests
import json

def add_record():
    API_endpoint = "https://{YOUR_SUBDOMAIN}.cybozu.com/k/v1/record.json"
    app_id = "{APP_ID}"

    kintone_headers = {
        "X-Cybozu-API-Token": "{API_TOKEN}",
        "Content-Type": "application/json"
    }

    bodydata = {
        "app": app_id,
        "record": {
            "player": {
                "value": "John Doe"
            },
            "score": {
                "value": "1500"
            },
            "diff": {
                "value": "Medium"
            }
        }
    }

    try:
        response = requests.post(API_endpoint, headers=kintone_headers, data=json.dumps(bodydata))
        jsondata = response.json()
        print(jsondata)

    except requests.exceptions.RequestException as error:
        print(error)

add_record()


The App ID is a number that can be found in the URL of the Kintone App.
If the request is successful, a JSON is responded that includes the ID of the newly added record.


{'id': '7', 'revision': '1'}


If the request is successful, but the record data is empty, it may be because the keys inside the body data were incorrect. Make sure that the keys for the fields are stated as their field codes, and not their field names.

2. Retrieving All Records from the Kintone App

The following Python script will retrieve all records stored in your Kintone App.


import requests

def get_all_records():
    API_endpoint = "https://{YOUR_SUBDOMAIN}.cybozu.com/k/v1/records.json"
    app_id = "{APP_ID}"
    API_endpoint = API_endpoint   "?app="   app_id

    kintone_headers = {
        "X-Cybozu-API-Token": "{API_TOKEN}",
    }

    try:
        response = requests.get(API_endpoint, headers=kintone_headers)
        jsondata = response.json()
        print(jsondata)

    except requests.exceptions.RequestException as error:
        print(error)

get_all_records()


If the request is successful, the response will include a JSON of all the records in the App.


"records": [
    {
      "difficulty": {
        "type": "DROP_DOWN",
        "value": null
      },
      "score": {
        "type": "NUMBER",
        "value": "1500"
      },
      "Record Number": {
        "type": "RECORD_NUMBER",
        "value": "7"
      },
      "Updated By": {
        "type": "MODIFIER",
        "value": {
          "code": "Administrator",
          "name": "Administrator"
        }
      },
      "Created By": {
        "type": "CREATOR",
        "value": {
          "code": "Administrator",
          "name": "Administrator"
        }
      },
      "playername": {
        "type": "SINGLE_LINE_TEXT",
        "value": ""
      },
      "$revision": {
        "type": "__REVISION__",
        "value": "1"
      },
      "Updated Datetime": {
        "type": "UPDATED_TIME",
        "value": "2024-10-06T02:33:00Z"
      },
      "Created Datetime": {
        "type": "CREATED_TIME",
        "value": "2024-10-06T02:33:00Z"
      },
      "$id": {
        "type": "__ID__",
        "value": "7"
      }
    },
    {
      "difficulty": {
        "type": "DROP_DOWN",
        "value": "Hard"
      },
      "score": {
        "type": "NUMBER",
        "value": "34000"
      },
      "Record Number": {
        "type": "RECORD_NUMBER",
        "value": "6"
      },
      "Updated By": {
        "type": "MODIFIER",
        "value": {
          "code": "will",
          "name": "will-yama"
        }
      },
      "Created By": {
        "type": "CREATOR",
        "value": {
          "code": "will",
          "name": "will-yama"
        }
      },
      "playername": {
        "type": "SINGLE_LINE_TEXT",
        "value": "Kelly Smiles"
      },
      "$revision": {
        "type": "__REVISION__",
        "value": "1"
      },
      "Updated Datetime": {
        "type": "UPDATED_TIME",
        "value": "2024-10-06T01:41:00Z"
      },
      "Created Datetime": {
        "type": "CREATED_TIME",
        "value": "2024-10-06T01:41:00Z"
      },
      "$id": {
        "type": "__ID__",
        "value": "6"
      }
    },...


We have cut off the above JSON response half way through for this article, as it is quite long.

3. Retrieving Records with Query Filtering

In some cases, you may want to retrieve records based on specific conditions, such as fetching records where the difficulty is set to "Hard". Add a query to the GET request to achieve this.


import requests

def get_all_records():
    API_endpoint = "https://{YOUR_SUBDOMAIN}.cybozu.com/k/v1/records.json"
    app_id = "{APP_ID}"
    query = "difficulty in (\"Hard\")"
    API_endpoint = API_endpoint   "?app="   app_id   "&query="   query

    kintone_headers = {
        "X-Cybozu-API-Token": "{API_TOKEN}",
    }

    try:
        response = requests.get(API_endpoint, headers=kintone_headers)
        jsondata = response.json()
        print(jsondata)

    except requests.exceptions.RequestException as error:
        print(error)

get_all_records()


If the request is successful, the response will include a JSON of the filtered records.


"records": [
{
"difficulty": {
"type": "DROP_DOWN",
"value": "Hard"
},
"score": {
"type": "NUMBER",
"value": "34000"
},
"Record Number": {
"type": "RECORD_NUMBER",
"value": "6"
},
"Updated By": {
"type": "MODIFIER",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"Created By": {
"type": "CREATOR",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"playername": {
"type": "SINGLE_LINE_TEXT",
"value": "Kelly Smiles"
},
"$revision": {
"type": "REVISION",
"value": "1"
},
"Updated Datetime": {
"type": "UPDATED_TIME",
"value": "2024-10-06T01:41:00Z"
},
"Created Datetime": {
"type": "CREATED_TIME",
"value": "2024-10-06T01:41:00Z"
},
"$id": {
"type": "ID",
"value": "6"
}
},
{
"difficulty": {
"type": "DROP_DOWN",
"value": "Hard"
},
"score": {
"type": "NUMBER",
"value": "45000"
},
"Record Number": {
"type": "RECORD_NUMBER",
"value": "5"
},
"Updated By": {
"type": "MODIFIER",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"Created By": {
"type": "CREATOR",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"playername": {
"type": "SINGLE_LINE_TEXT",
"value": "Jay Pudding"
},
"$revision": {
"type": "REVISION",
"value": "1"
},
"Updated Datetime": {
"type": "UPDATED_TIME",
"value": "2024-10-06T01:38:00Z"
},
"Created Datetime": {
"type": "CREATED_TIME",
"value": "2024-10-06T01:38:00Z"
},
"$id": {
"type": "ID",
"value": "5"
}
},
{
"difficulty": {
"type": "DROP_DOWN",
"value": "Hard"
},
"score": {
"type": "NUMBER",
"value": "34000"
},
"Record Number": {
"type": "RECORD_NUMBER",
"value": "2"
},
"Updated By": {
"type": "MODIFIER",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"Created By": {
"type": "CREATOR",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"playername": {
"type": "SINGLE_LINE_TEXT",
"value": "Jam Flipping"
},
"$revision": {
"type": "REVISION",
"value": "2"
},
"Updated Datetime": {
"type": "UPDATED_TIME",
"value": "2024-10-06T01:38:00Z"
},
"Created Datetime": {
"type": "CREATED_TIME",
"value": "2024-10-05T01:26:00Z"
},
"$id": {
"type": "ID",
"value": "2"
}
}
],
"totalCount": null




Conclusion

By setting up a Kintone App and interacting with it via API, you can easily manage data for your projects. Whether you're keeping track of player performances or storing other types of data, Kintone’s flexible API makes it easy to integrate into any hackathon project.

This guide has provided examples for adding records, retrieving all records, and querying records with specific conditions, allowing you to customize your data management according to your needs.

Good luck at your hackathon, and happy coding with Kintone!

版本声明 本文转载于:https://dev.to/kintonedevprogram/tips-for-using-kintone-in-hackathons-3j90?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • 不可变数据结构:ECMA 4 中的记录和元组
    不可变数据结构:ECMA 4 中的记录和元组
    不可变数据结构:ECMAScript 2024 中的新功能 ECMAScript 2024 引入了几个令人兴奋的更新,但对我来说最突出的一个功能是引入了不可变数据结构。这些新结构——记录和元组——改变了 JavaScript 中数据管理的游戏规则。它们提供了一种令人满意的方式来保持...
    编程 发布于2024-11-08
  • 如何在 PHP 中为注册用户自定义 URL?
    如何在 PHP 中为注册用户自定义 URL?
    在 PHP 中为注册用户设置自定义 URL对于电子商务平台来说,为每个用户提供唯一的 URL 对于展示他们的产品至关重要单独的产品。通过生成单独的网址(例如 www.seloncart.com/customername),您可以显示客户的特定产品。为此,请按照下列步骤操作:配置服务器路由: 修改服务...
    编程 发布于2024-11-08
  • 我如何用 Python 创建 QR 码生成器
    我如何用 Python 创建 QR 码生成器
    这将是一篇简短的文章,介绍我如何在 Python 中创建一个简单的二维码生成器 对于此步骤,您需要使用 qrcode 库:https://pypi.org/project/qrcode/ 创建项目文件夹后我所做的第一步就是创建一个虚拟环境。 Python 中的虚拟环境只是计算机上另一个独立的工作区,...
    编程 发布于2024-11-08
  • 如何在 PHP 中验证整数数据类型?
    如何在 PHP 中验证整数数据类型?
    验证 PHP 中的整数数据类型在 PHP 中处理数字数据时,确定变量是否表示整数至关重要。为了解决这个问题,通常使用 is_int() 函数。然而,它的行为有时可能是意想不到的,导致混乱。为了纠正这个问题,我们引入了验证整数数据类型的替代方法:FILTER_VALIDATE_INT使用该方法,可以高...
    编程 发布于2024-11-08
  • 为什么 DOMSubtreeModified 在 DOM Level 3 中被弃用以及替代方案是什么?
    为什么 DOMSubtreeModified 在 DOM Level 3 中被弃用以及替代方案是什么?
    在 DOM Level 3 中弃用 DOMSubtreeModified 事件DOMSubtreeModified 事件曾经是跟踪文档子树中更改的基本元素,现在已被在 DOM level 3 中已过时。了解这种弃用背后的基本原理并确定合适的替代方案至关重要。DOM Level 3 规范对 DOMSu...
    编程 发布于2024-11-08
  • 将 PDO 连接设置为 NULL 是否真正关闭连接并释放资源?
    将 PDO 连接设置为 NULL 是否真正关闭连接并释放资源?
    关闭PDO连接在PHP中,有两种流行的数据库连接接口:MySQLi和PDO。虽然两者的用途相似,但它们处理连接关闭的方式不同。MySQLi 需要显式关闭函数调用来释放连接:$this->connection->close();相反,PDO 使用空赋值来终止连接:$this->con...
    编程 发布于2024-11-08
  • 动态数据管理:了解 Vue.js 中的数据属性
    动态数据管理:了解 Vue.js 中的数据属性
    Vue.js 是用于开发现代 Web 应用程序的最流行的 JavaScript 框架之一。它提供了一种创建交互式动态应用程序的有效方法。在本文中,我们将深入研究 Vue.js 中的 data 属性,并探讨它的工作原理、为什么要使用它以及围绕它的最佳实践。 什么是数据属性? 在Vue....
    编程 发布于2024-11-08
  • 如何有效地检查 Python 字符串中是否存在列表元素?
    如何有效地检查 Python 字符串中是否存在列表元素?
    检查 Python 中字符串中列表元素的存在Python 编程中的一个常见任务是验证字符串是否包含给定的元素列表。传统方法采用 for 循环,如下面的代码所示:extensionsToCheck = ['.pdf', '.doc', '.xls'] for extension in extensio...
    编程 发布于2024-11-08
  • \'window.JSON\' 如何在现代浏览器中提供本机 JSON 支持?
    \'window.JSON\' 如何在现代浏览器中提供本机 JSON 支持?
    浏览器原生 JSON 支持:window.JSON 对象window.JSON 对象为现代 Web 浏览器提供原生 JSON 解析和序列化功能,实现结构化数据的高效、安全处理。本文探讨了该对象的详细信息,包括其支持的方法和浏览器兼容性。window.JSON 公开的方法window.JSON 对象公...
    编程 发布于2024-11-08
  • Java 中的接口继承自对象类吗?
    Java 中的接口继承自对象类吗?
    接口和对象类:继承和方法调用在 Java 中,接口提供了一种定义类可以实现的契约的方法。在考虑接口和Object类的关系时,就提出了继承的问题。接口是否继承自Object类?答案是否。接口不继承自Object 类。与类不同,所有接口都不会隐式继承任何公共根接口。接口实例上的方法调用尽管不是从 Obj...
    编程 发布于2024-11-08
  • Python:有趣的代码模式
    Python:有趣的代码模式
    我主要使用 Python 工作,几乎每天都会检查代码。在我们的代码库中,格式化和 linting 由 CI 作业使用 black 和 mypy 处理。因此,我们只关注变化。 在团队中工作时,您已经知道某个团队成员会编写什么样的代码。当新人加入团队时,代码审查会变得有趣。我说有趣,是因为每个人都有一些...
    编程 发布于2024-11-08
  • 在 Laravel 中使用 Redis 进行缓存:分步指南
    在 Laravel 中使用 Redis 进行缓存:分步指南
    Introduction Laravel is, without fear of contradiction, the most popular PHP framework, and among the most popular within web development. Re...
    编程 发布于2024-11-08
  • 释放实时 UI 的力量:使用 React.js、gRPC、Envoy 和 Golang 流式传输数据的初学者指南
    释放实时 UI 的力量:使用 React.js、gRPC、Envoy 和 Golang 流式传输数据的初学者指南
    作者:Naveen M 背景 作为 Kubernetes 平台团队的一部分,我们面临着提供用户工作负载实时可见性的持续挑战。从监控资源使用情况到跟踪 Kubernetes 集群活动和应用程序状态,每个特定类别都有许多开源解决方案。然而,这些工具往往分散在不同的平台上,导致用户体验支离...
    编程 发布于2024-11-08
  • 构建您自己的操作系统(真的!):初学者 C 编程
    构建您自己的操作系统(真的!):初学者 C 编程
    建立自己的操作系统:安装 C 编译器和工具,如 MinGW-w64。使用汇编语言编写引导加载程序,加载内核。用 C 语言创建内核,包括命令解释器。使用 Makefile 将引导加载程序和内核组合为“os.img”文件。在 VirtualBox 等虚拟机或硬件上运行“os.img”文件。创建自己的操作...
    编程 发布于2024-11-08

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3