{"id":2793,"date":"2019-10-03T10:42:50","date_gmt":"2019-10-03T01:42:50","guid":{"rendered":"http:\/\/uraneko.tcorps.info\/?p=2793"},"modified":"2019-12-13T10:37:36","modified_gmt":"2019-12-13T01:37:36","slug":"splatnet2statink-%e3%81%ae-lambda%e5%8c%96-stat-ink","status":"publish","type":"post","link":"http:\/\/uraneko.tcorps.info\/?p=2793","title":{"rendered":"splatnet2statink \u306e Lambda\u5316 (stat.ink)"},"content":{"rendered":"<p>splatoon2\u306e\u8a18\u9332\u4fdd\u6301\u306b stat.ink \u3092\u4f7f\u3063\u3066\u308b\u308f\u3051\u3060\u304c\u3001EC2 \u3067 splatnet2statink \u3092\u8d70\u3089\u305b\u3066\u3044\u305f\u3068\u3053\u308d\u3001aws\u7121\u6599\u67a0\u671f\u9593\u904e\u304e\u3066\u3057\u307e\u3044EC2\u305f\u305f\u307f\u305f\u3044\u306e\u3067\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067lambda\u5316\u3057\u3088\u3046\u305d\u3046\u3057\u3088\u3046\u3002<\/p>\n<p>\u3053\u3061\u3089\u3092\u53c2\u8003\u306b\u3002<br \/>\nhttps:\/\/engineering.mobalab.net\/2019\/01\/09\/upload-splatoon2-battle-histories-regularly-on-lambda\/<br \/>\nhttps:\/\/github.com\/issei-m\/splatnet2statink-on-lambda<\/p>\n<p>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u5c4b\u306a\u306e\u3067\u30b5\u30fc\u30d0\u30ec\u30b9\u7cfb\u306f\u305a\u3063\u3076\u305a\u3076\u306e\u7d20\u4eba\u3067\u3042\u308a\u3001\u3053\u306e\u305f\u3073\u30cf\u30de\u3063\u305f\u3068\u3053\u308d\u306a\u3069\u3092\u30e1\u30e2\uff1a<\/p>\n<p><!--more--><\/p>\n<ul>\n<li>script \u672c\u4f53\u3060\u3051\u3042\u3063\u3066\u3082\u30c0\u30e1\u3067\u4f9d\u5b58\u95a2\u4fc2\u306b\u3042\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3082\u4e00\u7dd2Lambda\u306b\u4e0a\u3052\u308b\u5fc5\u8981\u3042\u308a<\/li>\n<li>\u4e0a\u8a18github\u306b\u3042\u308b\u306e\u306fseverless\u3068\u3044\u3046framework\u4f7f\u3063\u3066\u307e\u308b\u3063\u3068\u3042\u3052\u3066\u304f\u308c\u308b\u3063\u307d\u3044\n<ul>\n<li>\u3053\u308c\u4f7f\u3046\u3068\u30ed\u30fc\u30ab\u30eb\u3067\u958b\u767a\u3057\u305f\u3082\u306e\u3092\u3059\u308b\u3063\u3068Lambda\u3068\u304b\u306b\u4e0a\u3052\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u307d\u3044<\/li>\n<li>\u4e0a\u8a18\u30ea\u30dd\u30b8\u30c8\u30ea\u306fserverless\u4f7f\u3048\u308b\u74b0\u5883\u304c\u3042\u308b\u524d\u63d0\u307d\u3044<\/li>\n<li>\u30d1\u30c3\u30b1\u30fc\u30b8\u7b49\u3092\u624b\u52d5\u3067\u56fa\u3081\u3066\u4e0a\u3052\u308c\u3070\u52d5\u304f\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u304c\u3001\u697d\u305d\u3046\u306a\u306e\u3067serverless\u74b0\u5883\u4f5c\u3063\u305f<\/li>\n<\/ul>\n<\/li>\n<li>\u304a\u624b\u5143\u306bCent7\u304c\u3042\u3063\u305f\u306e\u3067\u305d\u3053\u304b\u3089deploy<\/li>\n<li>\u5168\u4f53\u7684\u306bPython3.x\u306a\u306e\u3067\u30012.x\u3068\u5206\u3051\u308b\u5fc5\u8981\u304c\u3042\u308b\u306a\u3089\u3046\u307e\u3044\u3053\u3068\u305d\u3046\u3059\u308b\u3000\u203b\u4f5c\u696d\u4e2d\u3053\u306e\u8fba\u3044\u307e\u3044\u3061\u7406\u89e3\u3057\u3066\u306a\u304b\u3063\u305f<\/li>\n<li>serverless\u306ecredential\u3069\u3053\u3067\u8a2d\u7f6e\u3059\u308b\u3093\u3060\u308d\u3068\u601d\u3063\u305f\u304c\u3001awscli \u306b credential \u3092\u8a2d\u5b9a\u3057\u3068\u3051\u3070\u3088\u3055\u3052<\/li>\n<li>\u30b5\u30fc\u30e2\u30f3\u30e9\u30f3\u7d50\u679c\u3082\u4fdd\u5b58\u3059\u308b\u305f\u3081\u3001[&#8220;.\/splatnet2statink.py&#8221;, &#8220;&#8211;salmon&#8221;, &#8220;-r&#8221;] \u3068\u3057\u305f\u51e6\u7406\u3092&#8221;handler.py&#8221;\u306b\u8ffd\u52a0\u3057\u305f\n<ul>\n<li>\u00a0python3 .\/handler.py\u3000\u3067\u671f\u5f85\u901a\u308a\u52d5\u3044\u3066\u3044\u308b\u3088\u3046\u306b\u307f\u3048\u305f\u306e\u3067\u554f\u984c\u306a\u3055\u305d\u3046<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5177\u4f53\u7684\u306b\u3084\u3063\u305f\u3053\u3068\u306f\u4ee5\u4e0b\u3002\u7121\u99c4\u306apython \u306e install\u4f5c\u696d\u304c\u542b\u307e\u308c\u3066\u308b\u6c17\u306f\u3059\u308b\u304c\u3046\u3054\u3044\u305f\u304b\u3089\u307e\u3042\u3001\u3046\u3093\u3002<br \/>\n\u3059\u3067\u306bEC2\u3067\u52d5\u304b\u3057\u3066\u305f\u306e\u3067iksm_session\u3092\u5f15\u304d\u7d99\u3044\u3060\u611f\u3058\u3002<\/p>\n<p># \u4e8b\u524d\u306bAWS\u306bIAM\u304b\u3089\u30a2\u30ab\u30a6\u30f3\u30c8\u4f5c\u3063\u3066\u304a\u304f\u3002\u96e3\u3057\u3044\u3053\u3068\u306f\u3084\u3063\u3066\u3044\u306a\u3044\u304c\u3053\u308c\u3092\u898b\u305f\u2192https:\/\/serverless.com\/framework\/docs\/providers\/aws\/guide\/credentials\/<br \/>\n# \u6a29\u9650\u306fAdmin\u3067\u306f\u306a\u304f\u3053\u308c\uff08https:\/\/gist.github.com\/ServerlessBot\/7618156b8671840a539f405dea2704c8\uff09\u3067\u3082\u52d5\u3044\u305f<br \/>\n# APIKey\u3068SecretKey\u3092\u30e1\u30e2\u3057\u3066\u304a\u304f<\/p>\n<p># NPM, Docker<br \/>\nyum install nodejs npm docker<\/p>\n<p># Serverless<br \/>\nnpm install -g serverless<\/p>\n<p># pyenv, git<br \/>\nyum install gcc zlib-devel bzip2 bzip2-devel readline readline-devel sqlite sqlite-devel openssl openssl-devel git<br \/>\ngit clone https:\/\/github.com\/yyuu\/pyenv.git ~\/.pyenv<\/p>\n<p>#\u74b0\u5883\u5909\u6570<br \/>\nvi .bash_profile<\/p>\n<blockquote>\n<pre>export PYENV_ROOT=\"$HOME\/.pyenv\"\r\nexport PATH=\"$PYENV_ROOT\/bin:$PATH\"\r\neval \"$(pyenv init -)\"<\/pre>\n<\/blockquote>\n<p>source .bash_profile<\/p>\n<p># Python3.6<br \/>\npyenv install 3.6.8<br \/>\npyenv global 3.6.8<\/p>\n<p>easy_install pip<br \/>\npip install virtualenv<br \/>\npip install awscli<\/p>\n<p># aws\u3078\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fc<br \/>\naws configure<\/p>\n<blockquote><p>AWS Access Key ID [None]: xxxx<br \/>\nAWS Secret Access Key [None]: xxxxxxxx<br \/>\nDefault region name [None]: ap-northeast-1<br \/>\nDefault output format [None]: text<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p># \u78ba\u8a8d<br \/>\ncat .aws\/credentials<\/p>\n<p># github\u304b\u3089\u30af\u30ed\u30fc\u30f3<br \/>\nmkdir testgit<br \/>\ncd testgit<br \/>\ngit clone https:\/\/github.com\/issei-m\/splatnet2statink-on-lambda.git<\/p>\n<p># readme\u306b\u5f93\u3046<br \/>\nvirtualenv venv &#8211;python=python3<br \/>\nsource venv\/bin\/activate<br \/>\npip3 install -r requirements.txt<\/p>\n<p>vi config.txt \/\/ \u81ea\u5206\u306eiksm_session\u3082\u3063\u3066\u305f\u306e\u3067\u305d\u308c\u3092\u3044\u308c\u305f<\/p>\n<blockquote><p>{<br \/>\n&#8220;api_key&#8221;: &#8220;xxx&#8221;,<br \/>\n&#8220;cookie&#8221;: &#8220;xxx&#8221;,<br \/>\n&#8220;session_token&#8221;: &#8220;skip&#8221;,<br \/>\n&#8220;user_lang&#8221;: &#8220;en-US&#8221;<br \/>\n}<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p># \u30b5\u30fc\u30e2\u30f3\u30e9\u30f3\u7d50\u679c\u3082\u4fdd\u5b58\u3059\u308b\u305f\u3081\u3001[&#8220;.\/splatnet2statink.py&#8221;, &#8220;&#8211;salmon&#8221;, &#8220;-r&#8221;] \u3068\u3057\u305f\u51e6\u7406\u3092&#8221;handler.py&#8221;\u306b\u8ffd\u52a0<\/p>\n<blockquote><p>import re<br \/>\nimport subprocess<\/p>\n<p>def main(event, context):<br \/>\nresult = subprocess.run([&#8220;.\/splatnet2statink.py&#8221;, &#8220;-r&#8221;], encoding=&#8221;utf-8&#8243;, stdout=subprocess.PIPE)<br \/>\nformatted_result = re.sub(r&#8221;^splatnet2statink .+\\nChecking if there are previously-unuploaded battles&#8230;\\n&#8221;, &#8220;&#8221;,<br \/>\nresult.stdout).strip()<br \/>\nprint(formatted_result)<\/p>\n<p>result2 = subprocess.run([&#8220;.\/splatnet2statink.py&#8221;, &#8220;&#8211;salmon&#8221;, &#8220;-r&#8221;], encoding=&#8221;utf-8&#8243;, stdout=subprocess.PIPE)<br \/>\nformatted_result2 = re.sub(r&#8221;^splatnet2statink .+\\nPulling Salmon Run data from online&#8230;\\nSuccessfully updated your Salmon Run profile.\\nChecking if there are previously-unuploaded shifts&#8230;\\n&#8221;, &#8220;&#8221;,<br \/>\nresult2.stdout).strip()<br \/>\nprint(formatted_result2)<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<br \/>\nmain(&#8220;&#8221;, &#8220;&#8221;)<\/p><\/blockquote>\n<pre><\/pre>\n<pre># \u3066\u3059\u3068<\/pre>\n<pre>python3 .\/handler.py \/\/test<\/pre>\n<p>npm i<br \/>\nnode_modules\/.bin\/sls deploy<\/p>\n<p>\u203b\u9014\u4e2dPython3\u5171\u5b58\u306e\u3042\u305f\u308a\u3067\u6df7\u4e71\u3057\u3066\u3053\u308c\u3082\u3084\u3063\u3066\u305f\u3088\u3046\u306a\u6c17\u304c\u3059\u308b\u304c\u305f\u3076\u3093\u5fc5\u8981\u306a\u3044<br \/>\nyum install -y https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\nyum install python36u python36u-libs python36u-devel python36u-pip<\/p>\n<p>\u203b\u3082\u3057\u30b9\u30d7\u30e9\u57a2\u3092\u8907\u6570\u6301\u3063\u3066\u3066\u30a2\u30ab\u30a6\u30f3\u30c8\u5206\u4f5c\u6210\u3057\u305f\u3044\u5834\u5408\u3001serverless.yml \u306e service\u306e\u306a\u307e\u3048\u3092\u5909\u3048\u308c\u3070\u3088\u3055\u3052\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>splatoon2\u306e\u8a18\u9332\u4fdd\u6301\u306b stat.ink \u3092\u4f7f\u3063\u3066\u308b\u308f\u3051\u3060\u304c\u3001EC2 \u3067 splatnet2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,14,5],"tags":[],"class_list":["post-2793","post","type-post","status-publish","format-standard","hentry","category-11","category-14","category-5"],"_links":{"self":[{"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=\/wp\/v2\/posts\/2793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2793"}],"version-history":[{"count":12,"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=\/wp\/v2\/posts\/2793\/revisions"}],"predecessor-version":[{"id":2809,"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=\/wp\/v2\/posts\/2793\/revisions\/2809"}],"wp:attachment":[{"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2793"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/uraneko.tcorps.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}