{"id":27,"date":"2024-06-01T15:22:41","date_gmt":"2024-06-01T06:22:41","guid":{"rendered":"https:\/\/blog.hy2t.com\/?p=27"},"modified":"2024-07-02T02:44:25","modified_gmt":"2024-07-01T17:44:25","slug":"gas%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6google%e3%82%ab%e3%83%ac%e3%83%b3%e3%83%80%e3%83%bc%e3%81%ae%e4%ba%88%e5%ae%9a%e3%81%ab%e8%89%b2%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab","status":"publish","type":"post","link":"https:\/\/hy2t.com\/?p=27","title":{"rendered":"GAS\u3092\u4f7f\u3063\u3066Google\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u4e88\u5b9a\u306b\u8272\u3092\u3064\u3051\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u305f"},"content":{"rendered":"\n<p>GAS\u3092\u4f7f\u3063\u3066\u666e\u6bb5\u4f7f\u3063\u3066\u3044\u308bGoogle\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u5185\u5bb9\u3067\u8272\u3064\u3051\u308b\u6a5f\u80fd\u306b\u3057\u3066\u3061\u3087\u3063\u3068\u30cf\u30c3\u30af\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u305f<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"258\" src=\"https:\/\/blog.hy2t.com\/wp-content\/uploads\/2024\/06\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-06-01-14.59.50.png\" alt=\"\" class=\"wp-image-28\" srcset=\"https:\/\/hy2t.com\/wp-content\/uploads\/2024\/06\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-06-01-14.59.50.png 480w, https:\/\/hy2t.com\/wp-content\/uploads\/2024\/06\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-06-01-14.59.50-300x161.png 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/figure>\n\n\n\n<p>\u4e88\u5b9a\u304c\u3067\u304d\u305f\u6642\u306b\u30b9\u30de\u30db\u304b\u3089\u3068\u308a\u3042\u3048\u305a\u4e88\u5b9a\u3060\u3051\u5165\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u884c\u304d\u65b9\u3068\u304b\u6700\u5bc4\u99c5\u3092\u8abf\u3079\u306a\u3044\u3068\u884c\u3051\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u305d\u308c\u3092\u78ba\u8a8d\u3057\u3066\u306a\u3044\u305e\u3001\u3063\u3066\u5834\u5408\u306b\u8272\u3092\u5909\u66f4\u3057\u3088\u3046\u3068\u601d\u3063\u3066\u3044\u307e\u3059<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9f65cee7527d489ca96b0804f819a734\"><code># GAS\u306e\u74b0\u5883\u69cb\u7bc9\nnpm init -y\nnpm install @google\/clasp -g\nnpm install @types\/google-apps-script\n\nclasp login\nclasp open\n\n# \u30ea\u30e2\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u30ed\u30fc\u30ab\u30eb\u306b\nclasp pull\n\n# \u30ed\u30fc\u30ab\u30eb\u30b3\u30fc\u30c9\u3092\u30ea\u30e2\u30fc\u30c8\u306b\u9001\u4fe1\nclasp push<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>main.js<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9acd537699606531f08b058ee44cd44a\"><code>function main() {\n  const startDate = new Date(get_current_date()); \/\/ The first date to remove the guest from the events\n  const endDate = new Date(get_next_month_date()); \/\/ The last date to remove the attendee from the events\n  const calender = CalendarApp.getCalendarById('\u81ea\u5206\u306e\u30ab\u30ec\u30f3\u30c0\u30fcID');\n  const events = calender.getEvents(startDate, endDate);\n\n  \/\/ \u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\n  calender_description_empty(events);\n  calender_still_default(events);\n}\n\nfunction calender_description_empty(events) {\n  \/*\n  \u4e88\u5b9a\u3092\u5165\u308c\u305f\u3060\u3051\u306e\u30a4\u30d9\u30f3\u30c8\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\n  @param events \u30ab\u30ec\u30f3\u30c0\u30fc\u30a4\u30d9\u30f3\u30c8\u306e\u914d\u5217\n  *\/\n\n  const schema = schemas();\n  for (let i = 0; i &lt; events.length; i++) {\n    let event = events&#91;i];\n\n    if (!event.getDescription()) {\n      event.setDescription(\n        `def!\n\u51fa\u767a\u6642\u523b: ${schema.default_calender_description.departure_time}\n\u6700\u5bc4\u99c5: ${schema.default_calender_description.nearest_station}\n\u8aac\u660e: ${schema.default_calender_description.description}\n`\n      );\n    }\n  }\n}\n\nfunction calender_still_default(events) {\n  \/*\n  \u4e88\u5b9a\u3092\u5165\u308c\u305f\u3060\u3051\u306e\u30a4\u30d9\u30f3\u30c8\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u306b\u8272\u3092\u8a2d\u5b9a\u3059\u308b\n  @param events \u30ab\u30ec\u30f3\u30c0\u30fc\u30a4\u30d9\u30f3\u30c8\u306e\u914d\u5217\n  *\/\n\n  for (let i = 0; i &lt; events.length; i++) {\n    let event = events&#91;i];\n    console.log(CalendarApp.EventColor.YELLOW)\n    console.log( event.getDescription().includes(\"def!\"))\n\n    if (\n      event.getColor() !== CalendarApp.EventColor.YELLOW &amp;&amp;\n      event.getDescription().includes(\"def!\")\n    ) {\n      event.setColor(CalendarApp.EventColor.YELLOW);\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p>schema.js<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-77c55a06c7c960e75cf547fea8c534c7\"><code>\nfunction schemas() {\n  return  {\n    default_calender_description: {\n      def: \"def\",\n      nearest_station: \"\", \/\/ \u6700\u5bc4\u99c5\n      departure_time: \"\", \/\/ \u51fa\u767a\u6642\u523b\n      description: \"\", \/\/ \u8aac\u660e\n    }\n  };\n}<\/code><\/pre>\n\n\n\n<p>lib.js<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-196e1d3e827560595103033d923629f3\"><code>function get_current_date() {\n  \/* \n  \u5b9f\u884c\u65e5\u306e\u65e5\u4ed8\u3092\u53d6\u5f97 yyyy-mm-dd\n  *\/\n  return new Date().toLocaleDateString('sv-SE') \n}\n\nfunction get_next_month_date() {\n  \/* \n  \u5b9f\u884c\u65e5\u306e\u7fcc\u6708\u306e\u65e5\u4ed8\u3092\u53d6\u5f97 yyyy-mm-dd\n  *\/\n  const d = new Date(new Date().toLocaleDateString())\n d.setMonth(d.getMonth() + 1)\n  return d.toLocaleDateString('sv-SE')\n}<\/code><\/pre>\n\n\n\n<p>\u5b9f\u884c\u65e5\u304b\u3089\uff11\u30f6\u6708\u5f8c\u307e\u3067\u306e\u4e88\u5b9a\u3092\u53d6\u5f97\u3057\u3066\u3001description\u304c\u7a7a\u3060\u3063\u305f\u3089\u8272\u3092\u3064\u3051\u308b\u3063\u3066\u3044\u3046\u5185\u5bb9\u3067\u3059<\/p>\n\n\n\n<p>\u4ed6\u306b\u30ab\u30b9\u30bf\u30e0\u3059\u308b\u5834\u5408\u306fGoogle\u30ab\u30ec\u30f3\u30c0\u30fc\u306edoc\u3092\u53c2\u7167\u304f\u3060\u3055\u3044<\/p>\n\n\n\n<p><a href=\"https:\/\/developers.google.com\/apps-script\/reference\/calendar\/calendar-event?hl=ja\">https:\/\/developers.google.com\/apps-script\/reference\/calendar\/calendar-event?hl=ja<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>GAS\u3092\u4f7f\u3063\u3066\u666e\u6bb5\u4f7f\u3063\u3066\u3044\u308bGoogle\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u5185\u5bb9\u3067\u8272\u3064\u3051\u308b\u6a5f\u80fd\u306b\u3057\u3066\u3061\u3087\u3063\u3068\u30cf\u30c3\u30af\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u305f \u4e88\u5b9a\u304c\u3067\u304d\u305f\u6642\u306b\u30b9\u30de\u30db\u304b\u3089\u3068\u308a\u3042\u3048\u305a\u4e88\u5b9a\u3060\u3051\u5165\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u884c\u304d\u65b9\u3068\u304b\u6700\u5bc4\u99c5\u3092\u8abf\u3079\u306a\u3044\u3068\u884c\u3051\u306a\u304b\u3063\u305f\u308a\u3059\u308b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":70,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"footnotes":""},"categories":[12],"tags":[9],"class_list":["post-27","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-12","tag-gas"],"_links":{"self":[{"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hy2t.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":2,"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/41"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hy2t.com\/index.php?rest_route=\/wp\/v2\/media\/70"}],"wp:attachment":[{"href":"https:\/\/hy2t.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hy2t.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hy2t.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}