{"id":21627,"date":"2025-12-08T09:44:55","date_gmt":"2025-12-08T00:44:55","guid":{"rendered":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/?p=21627"},"modified":"2025-12-08T09:44:55","modified_gmt":"2025-12-08T00:44:55","slug":"%e3%82%b9%e3%83%97%e3%83%ac%e3%83%83%e3%83%89%e3%82%b7%e3%83%bc%e3%83%88%e3%82%92python%e3%81%a7%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e3%81%ab%e3%81%af%ef%bc%9fapi%e8%a8%ad%e5%ae%9a%e3%81%8b%e3%82%89","status":"publish","type":"post","link":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/21627\/","title":{"rendered":"\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092Python\u3067\u64cd\u4f5c\u3059\u308b\u306b\u306f\uff1fAPI\u8a2d\u5b9a\u304b\u3089\u81ea\u52d5\u5316\u307e\u3067"},"content":{"rendered":"<p>Python\u3067Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u64cd\u4f5c\u3059\u308c\u3070\u3001\u624b\u52d5\u5165\u529b\u3084\u96c6\u8a08\u4f5c\u696d\u3092\u81ea\u52d5\u5316\u3057\u3001\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u3084\u30c7\u30fc\u30bf\u5206\u6790\u3092\u52b9\u7387\u5316\u3067\u304d\u307e\u3059\u3002Google Sheets API\u3084gspread\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u8aad\u307f\u66f8\u304d\u304c\u53ef\u80fd\u306b\u306a\u308a\u3001\u5b9a\u671f\u7684\u306a\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u3084\u30c7\u30fc\u30bf\u51e6\u7406\u306e\u81ea\u52d5\u5316\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001Python\u3067\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306e\u74b0\u5883\u8a2d\u5b9a\u304b\u3089\u3001\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3067\u306e\u8aad\u307f\u66f8\u304d\u3001\u30c7\u30fc\u30bf\u5206\u6790\u3068\u306e\u9023\u643a\u307e\u3067\u3001\u5b9f\u52d9\u3067\u4f7f\u3048\u308b\u5b9f\u8df5\u7684\u306a\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<div id=\"post-below-intro\"><\/div><h2>Python\u3067Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u64cd\u4f5c\u3067\u304d\u308b\uff1f<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>Python\u3067Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u306b\u306f\u3001Google Sheets API\u3092\u901a\u3058\u3066\u901a\u4fe1\u3057\u3001gspread\u306a\u3069\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u8aad\u307f\u66f8\u304d\u3092\u884c\u3044\u307e\u3059\u3002<\/b><\/span>\u3053\u308c\u306b\u3088\u308a\u3001\u624b\u52d5\u4f5c\u696d\u3092\u81ea\u52d5\u5316\u3057\u3001\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u51e6\u7406\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>Python\u304b\u3089\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u4ee3\u8868\u7684\u306a\u65b9\u6cd5\u3068\u3057\u30663\u3064\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002\u7b2c1\u306e\u65b9\u6cd5\u306f\u3001Google\u516c\u5f0f\u306eGoogle Sheets API\u3092\u76f4\u63a5\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002\u6700\u3082\u67d4\u8edf\u6027\u304c\u9ad8\u3044\u3067\u3059\u304c\u3001\u30b3\u30fc\u30c9\u304c\u8907\u96d1\u306b\u306a\u308a\u304c\u3061\u3067\u3059\u3002\u7b2c2\u306e\u65b9\u6cd5\u306f\u3001gspread\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3067\u3001API\u3092\u30e9\u30c3\u30d7\u3057\u305f\u4f7f\u3044\u3084\u3059\u3044\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u7b2c3\u306e\u65b9\u6cd5\u306f\u3001pandas\u3068\u9023\u643a\u3057\u3066\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3068\u3057\u3066\u6271\u3046\u65b9\u6cd5\u3067\u3001\u30c7\u30fc\u30bf\u5206\u6790\u306b\u7279\u5316\u3057\u305f\u64cd\u4f5c\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u591a\u304f\u306e\u30e6\u30fc\u30b6\u30fc\u304c\u300cPython \u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8 \u9023\u643a\u300d\u3067\u691c\u7d22\u3059\u308b\u80cc\u666f\u306b\u306f\u3001\u5b9a\u671f\u30ec\u30dd\u30fc\u30c8\u306e\u81ea\u52d5\u5316\u3001\u30c7\u30fc\u30bf\u53ce\u96c6\u306e\u52b9\u7387\u5316\u3001\u8907\u6570\u30b7\u30fc\u30c8\u306e\u7d71\u5408\u51e6\u7406\u3068\u3044\u3063\u305f\u30cb\u30fc\u30ba\u304c\u3042\u308a\u307e\u3059\u3002Python\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u3053\u308c\u3089\u306e\u4f5c\u696d\u3092\u77ed\u3044\u30b3\u30fc\u30c9\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u81ea\u52d5\u64cd\u4f5c\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u696d\u52d9\u304c\u52b9\u7387\u5316\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"summary-box\">\n<ul class=\"summary-box__list summary-box__list\">\n<li>\u58f2\u4e0a\u30c7\u30fc\u30bf\u306e\u81ea\u52d5\u96c6\u8a08<\/li>\n<li>\u5728\u5eab\u7ba1\u7406\u306e\u81ea\u52d5\u66f4\u65b0<\/li>\n<li>\u30a2\u30f3\u30b1\u30fc\u30c8\u7d50\u679c\u306e\u81ea\u52d5\u5206\u6790<\/li>\n<li>\u8907\u6570\u30b7\u30fc\u30c8\u304b\u3089\u306e\u30c7\u30fc\u30bf\u7d71\u5408<\/li>\n<li>\u5b9a\u671f\u7684\u306a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u4f5c\u6210<\/li>\n<\/ul>\n<\/div>\n<h2>\u74b0\u5883\u8a2d\u5b9a\u3068\u6e96\u5099\uff1aGoogle Sheets API\u3092\u4f7f\u3046\u305f\u3081\u306e\u521d\u671f\u8a2d\u5b9a\u306f\uff1f<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>Google Sheets API\u3092\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001Google Cloud Platform\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u8a8d\u8a3c\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/b><\/span>\u4ee5\u4e0b\u3001\u5177\u4f53\u7684\u306a\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3>STEP1\uff1aGoogle Cloud Platform\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210<\/h3>\n<div class=\"summary-box\">\n<div class=\"summary-box__title\"><span class=\"summary-box__title_tag\"><strong>GCP\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u306e\u8a2d\u5b9a\u624b\u9806<\/strong><\/span><\/div>\n<ol class=\"summary-box__list summary-box__list--number\">\n<li><a href=\"https:\/\/console.cloud.google.com\/\" target=\"_blank\" rel=\"noopener\">Google Cloud Console<\/a>\u306b\u30a2\u30af\u30bb\u30b9<\/li>\n<li>\u65b0\u3057\u3044\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\uff08\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u306f\u4efb\u610f\uff09<\/li>\n<li>\u4f5c\u6210\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u9078\u629e<\/li>\n<\/ol>\n<\/div>\n<h3>STEP2\uff1aGoogle Sheets API\u306e\u6709\u52b9\u5316<\/h3>\n<div class=\"summary-box\">\n<div class=\"summary-box__title\"><span class=\"summary-box__title_tag\"><strong>API\u3092\u6709\u52b9\u306b\u3059\u308b\u624b\u9806<\/strong><\/span><\/div>\n<ol class=\"summary-box__list summary-box__list--number\">\n<li>\u300cAPI\u3068\u30b5\u30fc\u30d3\u30b9\u300d\u2192\u300c\u30e9\u30a4\u30d6\u30e9\u30ea\u300d\u3092\u9078\u629e<\/li>\n<li>\u300cGoogle Sheets API\u300d\u3092\u691c\u7d22<\/li>\n<li>\u300c\u6709\u52b9\u306b\u3059\u308b\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af<\/li>\n<li>\u540c\u69d8\u306b\u300cGoogle Drive API\u300d\u3082\u6709\u52b9\u5316\uff08\u63a8\u5968\uff09<\/li>\n<\/ol>\n<\/div>\n<h3>STEP3\uff1a\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u4f5c\u6210\u3068\u8a8d\u8a3c\u60c5\u5831\u53d6\u5f97<\/h3>\n<div class=\"summary-box\">\n<div class=\"summary-box__title\"><span class=\"summary-box__title_tag\"><strong>\u8a8d\u8a3c\u8a2d\u5b9a\u306e\u624b\u9806<\/strong><\/span><\/div>\n<ol class=\"summary-box__list summary-box__list--number\">\n<li>\u300cAPI\u3068\u30b5\u30fc\u30d3\u30b9\u300d\u2192\u300c\u8a8d\u8a3c\u60c5\u5831\u300d\u3092\u9078\u629e<\/li>\n<li>\u300c\u8a8d\u8a3c\u60c5\u5831\u3092\u4f5c\u6210\u300d\u2192\u300c\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u300d\u3092\u9078\u629e<\/li>\n<li>\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\u3092\u5165\u529b\uff08\u4f8b\uff1apython-sheets-access\uff09<\/li>\n<li>\u300c\u4f5c\u6210\u3057\u3066\u7d9a\u884c\u300d\u3092\u30af\u30ea\u30c3\u30af<\/li>\n<\/ol>\n<\/div>\n<h3>STEP4\uff1aJSON\u30ad\u30fc\u30d5\u30a1\u30a4\u30eb\u306e\u53d6\u5f97<\/h3>\n<div class=\"summary-box\">\n<div class=\"summary-box__title\"><span class=\"summary-box__title_tag\"><strong>\u79d8\u5bc6\u9375\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/strong><\/span><\/div>\n<ol class=\"summary-box__list summary-box__list--number\">\n<li>\u4f5c\u6210\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u30af\u30ea\u30c3\u30af<\/li>\n<li>\u300c\u30ad\u30fc\u300d\u30bf\u30d6\u3092\u9078\u629e<\/li>\n<li>\u300c\u9375\u3092\u8ffd\u52a0\u300d\u2192\u300c\u65b0\u3057\u3044\u9375\u3092\u4f5c\u6210\u300d<\/li>\n<li>JSON\u5f62\u5f0f\u3092\u9078\u629e\u3057\u3066\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/li>\n<li>\u30d5\u30a1\u30a4\u30eb\u3092\u5b89\u5168\u306a\u5834\u6240\u306b\u4fdd\u5b58\uff08credentials.json\u7b49\uff09<\/li>\n<\/ol>\n<\/div>\n<h3>STEP5\uff1a\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3078\u306e\u30a2\u30af\u30bb\u30b9\u6a29\u9650\u4ed8\u4e0e<\/h3>\n<div class=\"summary-box\">\n<div class=\"summary-box__title\"><span class=\"summary-box__title_tag\"><strong>\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u306b\u6a29\u9650\u3092\u4ed8\u4e0e<\/strong><\/span><\/div>\n<ol class=\"summary-box__list summary-box__list--number\">\n<li>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fJSON\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f<\/li>\n<li>&#8220;client_email&#8221;\u306e\u5024\u3092\u30b3\u30d4\u30fc<\/li>\n<li>\u64cd\u4f5c\u3057\u305f\u3044\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u958b\u304f<\/li>\n<li>\u300c\u5171\u6709\u300d\u30dc\u30bf\u30f3\u304b\u3089\u30b3\u30d4\u30fc\u3057\u305f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u8ffd\u52a0<\/li>\n<li>\u7de8\u96c6\u6a29\u9650\u3092\u4ed8\u4e0e<\/li>\n<\/ol>\n<\/div>\n<h2>Python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u57fa\u672c\u8a2d\u5b9a\u306f\uff1f<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>\u5fc5\u8981\u306aPython\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u8a8d\u8a3c\u8a2d\u5b9a\u3092\u884c\u3046\u3053\u3068\u3067\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u64cd\u4f5c\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/b><\/span>\u4e3b\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u8a2d\u5b9a\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<h3>\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>pip\u3067\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30b3\u30de\u30f3\u30c9\uff1a<\/p>\n<p># \u57fa\u672c\u30e9\u30a4\u30d6\u30e9\u30ea<\/p>\n<p>pip install gspread<\/p>\n<p>pip install google-auth<\/p>\n<p>pip install google-auth-oauthlib<\/p>\n<p>pip install google-auth-httplib2<\/p>\n<p># \u30c7\u30fc\u30bf\u5206\u6790\u7528\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\uff09<\/p>\n<p>pip install pandas<\/p>\n<p>pip install numpy<\/p>\n<h3>\u4eee\u60f3\u74b0\u5883\u306e\u4f5c\u6210\uff08\u63a8\u5968\uff09<\/h3>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5c02\u7528\u74b0\u5883\u306e\u69cb\u7bc9\uff1a<\/p>\n<p># \u4eee\u60f3\u74b0\u5883\u306e\u4f5c\u6210<\/p>\n<p>python -m venv spreadsheet_env<\/p>\n<p># \u4eee\u60f3\u74b0\u5883\u306e\u6709\u52b9\u5316\uff08Windows\uff09<\/p>\n<p>spreadsheet_envScriptsactivate<\/p>\n<p># \u4eee\u60f3\u74b0\u5883\u306e\u6709\u52b9\u5316\uff08Mac\/Linux\uff09<\/p>\n<p>source spreadsheet_env\/bin\/activate<\/p>\n<p># requirements.txt\u306e\u4f5c\u6210<\/p>\n<p>pip freeze &gt; requirements.txt<\/p>\n<h3>\u8a8d\u8a3c\u8a2d\u5b9a\u306e\u5b9f\u88c5<\/h3>\n<p>\u57fa\u672c\u7684\u306a\u8a8d\u8a3c\u30b3\u30fc\u30c9\uff1a<\/p>\n<p>import gspread<\/p>\n<p>from google.oauth2.service_account import Credentials<\/p>\n<p># \u30b9\u30b3\u30fc\u30d7\u306e\u8a2d\u5b9a<\/p>\n<p>scope = [<\/p>\n<p>&#8216;https:\/\/www.googleapis.com\/auth\/spreadsheets&#8217;,<\/p>\n<p>&#8216;https:\/\/www.googleapis.com\/auth\/drive&#8217;]<\/p>\n<p># \u8a8d\u8a3c\u60c5\u5831\u306e\u8aad\u307f\u8fbc\u307f<\/p>\n<p>credentials = Credentials.from_service_account_file(<\/p>\n<p>&#8216;credentials.json&#8217;,<\/p>\n<p>scopes=scope)<\/p>\n<p># \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u521d\u671f\u5316<\/p>\n<p>client = gspread.authorize(credentials)<\/p>\n<h2>Python\u30b3\u30fc\u30c9\u3067\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u8aad\u307f\u53d6\u308b\u65b9\u6cd5\u306f\uff1f<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>gspread\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u30c7\u30fc\u30bf\u3092\u7c21\u5358\u306b\u8aad\u307f\u53d6\u308a\u3001Python\u3067\u51e6\u7406\u3067\u304d\u307e\u3059\u3002<\/b><\/span>\u57fa\u672c\u7684\u306a\u8aad\u307f\u53d6\u308a\u64cd\u4f5c\u304b\u3089\u9ad8\u5ea6\u306a\u53d6\u5f97\u65b9\u6cd5\u307e\u3067\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3>\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u8aad\u307f\u53d6\u308a<\/h3>\n<p>\u30b7\u30fc\u30c8\u5168\u4f53\u306e\u30c7\u30fc\u30bf\u53d6\u5f97\uff1a<\/p>\n<p># \u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u958b\u304f<\/p>\n<p>spreadsheet = client.open(&#8216;\u30b7\u30fc\u30c8\u540d&#8217;)<\/p>\n<p># \u307e\u305f\u306f\u3001URL\u3067\u958b\u304f<\/p>\n<p># spreadsheet = client.open_by_url(&#8216;https:\/\/docs.google.com\/spreadsheets\/&#8230;&#8217;)<\/p>\n<p># \u6700\u521d\u306e\u30b7\u30fc\u30c8\u3092\u53d6\u5f97<\/p>\n<p>worksheet = spreadsheet.sheet1<\/p>\n<p># \u307e\u305f\u306f\u3001\u30b7\u30fc\u30c8\u540d\u3067\u6307\u5b9a<\/p>\n<p># worksheet = spreadsheet.worksheet(&#8216;Sheet1&#8217;)<\/p>\n<p># \u5168\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/p>\n<p>all_values = worksheet.get_all_values()<\/p>\n<p>print(all_values)<\/p>\n<p># \u8f9e\u66f8\u5f62\u5f0f\u3067\u53d6\u5f97\uff081\u884c\u76ee\u3092\u30ad\u30fc\u3068\u3057\u3066\u4f7f\u7528\uff09<\/p>\n<p>all_records = worksheet.get_all_records()<\/p>\n<p>print(all_records)<\/p>\n<h3>\u7279\u5b9a\u7bc4\u56f2\u306e\u30c7\u30fc\u30bf\u53d6\u5f97<\/h3>\n<p>\u30bb\u30eb\u7bc4\u56f2\u3092\u6307\u5b9a\u3057\u305f\u8aad\u307f\u53d6\u308a\uff1a<\/p>\n<p># \u5358\u4e00\u30bb\u30eb\u306e\u5024\u3092\u53d6\u5f97<\/p>\n<p>cell_value = worksheet.acell(&#8216;A1&#8217;).value<\/p>\n<p>print(f&#8221;A1\u30bb\u30eb\u306e\u5024: {cell_value}&#8221;)<\/p>\n<p># \u7bc4\u56f2\u6307\u5b9a\u3067\u30c7\u30fc\u30bf\u53d6\u5f97<\/p>\n<p>range_values = worksheet.get(&#8216;A1:C10&#8217;)<\/p>\n<p>print(range_values)<\/p>\n<p># \u7279\u5b9a\u884c\u306e\u53d6\u5f97<\/p>\n<p>row_values = worksheet.row_values(3)\u00a0 # 3\u884c\u76ee<\/p>\n<p>print(f&#8221;3\u884c\u76ee\u306e\u30c7\u30fc\u30bf: {row_values}&#8221;)<\/p>\n<p># \u7279\u5b9a\u5217\u306e\u53d6\u5f97<\/p>\n<p>col_values = worksheet.col_values(2)\u00a0 # B\u5217<\/p>\n<p>print(f&#8221;B\u5217\u306e\u30c7\u30fc\u30bf: {col_values}&#8221;)<\/p>\n<h3>pandas\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3078\u306e\u5909\u63db<\/h3>\n<p>\u30c7\u30fc\u30bf\u5206\u6790\u7528\u306e\u5909\u63db\uff1a<\/p>\n<p>import pandas as pd<\/p>\n<p># \u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306b\u5909\u63db<\/p>\n<p>df = pd.DataFrame(worksheet.get_all_records())<\/p>\n<p>print(df.head())<\/p>\n<p># \u7279\u5b9a\u306e\u6761\u4ef6\u3067\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0<\/p>\n<p>filtered_df = df[df[&#8216;\u58f2\u4e0a&#8217;] &gt; 10000]<\/p>\n<p>print(filtered_df)<\/p>\n<p># \u7d71\u8a08\u60c5\u5831\u306e\u53d6\u5f97<\/p>\n<p>print(df.describe())<\/p>\n<h3>\u30d0\u30c3\u30c1\u8aad\u307f\u53d6\u308a\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5411\u4e0a<\/h3>\n<p>\u8907\u6570\u7bc4\u56f2\u306e\u4e00\u62ec\u53d6\u5f97\uff1a<\/p>\n<p># \u8907\u6570\u7bc4\u56f2\u3092\u4e00\u5ea6\u306b\u53d6\u5f97<\/p>\n<p>ranges = [&#8216;A1:B10&#8217;, &#8216;D1:E10&#8217;, &#8216;G1:H10&#8217;]<\/p>\n<p>batch_data = worksheet.batch_get(ranges)<\/p>\n<p>for i, data in enumerate(batch_data):<\/p>\n<p>print(f&#8221;\u7bc4\u56f2{ranges[i]}: {data}&#8221;)<\/p>\n<h2>Python\u30b3\u30fc\u30c9\u3067\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306b\u66f8\u304d\u8fbc\u3080\u65b9\u6cd5\u306f\uff1f<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3078\u306e\u66f8\u304d\u8fbc\u307f\u306f\u3001\u5358\u4e00\u30bb\u30eb\u306e\u66f4\u65b0\u304b\u3089\u5927\u91cf\u30c7\u30fc\u30bf\u306e\u4e00\u62ec\u66f8\u304d\u8fbc\u307f\u307e\u3067\u3001\u69d8\u3005\u306a\u65b9\u6cd5\u3067\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/b><\/span>\u5b9f\u7528\u7684\u306a\u66f8\u304d\u8fbc\u307f\u30d1\u30bf\u30fc\u30f3\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>\u5358\u4e00\u30bb\u30eb\u3078\u306e\u66f8\u304d\u8fbc\u307f<\/h3>\n<p>\u57fa\u672c\u7684\u306a\u66f4\u65b0\u64cd\u4f5c\uff1a<\/p>\n<p># \u5358\u4e00\u30bb\u30eb\u306e\u66f4\u65b0<\/p>\n<p>worksheet.update(&#8216;A1&#8217;, &#8216;Hello, Python!&#8217;)<\/p>\n<p># \u6570\u5024\u306e\u66f8\u304d\u8fbc\u307f<\/p>\n<p>worksheet.update(&#8216;B1&#8217;, 12345)<\/p>\n<p># \u65e5\u4ed8\u306e\u66f8\u304d\u8fbc\u307f<\/p>\n<p>from datetime import datetime<\/p>\n<p>worksheet.update(&#8216;C1&#8217;, datetime.now().strftime(&#8216;%Y-%m-%d&#8217;))<\/p>\n<h3>\u8907\u6570\u30bb\u30eb\u306e\u4e00\u62ec\u66f4\u65b0<\/h3>\n<p>\u52b9\u7387\u7684\u306a\u30d0\u30c3\u30c1\u66f4\u65b0\uff1a<\/p>\n<p># \u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u306e\u30d0\u30c3\u30c1\u66f4\u65b0<\/p>\n<p>values_list = [<\/p>\n<p>[&#8216;\u5546\u54c1A&#8217;, 1000, &#8216;\u5728\u5eab\u3042\u308a&#8217;],<\/p>\n<p>[&#8216;\u5546\u54c1B&#8217;, 2000, &#8216;\u5728\u5eab\u306a\u3057&#8217;],<\/p>\n<p>[&#8216;\u5546\u54c1C&#8217;, 1500, &#8216;\u5728\u5eab\u3042\u308a&#8217;]]<\/p>\n<p># A2\u304b\u3089\u59cb\u307e\u308b\u7bc4\u56f2\u306b\u66f8\u304d\u8fbc\u307f<\/p>\n<p>worksheet.update(&#8216;A2:C4&#8217;, values_list)<\/p>\n<p># \u30d0\u30c3\u30c1\u66f4\u65b0\uff08\u8907\u6570\u7bc4\u56f2\uff09<\/p>\n<p>batch_update_data = [<\/p>\n<p>{&#8216;range&#8217;: &#8216;A1:B2&#8217;,<\/p>\n<p>&#8216;values&#8217;: [[&#8216;Header1&#8217;, &#8216;Header2&#8217;], [&#8216;Data1&#8217;, &#8216;Data2&#8217;]]},<\/p>\n<p>{&#8216;range&#8217;: &#8216;D1:E2&#8217;,<\/p>\n<p>&#8216;values&#8217;: [[&#8216;Header3&#8217;, &#8216;Header4&#8217;], [&#8216;Data3&#8217;, &#8216;Data4&#8217;]]}]<\/p>\n<p>worksheet.batch_update(batch_update_data)<\/p>\n<h3>pandas\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u304b\u3089\u306e\u66f8\u304d\u8fbc\u307f<\/h3>\n<p>\u30c7\u30fc\u30bf\u5206\u6790\u7d50\u679c\u306e\u51fa\u529b\uff1a<\/p>\n<p>import pandas as pd<\/p>\n<p># \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u4f5c\u6210<\/p>\n<p>df = pd.DataFrame({<\/p>\n<p>&#8216;\u65e5\u4ed8&#8217;: pd.date_range(&#8216;2025-01-01&#8217;, periods=5),<\/p>\n<p>&#8216;\u58f2\u4e0a&#8217;: [10000, 12000, 15000, 11000, 13000],<\/p>\n<p>&#8216;\u5229\u76ca&#8217;: [2000, 2400, 3000, 2200, 2600]})<\/p>\n<p># \u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u30ea\u30b9\u30c8\u306b\u5909\u63db<\/p>\n<p>values = df.values.tolist()<\/p>\n<p># \u30d8\u30c3\u30c0\u30fc\u3092\u8ffd\u52a0<\/p>\n<p>values.insert(0, df.columns.tolist())<\/p>\n<p># \u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306b\u66f8\u304d\u8fbc\u307f<\/p>\n<p>worksheet.clear()\u00a0 # \u65e2\u5b58\u30c7\u30fc\u30bf\u3092\u30af\u30ea\u30a2<\/p>\n<p>worksheet.update(&#8216;A1&#8217;, values)<\/p>\n<h3>\u66f8\u5f0f\u8a2d\u5b9a\u306e\u8ffd\u52a0<\/h3>\n<p>\u30bb\u30eb\u306e\u88c5\u98fe\uff1a<\/p>\n<p># \u30bb\u30eb\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u8a2d\u5b9a<\/p>\n<p>worksheet.format(&#8216;A1:C1&#8217;, {<\/p>\n<p>&#8216;textFormat&#8217;: {<\/p>\n<p>&#8216;bold&#8217;: True,<\/p>\n<p>&#8216;fontSize&#8217;: 12},<\/p>\n<p>&#8216;backgroundColor&#8217;: {<\/p>\n<p>&#8216;red&#8217;: 0.9,<\/p>\n<p>&#8216;green&#8217;: 0.9,<\/p>\n<p>&#8216;blue&#8217;: 0.9}})<\/p>\n<p># \u6570\u5024\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u8a2d\u5b9a<\/p>\n<p>worksheet.format(&#8216;B2:B10&#8217;, {<\/p>\n<p>&#8216;numberFormat&#8217;: {<\/p>\n<p>&#8216;type&#8217;: &#8216;NUMBER&#8217;,<\/p>\n<p>&#8216;pattern&#8217;: &#8216;#,##0&#8217;}})<\/p>\n<h2>\u9ad8\u5ea6\u306a\u81ea\u52d5\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3068\u5b9f\u8df5\u4f8b\u306f\uff1f<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>\u5b9a\u671f\u5b9f\u884c\u3084\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u5b9f\u52d9\u3067\u4f7f\u3048\u308b\u5805\u7262\u306a\u81ea\u52d5\u5316\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3067\u304d\u307e\u3059\u3002<\/b><\/span>\u5b9f\u8df5\u7684\u306a\u6d3b\u7528\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>\u5b9a\u671f\u5b9f\u884c\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f5c\u6210<\/h3>\n<p>\u58f2\u4e0a\u30ec\u30dd\u30fc\u30c8\u81ea\u52d5\u751f\u6210\uff1a<\/p>\n<p>import schedule<\/p>\n<p>import time<\/p>\n<p>from datetime import datetime<\/p>\n<p>def daily_report():<\/p>\n<p>try:<\/p>\n<p># \u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u958b\u304f<\/p>\n<p>spreadsheet = client.open(&#8216;\u58f2\u4e0a\u7ba1\u7406&#8217;)<\/p>\n<p>worksheet = spreadsheet.worksheet(&#8216;\u65e5\u6b21\u30ec\u30dd\u30fc\u30c8&#8217;)<\/p>\n<p># \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u58f2\u4e0a\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\uff08\u4eee\u60f3\u7684\u306a\u4f8b\uff09<\/p>\n<p>sales_data = get_sales_data_from_db()<\/p>\n<p># \u30ec\u30dd\u30fc\u30c8\u306e\u4f5c\u6210<\/p>\n<p>report = [<\/p>\n<p>[f&#8221;\u65e5\u6b21\u58f2\u4e0a\u30ec\u30dd\u30fc\u30c8 &#8211; {datetime.now().strftime(&#8216;%Y-%m-%d&#8217;)}&#8221;],<\/p>\n<p>[&#8216;\u5546\u54c1\u540d&#8217;, &#8216;\u8ca9\u58f2\u6570&#8217;, &#8216;\u58f2\u4e0a\u91d1\u984d&#8217;],]<\/p>\n<p>report.extend(sales_data)<\/p>\n<p># \u5408\u8a08\u884c\u306e\u8ffd\u52a0<\/p>\n<p>total_sales = sum([row[2] for row in sales_data])<\/p>\n<p>report.append([&#8216;\u5408\u8a08&#8217;, &#8221;, total_sales])<\/p>\n<p># \u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306b\u66f8\u304d\u8fbc\u307f<\/p>\n<p>worksheet.clear()<\/p>\n<p>worksheet.update(&#8216;A1&#8217;, report)<\/p>\n<p>print(f&#8221;\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u5b8c\u4e86: {datetime.now()}&#8221;)<\/p>\n<p>except Exception as e:<\/p>\n<p>print(f&#8221;\u30a8\u30e9\u30fc\u767a\u751f: {e}&#8221;)<\/p>\n<p>send_error_notification(str(e))<\/p>\n<p># \u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u8a2d\u5b9a<\/p>\n<p>schedule.every().day.at(&#8220;09:00&#8221;).do(daily_report)<\/p>\n<p># \u5b9f\u884c\u30eb\u30fc\u30d7<\/p>\n<p>while True:<\/p>\n<p>schedule.run_pending()<\/p>\n<p>time.sleep(60)<\/p>\n<h3>\u8907\u6570\u30b7\u30fc\u30c8\u306e\u7d71\u5408\u51e6\u7406<\/h3>\n<p>\u30c7\u30fc\u30bf\u96c6\u7d04\u30b9\u30af\u30ea\u30d7\u30c8\uff1a<\/p>\n<p>def consolidate_sheets():<\/p>\n<p># \u8907\u6570\u306e\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53ce\u96c6<\/p>\n<p>sheet_names = [&#8216;\u6771\u4eac\u652f\u5e97&#8217;, &#8216;\u5927\u962a\u652f\u5e97&#8217;, &#8216;\u540d\u53e4\u5c4b\u652f\u5e97&#8217;]<\/p>\n<p>all_data = []<\/p>\n<p>for sheet_name in sheet_names:<\/p>\n<p>try:<\/p>\n<p>spreadsheet = client.open(sheet_name)<\/p>\n<p>worksheet = spreadsheet.sheet1<\/p>\n<p># \u30d8\u30c3\u30c0\u30fc\u3092\u9664\u304f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/p>\n<p>data = worksheet.get_all_values()[1:]<\/p>\n<p># \u652f\u5e97\u540d\u3092\u8ffd\u52a0<\/p>\n<p>for row in data:<\/p>\n<p>row.insert(0, sheet_name)<\/p>\n<p>all_data.extend(data)<\/p>\n<p>except Exception as e:<\/p>\n<p>print(f&#8221;{sheet_name}\u306e\u51e6\u7406\u3067\u30a8\u30e9\u30fc: {e}&#8221;)<\/p>\n<p># \u7d71\u5408\u30b7\u30fc\u30c8\u306b\u66f8\u304d\u8fbc\u307f<\/p>\n<p>master_sheet = client.open(&#8216;\u7d71\u5408\u7ba1\u7406\u8868&#8217;)<\/p>\n<p>master_worksheet = master_sheet.sheet1<\/p>\n<p># \u30d8\u30c3\u30c0\u30fc\u306e\u4f5c\u6210<\/p>\n<p>headers = [&#8216;\u652f\u5e97\u540d&#8217;, &#8216;\u65e5\u4ed8&#8217;, &#8216;\u5546\u54c1&#8217;, &#8216;\u6570\u91cf&#8217;, &#8216;\u91d1\u984d&#8217;]<\/p>\n<p>all_data.insert(0, headers)<\/p>\n<p># \u30c7\u30fc\u30bf\u306e\u66f8\u304d\u8fbc\u307f<\/p>\n<p>master_worksheet.clear()<\/p>\n<p>master_worksheet.update(&#8216;A1&#8217;, all_data)<\/p>\n<p>return len(all_data) &#8211; 1\u00a0 # \u30c7\u30fc\u30bf\u4ef6\u6570\u3092\u8fd4\u3059<\/p>\n<h3>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u30ed\u30b0\u8a18\u9332<\/h3>\n<p>\u5b89\u5b9a\u3057\u305f\u52d5\u4f5c\u3092\u5b9f\u73fe\u3059\u308b\u4ed5\u7d44\u307f\uff1a<\/p>\n<p>import logging<\/p>\n<p>from typing import Optional, List, Dict<\/p>\n<p># \u30ed\u30b0\u8a2d\u5b9a<\/p>\n<p>logging.basicConfig(<\/p>\n<p>filename=&#8217;spreadsheet_operations.log&#8217;,<\/p>\n<p>level=logging.INFO,<\/p>\n<p>format=&#8217;%(asctime)s &#8211; %(levelname)s &#8211; %(message)s&#8217;)<\/p>\n<p>class SpreadsheetManager:<\/p>\n<p>def __init__(self, credentials_file: str):<\/p>\n<p>self.client = self._initialize_client(credentials_file)<\/p>\n<p>self.retry_count = 3<\/p>\n<p>def _initialize_client(self, credentials_file: str):<\/p>\n<p>try:<\/p>\n<p>scope = [<\/p>\n<p>&#8216;https:\/\/www.googleapis.com\/auth\/spreadsheets&#8217;,<\/p>\n<p>&#8216;https:\/\/www.googleapis.com\/auth\/drive&#8217;]<\/p>\n<p>credentials = Credentials.from_service_account_file(<\/p>\n<p>credentials_file,<\/p>\n<p>scopes=scope)<\/p>\n<p>return gspread.authorize(credentials)<\/p>\n<p>except Exception as e:<\/p>\n<p>logging.error(f&#8221;\u8a8d\u8a3c\u30a8\u30e9\u30fc: {e}&#8221;)<\/p>\n<p>raise<\/p>\n<p>def safe_update(self,<\/p>\n<p>sheet_name: str,<\/p>\n<p>range_name: str,<\/p>\n<p>values: List[List]) -&gt; bool:<\/p>\n<p>&#8220;&#8221;&#8221;<\/p>\n<p>\u5b89\u5168\u306a\u66f4\u65b0\u51e6\u7406\uff08\u30ea\u30c8\u30e9\u30a4\u6a5f\u80fd\u4ed8\u304d\uff09<\/p>\n<p>&#8220;&#8221;&#8221;<\/p>\n<p>for attempt in range(self.retry_count):<\/p>\n<p>try:<\/p>\n<p>spreadsheet = self.client.open(sheet_name)<\/p>\n<p>worksheet = spreadsheet.sheet1<\/p>\n<p>worksheet.update(range_name, values)<\/p>\n<p>logging.info(f&#8221;\u66f4\u65b0\u6210\u529f: {sheet_name} &#8211; {range_name}&#8221;)<\/p>\n<p>return True<\/p>\n<p>except gspread.exceptions.APIError as e:<\/p>\n<p>if e.response.status_code == 429:\u00a0 # Rate limit<\/p>\n<p>wait_time = 2 ** attempt<\/p>\n<p>logging.warning(f&#8221;Rate limit. {wait_time}\u79d2\u5f85\u6a5f&#8230;&#8221;)<\/p>\n<p>time.sleep(wait_time)<\/p>\n<p>else:<\/p>\n<p>logging.error(f&#8221;API\u30a8\u30e9\u30fc: {e}&#8221;)<\/p>\n<p>break<\/p>\n<p>except Exception as e:<\/p>\n<p>logging.error(f&#8221;\u4e88\u671f\u3057\u306a\u3044\u30a8\u30e9\u30fc: {e}&#8221;)<\/p>\n<p>break<\/p>\n<p>return False<\/p>\n<h2>\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u969b\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u969b\u306f\u3001API\u306e\u5236\u9650\u3092\u8003\u616e\u3057\u3001\u52b9\u7387\u7684\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/b><\/span>\u5b9f\u52d9\u3067\u4f7f\u3048\u308b\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>API\u30ec\u30fc\u30c8\u5236\u9650\u3078\u306e\u5bfe\u5fdc<\/h3>\n<p>\u5236\u9650\u56de\u907f\u306e\u30c6\u30af\u30cb\u30c3\u30af\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5236\u9650\u9805\u76ee<\/th>\n<th>\u4e0a\u9650<\/th>\n<th>\u5bfe\u7b56<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8aad\u307f\u53d6\u308a<\/td>\n<td style=\"text-align: left;\">100\u30ea\u30af\u30a8\u30b9\u30c8\/100\u79d2<\/td>\n<td style=\"text-align: left;\">\u30d0\u30c3\u30c1\u8aad\u307f\u53d6\u308a\u3092\u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u66f8\u304d\u8fbc\u307f<\/td>\n<td style=\"text-align: left;\">100\u30ea\u30af\u30a8\u30b9\u30c8\/100\u79d2<\/td>\n<td style=\"text-align: left;\">\u30d0\u30c3\u30c1\u66f4\u65b0\u3092\u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u30bb\u30eb\u6570<\/td>\n<td style=\"text-align: left;\">1000\u4e07\u30bb\u30eb\/\u30b7\u30fc\u30c8<\/td>\n<td style=\"text-align: left;\">\u30c7\u30fc\u30bf\u3092\u5206\u5272<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b9f\u88c5\u4f8b\uff1a<\/p>\n<p>import time<\/p>\n<p>from typing import List<\/p>\n<p>def batch_process_with_delay(data_chunks: List, delay: float = 1.0):<\/p>\n<p>&#8220;&#8221;&#8221;<\/p>\n<p>\u30c1\u30e3\u30f3\u30af\u3054\u3068\u306b\u9045\u5ef6\u3092\u5165\u308c\u306a\u304c\u3089\u51e6\u7406<\/p>\n<p>&#8220;&#8221;&#8221;<\/p>\n<p>for i, chunk in enumerate(data_chunks):<\/p>\n<p>process_chunk(chunk)<\/p>\n<p># \u6700\u5f8c\u306e\u30c1\u30e3\u30f3\u30af\u3067\u306a\u3051\u308c\u3070\u5f85\u6a5f<\/p>\n<p>if i &lt; len(data_chunks) &#8211; 1:<\/p>\n<p>time.sleep(delay)<\/p>\n<h3>\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u6d3b\u7528<\/h3>\n<p>\u30c7\u30fc\u30bf\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b9f\u88c5\uff1a<\/p>\n<p>import pickle<\/p>\n<p>from datetime import datetime, timedelta<\/p>\n<p>class DataCache:<\/p>\n<p>def __init__(self, cache_file=&#8217;cache.pkl&#8217;):<\/p>\n<p>self.cache_file = cache_file<\/p>\n<p>self.cache_duration = timedelta(hours=1)<\/p>\n<p>def get_or_fetch(self, key: str, fetch_function):<\/p>\n<p># \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u8aad\u307f\u8fbc\u307f<\/p>\n<p>cache = self._load_cache()<\/p>\n<p># \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u6709\u52b9\u6027\u78ba\u8a8d<\/p>\n<p>if key in cache:<\/p>\n<p>data, timestamp = cache[key]<\/p>\n<p>if datetime.now() &#8211; timestamp &lt; self.cache_duration:<\/p>\n<p>return data<\/p>\n<p># \u65b0\u898f\u53d6\u5f97\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u4fdd\u5b58<\/p>\n<p>data = fetch_function()<\/p>\n<p>cache[key] = (data, datetime.now())<\/p>\n<p>self._save_cache(cache)<\/p>\n<p>return data<\/p>\n<h2>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3068\u30c7\u30fc\u30bf\u4fdd\u8b77\u306e\u8003\u616e\u4e8b\u9805<\/h2>\n<p><span style=\"background-color: #ffff99;\"><b>\u8a8d\u8a3c\u60c5\u5831\u306e\u7ba1\u7406\u306f\u6975\u3081\u3066\u91cd\u8981\u3067\u3059\u3002<\/b><\/span>JSON\u30ad\u30fc\u30d5\u30a1\u30a4\u30eb\u306f\u7d76\u5bfe\u306bGit\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u30b3\u30df\u30c3\u30c8\u305b\u305a\u3001\u74b0\u5883\u5909\u6570\u3084\u79d8\u5bc6\u7ba1\u7406\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u7528\u3057\u3066\u4fdd\u8b77\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u6700\u5c0f\u6a29\u9650\u306e\u539f\u5247\u306b\u5f93\u3044\u3001\u5fc5\u8981\u6700\u5c0f\u9650\u306e\u30b9\u30b3\u30fc\u30d7\u306e\u307f\u3092\u8981\u6c42\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3082\u5fd8\u308c\u305a\u306b\u5b9f\u88c5\u3057\u307e\u3057\u3087\u3046\u3002\u91cd\u8981\u306a\u66f4\u65b0\u524d\u306b\u306f\u5fc5\u305a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u5f97\u3057\u3001\u30a8\u30e9\u30fc\u6642\u306b\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3067\u304d\u308b\u4ed5\u7d44\u307f\u3092\u6e96\u5099\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n<h2>Python\u3068\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8API\u9023\u643a\u3067\u696d\u52d9\u3092\u81ea\u52d5\u5316<\/h2>\n<p>Python\u3068Google Sheets API\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u66f4\u65b0\u3084\u96c6\u8a08\u3001\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u3092\u81ea\u52d5\u5316\u3057\u3001\u65e5\u5e38\u696d\u52d9\u306e\u52b9\u7387\u3092\u5927\u5e45\u306b\u9ad8\u3081\u3089\u308c\u307e\u3059\u3002gspread\u306a\u3069\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3059\u308c\u3070\u3001\u77ed\u3044\u30b3\u30fc\u30c9\u3067\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u66f8\u304d\u3084\u6574\u5f62\u304c\u53ef\u80fd\u3067\u3059\u3002\u3055\u3089\u306b\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u5b9f\u884c\u3084\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u5b89\u5b9a\u3057\u305f\u81ea\u52d5\u51e6\u7406\u304c\u5b9f\u73fe\u3057\u307e\u3059\u3002<\/p>\n<p>API\u306e\u5236\u9650\u3084\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u3092\u7406\u89e3\u3057\u305f\u4e0a\u3067\u6700\u9069\u5316\u3092\u884c\u3046\u3053\u3068\u3067\u3001\u4fe1\u983c\u6027\u306e\u9ad8\u3044\u81ea\u52d5\u5316\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u3067Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u64cd\u4f5c\u3059\u308c\u3070\u3001\u624b\u52d5\u5165\u529b\u3084\u96c6\u8a08\u4f5c\u696d\u3092\u81ea\u52d5\u5316\u3057\u3001\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210\u3084\u30c7\u30fc\u30bf\u5206\u6790\u3092\u52b9\u7387\u5316\u3067\u304d\u307e\u3059\u3002Google Sheets API\u3084gspread\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089 [&hellip;]<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[51],"tags":[],"class_list":["post-21627","post","type-post","status-publish","format-standard","hentry","category-excel"],"acf":{"pdf-dlbox-url":"","templatesbox-title":"\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8","templatesbox-img1-url":"","templatesbox-img1-title":"","templatesbox-img2-url":"","templatesbox-img2-title":"","templatesbox-desc":"\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u7121\u6599\u3067\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002\u305c\u3072\u3054\u81ea\u7531\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u6d3b\u7528\u304f\u3060\u3055\u3044\u3002","templatesbox-btn-text":"\u7121\u6599\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b","templatesbox-link":""},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/posts\/21627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/comments?post=21627"}],"version-history":[{"count":10,"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/posts\/21627\/revisions"}],"predecessor-version":[{"id":21763,"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/posts\/21627\/revisions\/21763"}],"wp:attachment":[{"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/media?parent=21627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/categories?post=21627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/biz.moneyforward.com\/work-efficiency\/basic\/wp-json\/wp\/v2\/tags?post=21627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}