{"id":4163,"date":"2019-07-19T17:18:20","date_gmt":"2019-07-19T08:18:20","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=4163"},"modified":"2019-07-19T17:18:20","modified_gmt":"2019-07-19T08:18:20","slug":"laravel-python-%e3%81%a7%e3%82%a6%e3%82%a7%e3%83%96%e3%82%b5%e3%82%a4%e3%83%88%e3%81%ae%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=4163","title":{"rendered":"Laravel + Python \u3067\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u7a81\u7136PR\u307f\u305f\u3044\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3053\u306e\u30d6\u30ed\u30b0\u306e\u30e1\u30cb\u30e5\u30fc\u306b\u3042\u308b<a href=\"https:\/\/www.prerele.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">prerele<\/a>\u3068\u3044\u3046\u7121\u6599\u30d7\u30ec\u30b9\u30ea\u30ea\u30fc\u30b9\u914d\u4fe1\u30b5\u30a4\u30c8\u306f\u79c1\u304c\u7ba1\u7406\u3092\u3057\u3066\u3044\u308b\u30b5\u30a4\u30c8\u3067\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u3053\u306e\u30b5\u30a4\u30c8\u306f\u6b63\u76f4\u30dc\u30e9\u30f3\u30c6\u30a3\u30a2\u306e\u3088\u3046\u306a\u5f62\u3067\u904b\u55b6\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u307b\u3069\u983b\u7e41\u306b\u62e1\u5f35\u3057\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u3053\u306e\u9593\u30d7\u30ec\u30b9\u30ea\u30ea\u30fc\u30b9\u306e\u30da\u30fc\u30b8\u306b\u4f55\u304b\u5909\u66f4\u3092\u52a0\u3048\u3089\u308c\u308b\u3082\u306e\u306f\u306a\u3044\u304b\u3068\u8003\u3048\u3066\u3044\u308b\u3068\u3001\u300c\u3042\u308b\u4fbf\u5229\u306a\u30a6\u30a7\u30d6\u30b5\u30fc\u30d3\u30b9\u300d\u3092\u9577\u5e74\u5229\u7528\u3055\u305b\u3066\u3082\u3089\u3063\u3066\u3044\u308b\u3053\u3068\u306b\u6c17\u304c\u3064\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u304c<strong style=\"font-size: 35px;\">\u300c\u30b5\u30e0\u30cd\u30a4\u30eb\u300d<\/strong>\u3067\u3059\u3002<\/p>\n<p>\u30b5\u30fc\u30d3\u30b9\u540d\u306f\u300c<a href=\"https:\/\/blinky.nemui.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Blinky<\/a>\uff08\u65e7\u30fbMozShot\uff09\u300d\u3068\u3044\u3046\u306e\u3067\u3059\u304c\u3001\u306a\u3093\u3068\u3053\u306e\u30b5\u30fc\u30d3\u30b9\u3002URL\u3092\u3064\u3051\u3066\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3060\u3051\u3067\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u8868\u793a\u3057\u3066\u304f\u308c\u308b\u3068\u3044\u3046\u795e\u304c\u304b\u3063\u305f\u3082\u306e\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5f53\u521d\u306f\u300c\u3053\u3093\u306a\u3044\u3044\u30b5\u30fc\u30d3\u30b9\u3001\u304d\u3063\u3068\u3059\u3050\u6709\u6599\u5316\u3059\u308b\u304b\u306a\u304f\u306a\u3063\u3061\u3083\u3046\u3093\u3060\u308d\u3046\u306a\u30fc\ud83d\ude05\u300d\u306a\u3093\u3066\u601d\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u8a18\u61b6\u304c\u6b63\u3057\u3051\u308c\u3070\uff14\u301c\uff15\u5e74\u306f\u666e\u901a\u306b\u7121\u6599\u3067\u5229\u7528\u53ef\u80fd\u306a\u307e\u307e\u3067\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u3053\u306e<strong>\u300cBlinky\u300d<\/strong>\u306e\u3088\u3046\u306b\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u3064\u304f\u308b\u30b3\u30fc\u30c9\u3092\u3054\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\uff08\u305f\u3060\u3057\u3001Blinky\u306f\u6c17\u306b\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3053\u306e\u307e\u307e\u4f7f\u308f\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002Thank you\ud83d\ude0a\u2728\uff09<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3467 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9.png\" alt=\"\" width=\"216\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9.png 216w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9-203x300.png 203w\" sizes=\"auto, (max-width: 216px) 100vw, 216px\" \/><\/p>\n<p>\u958b\u767a\u74b0\u5883\uff1a Ubuntu 18.04\u3001Python 2.7\u3001Laravel 5.8<\/p>\n<h1>\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u3064\u304f\u308b\u4ed5\u7d44\u307f<\/h1>\n<p>\u3055\u3059\u304c\u306b<code>PHP<\/code>\u3060\u3051\u3067\u306f\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306f\u51fa\u6765\u306a\u3044\u306e\u3067\u3001\u30b3\u30de\u30f3\u30c9\u304b\u3089<code>Google Chrome<\/code>\uff08\u6b63\u78ba\u306b\u306f<code>Chromium<\/code>\uff09\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u306e\u3082\u3001<code>Google Chrome<\/code>\u306f\u30d0\u30fc\u30b8\u30e7\u30f3<code>59<\/code>\u304b\u3089\u30d8\u30c3\u30c9\u30ec\u30b9\uff08\u753b\u9762\u306b\u8868\u793a\u3057\u306a\u3044\uff09\u30e2\u30fc\u30c9\u304c\u8ffd\u52a0\u3055\u308c\u305f\u306e\u3067\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u3044\u308d\u3044\u308d\u306a\u64cd\u4f5c\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u304b\u3089\u306a\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u3064\u304f\u308b\u624b\u9806\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308bURL\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u8ffd\u52a0\u3059\u308b<\/li>\n<li>\u30bf\u30a4\u30de\u30fc\u8a2d\u5b9a\u3067\u5b9a\u671f\u7684\u306bPython\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3057\u3001Chrome\u3092\u64cd\u4f5c\u3057\u3066\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u3068\u308b<\/li>\n<li>\u4f5c\u6210\u3055\u308c\u305f\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u52a0\u5de5\u3057\u3066\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b<\/li>\n<\/ol>\n<p>\u203b \u3064\u307e\u308a\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u9593\u306b\u5165\u308c\u308b\u3053\u3068\u3067<code>Laravel<\/code>\u306a\u3069\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3068<code>Python<\/code>\u306e\u9023\u643a\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3072\u3068\u3064\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1>\u74b0\u5883\u3092\u6574\u3048\u308b<\/h1>\n<h2>Chromium\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u3067\u306f\u3001\u307e\u305a\u306f\u5b9f\u884c\u74b0\u5883\u3092\u6574\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n<code>Ubuntu<\/code>\u306b<code>Chromium<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>sudo apt install chromium-browser<\/strong><\/pre>\n<h2>mysql-connector\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u307e\u305f\u3001<code>Python<\/code>\u304b\u3089<code>MySQL<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3067<code>pip<\/code>\u3067<code>mysql-connector<\/code>\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>pip install mysql-connector<\/strong><\/pre>\n<h2>DB\u30c6\u30fc\u30d6\u30eb\u3092\u3064\u304f\u308b<\/h2>\n<p>\u305d\u3057\u3066\u3001<code>Python<\/code>\u3068<code>PHP<\/code>\u306e\u4ef2\u4ecb\u5f79\u306b\u306a\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30fb\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\u3067\u3059\u3002<br \/>\n<code>Laravel<\/code>\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u79fb\u52d5\u3057\u3066\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:model Screenshot -m<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<\/p>\n<p><code>\/database\/migrations\/****_**_**_******_create_screenshots_table.php<\/code><\/p>\n<p>\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\n\r\nclass CreateScreenshotsTable extends Migration\r\n{\r\n    <strong>public function up()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        Schema::create('screenshots', function (Blueprint $table) {<\/strong>\r\n<strong>            $table-&gt;bigIncrements('id');<\/strong>\r\n<strong>            $table-&gt;string('title');<\/strong>\r\n<strong>            $table-&gt;string('url');<\/strong>\r\n<strong>            $table-&gt;string('status')-&gt;default('waiting');<\/strong>\r\n<strong>            $table-&gt;timestamps();<\/strong>\r\n<strong>        });<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function down()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        Schema::dropIfExists('screenshots');<\/strong>\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4165\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_1.png\" alt=\"\" width=\"357\" height=\"296\" \/><\/p>\n<h2>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3059\u308b<\/h2>\n<p>\u306a\u304a\u3001\u672c\u6765\u306f<code>Laravel<\/code>\u306b\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3059\u308b\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u3079\u304d\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u4f5c\u6210\u304c\u30e1\u30a4\u30f3\u306a\u306e\u3067\u3001\u30c7\u30fc\u30bf\u306f\u4e8b\u524d\u306b<code>Seeder<\/code>\u3092\u4f7f\u3063\u3066\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:seed ScreenshotsTableSeeder<\/strong><\/pre>\n<p><code>\/database\/seeds\/ScreenshotsTableSeeder.php<\/code>\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Database\\Seeder;\r\nuse \\Illuminate\\Support\\Str;\r\n\r\nclass ScreenshotsTableSeeder extends Seeder\r\n{\r\n    public function run()\r\n    {\r\n        <strong>$websites = [<\/strong>\r\n<strong>            ['title' =&gt; '\u30e4\u30d5\u30fc!', 'url' =&gt; 'https:\/\/www.yahoo.co.jp\/'],<\/strong>\r\n<strong>            ['title' =&gt; 'Google', 'url' =&gt; 'https:\/\/www.google.com\/'],<\/strong>\r\n<strong>            ['title' =&gt; 'Amazon', 'url' =&gt; 'https:\/\/www.amazon.co.jp\/'],<\/strong>\r\n<strong>            ['title' =&gt; 'Microsoft', 'url' =&gt; 'https:\/\/www.microsoft.com\/'],<\/strong>\r\n<strong>            ['title' =&gt; 'Apple', 'url' =&gt; 'https:\/\/www.apple.com\/'],<\/strong>\r\n<strong>        ];<\/strong>\r\n\r\n<strong>        foreach ($websites as $website) {<\/strong>\r\n\r\n<strong>            $screenshot = new \\App\\Screenshot();<\/strong>\r\n<strong>            $screenshot-&gt;title = $website['title'];<\/strong>\r\n<strong>            $screenshot-&gt;url = $website['url'];<\/strong>\r\n<strong>            $screenshot-&gt;save();<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u5185\u5bb9\u3068\u3057\u3066\u306f\u3001\u8ab0\u3067\u3082\u77e5\u3063\u3066\u308b\u300cGAFA + \u30e4\u30d5\u30fc!\u300d\u306e\u30b5\u30a4\u30c8\u540d\u3068URL\u3092\u767b\u9332\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002\uff08<code>status<\/code>\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u306e<code>waiting<\/code>\u306b\u306a\u308a\u307e\u3059\uff09<\/p>\n<p>\u305d\u3057\u3066\u3001<code>\/database\/seeds\/DatabaseSeeder.php<\/code>\u3092\u958b\u3044\u3066<code>run()<\/code>\u5185\u306b\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>public function run()\r\n{\r\n     <strong>$this-&gt;call(ScreenshotsTableSeeder::class);<\/strong>\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u3092\u5b9f\u884c\u3057\u3066<code>Seeder<\/code>\u304b\u3089\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan db:seed\r\n<\/strong>\r\n# \u3082\u3057\u304f\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u4e00\u65b0\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u3061\u3089\r\n<strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u5b8c\u4e86\u3059\u308b\u3068\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4168\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/internet_cafe_6.png\" alt=\"\" width=\"659\" height=\"368\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/internet_cafe_6.png 659w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/internet_cafe_6-300x168.png 300w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/p>\n<h2>\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p>\u4eca\u56de\u306f\u4f5c\u6210\u3055\u308c\u305f\u30b5\u30e0\u30cd\u30a4\u30eb\u3092<code>storage<\/code>\u5185\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u4fdd\u5b58\u3057\u307e\u3059\u304c\u3001\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<code>storage<\/code>\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan storage:link<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001<code>\/storage\/app\/public\/<\/code>\u30d5\u30a9\u30eb\u30c0\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u4e2d\u306b<code>thumbnails<\/code>\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u203b \u3082\u3061\u308d\u3093<code>sudo chmod 777 thumbnails -R<\/code>\u306a\u3069\u3068\u3057\u3066\u66f8\u304d\u8fbc\u307f\u6a29\u9650\u3092\u3064\u3051\u308b\u306e\u3082\u5fd8\u308c\u305a\u884c\u3063\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4170\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_3.png\" alt=\"\" width=\"445\" height=\"123\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_3.png 445w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_3-300x83.png 300w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><\/p>\n<h1>\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308bPython\u30b3\u30fc\u30c9\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3084\u3063\u3068\u30e1\u30a4\u30f3\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210\u90e8\u5206\u3067\u3059\u3002<br \/>\n<code>Laravel<\/code>\u3067\u306f\u306a\u304f<code>Python<\/code>\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u9069\u5f53\u306a\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b<code>generate_thumbnail.py<\/code>\u3068\u3044\u3046\u3088\u3046\u306a\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\nimport os\r\nimport sys\r\nimport mysql.connector\r\n\r\n# \u5b9a\u6570\uff08\u5909\u66f4\u304c\u5fc5\u8981\u306a\u5834\u6240\uff09\r\n<strong>THUMBNAIL_PATH = '\/\uff08Laravel\u306e\u30d5\u30a9\u30eb\u30c0\u30fb\u30d1\u30b9\uff09\/storage\/app\/public\/thumbnails'<\/strong>\r\n<strong>DB_HOST = 'DB_HOST'<\/strong>\r\n<strong>DB_DATABASE = 'DB_DATABASE'<\/strong>\r\n<strong>DB_USERNAME = 'DB_USER'<\/strong>\r\n<strong>DB_PASSWORD = 'DB_PASSWORD'<\/strong>\r\n\r\n# DB\u63a5\u7d9a\r\n<strong>try:<\/strong>\r\n<strong>    db = mysql.connector.connect(<\/strong>\r\n<strong>            host=DB_HOST,<\/strong>\r\n<strong>            database=DB_DATABASE,<\/strong>\r\n<strong>            user=DB_USERNAME,<\/strong>\r\n<strong>            passwd=DB_PASSWORD<\/strong>\r\n<strong>        )<\/strong>\r\n<strong>except:<\/strong>\r\n<strong>    print('[Error] DB\u63a5\u7d9a\u5931\u6557\u3002')<\/strong>\r\n<strong>    exit()<\/strong>\r\n\r\n# DB\u304b\u3089\uff11\u4ef6\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\r\n<strong>query = 'SELECT id, url FROM screenshots WHERE status = \"waiting\" ORDER BY id ASC LIMIT 1'<\/strong>\r\n<strong>cursor = db.cursor()<\/strong>\r\n<strong>cursor.execute(query)<\/strong>\r\n<strong>result = cursor.fetchone()<\/strong>\r\n<strong>if result == None:<\/strong>\r\n<strong>    print('[Warning] \u30c7\u30fc\u30bf\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\u3002')<\/strong>\r\n<strong>    exit()<\/strong>\r\n\r\n# \u30b3\u30de\u30f3\u30c9\u5b9f\u884c\uff08\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210\uff09\r\n<strong>id = result[0]<\/strong>\r\n<strong>url = result[1]<\/strong>\r\n<strong>filename = str(id) +'.png'<\/strong>\r\n<strong>original_filename = 'original_'+ filename<\/strong>\r\n<strong>moving_path = THUMBNAIL_PATH +'\/'+ filename<\/strong>\r\n<strong>commands = [<\/strong>\r\n<strong>    'chromium-browser --headless --disable-gpu --hide-scrollbars --screenshot='+ original_filename +' --window-size=1000,1000 '+ url,<\/strong>\r\n<strong>    'convert '+ original_filename +' -resize 92x92 '+ filename,<\/strong>\r\n<strong>    'rm '+ original_filename,<\/strong>\r\n<strong>    'mv '+ filename +' '+ moving_path<\/strong>\r\n<strong>]<\/strong>\r\n\r\n<strong>status = 'failed';<\/strong>\r\n<strong>try:<\/strong>\r\n<strong>    for command in commands:<\/strong>\r\n<strong>        os.system(command)<\/strong>\r\n<strong>    status = 'completed'<\/strong>\r\n<strong>except:<\/strong>\r\n<strong>    pass\r\n<\/strong>\r\n# \u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u66f4\u65b0\r\n<strong>query = 'UPDATE screenshots SET status = \"%s\" WHERE id = %d' % (status, id)<\/strong>\r\n<strong>cursor = db.cursor()<\/strong>\r\n<strong>cursor.execute(query)<\/strong>\r\n<strong>db.commit()<\/strong><\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<h2>\u5b9a\u6570<\/h2>\n<p>\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u60c5\u5831\u3067\u3059\u3002<\/p>\n<p><code>THUMBNAIL_PATH<\/code>\u306f\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f<code>Laravel<\/code>\u5185\u306e<code>thumbnails<\/code>\u30d5\u30a9\u30eb\u30c0\u306e\u3042\u308b\u4f4d\u7f6e\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u6b8b\u308a\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u60c5\u5831\u306b\u306a\u308a\u307e\u3059\u3002\uff08<code>DB_HOST<\/code>\u306f<code>localhost<\/code>\u304c\u591a\u3044\u3067\u3059\uff09<\/p>\n<h2>DB\u63a5\u7d9a<\/h2>\n<p>\u5148\u307b\u3069<code>pip<\/code>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f<code>mysql.connector<\/code>\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3057\u3066\u3044\u307e\u3059\u3002\u306a\u304a\u3001\u3082\u3057\u63a5\u7d9a\u306b\u5931\u6557\u3059\u308b\u3068\u5f37\u5236\u7684\u306b\u30b9\u30c8\u30c3\u30d7\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>DB\u304b\u3089\uff11\u4ef6\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/h2>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\uff11\u4ef6\u3060\u3051\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u308b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u6761\u4ef6\u306f\u4ee5\u4e0b\uff12\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u300cstatus\u300d\u304c\u300cwaiting\u300d\u306e\u3082\u306e<\/li>\n<li>\u300cid\u300d\u304c\u4e00\u756a\u5c0f\u3055\u3044\uff08\u3064\u307e\u308a\u4e00\u756a\u53e4\u3044\u30c7\u30fc\u30bf\uff09<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001\u30c7\u30fc\u30bf\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u5f37\u5236\u30b9\u30c8\u30c3\u30d7\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\uff08\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210\uff09<\/h2>\n<p>\u3053\u3053\u3067\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u304c\u3001\u5b9f\u969b\u306b\u5b9f\u884c\u3059\u308b\u306e\u306f\u4ee5\u4e0b\uff14\u3064\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3059\u3002<\/p>\n<ol>\n<li>Chromium\u3092\u4f7f\u3063\u3066\u30b5\u30a4\u30c8\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u300c1000 x 1000\u300d\u30d4\u30af\u30bb\u30eb\u3067\u4f5c\u6210\u3059\u308b<\/li>\n<li>\u4f5c\u6210\u3057\u305f\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092ImageMagick\u3092\u4f7f\u3063\u3066\u300c92&#215;92\u300d\u30d4\u30af\u30bb\u30eb\u306b\u30ea\u30b5\u30a4\u30ba<\/li>\n<li>\u300c1000 x 1000\u300d\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u306f\u4e0d\u8981\u306a\u306e\u3067\u524a\u9664<\/li>\n<li>Laravel\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u30d5\u30a9\u30eb\u30c0\u3078\u30ea\u30b5\u30a4\u30ba\u3057\u305f\u753b\u50cf\u3092\u79fb\u52d5<\/li>\n<\/ol>\n<h2>\u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u66f4\u65b0<\/h2>\n<p>\u30b5\u30e0\u30cd\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u305f\u3089\uff08\u305f\u3068\u3048\u30a8\u30e9\u30fc\u3067\u3042\u3063\u3066\u3082\uff09\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u5909\u66f4\u3057\u3066\u3001\u6b21\u306e\u5b9f\u884c\u6642\u306b\u306f\u540c\u3058\u30c7\u30fc\u30bf\u3092\u547c\u3073\u51fa\u3055\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u3067\u5b58\u5728\u3059\u308b\u30b9\u30c6\u30fc\u30bf\u30b9\u306f\u4ee5\u4e0b\u306e\uff13\u3064\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>waiting\u3000\u30fb\u30fb\u30fb\u3000\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210\u3092\u5f85\u6a5f\u4e2d<\/li>\n<li>completed\u3000\u30fb\u30fb\u30fb\u3000\u30b5\u30e0\u30cd\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u305f<\/li>\n<li>failed\u3000\u30fb\u30fb\u30fb\u3000\u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u4f5c\u6210\u306b\u5931\u6557\u3057\u305f<\/li>\n<\/ul>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u30b5\u30e0\u30cd\u30a4\u30eb\u304c\u4f5c\u6210\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u3092\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>crontab -e<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30a8\u30c7\u30a3\u30bf\u304c\u8d77\u52d5\u3057\u3066<code>crontab<\/code>\uff08\u30bf\u30a4\u30de\u30fc\u5b9f\u884c\uff09\u3092\u7de8\u96c6\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u6b21\u306e\u3088\u3046\u306b\u8ffd\u52a0\u3057\u3066\u6bce\u5206\u3054\u3068\u306bPython\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>* * * * * python \/PATH\/TO\/YOUR\/PYTHON\/generate_thumbnail.py<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u4fdd\u5b58\u306f<code>Esc<\/code> =&gt;\u00a0<code>:wq!<\/code> =&gt; <code>Enter<\/code>\u30ad\u30fc\u3067\u3059\u3002<\/p>\n<p>\u3042\u3068\u306f\u5f85\u3064\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\uff08\u7d04\uff15\u5206\u5f8c\u30fb\u30fb\u30fb\u30fb\u30fb\uff09<\/p>\n<p>&nbsp;<\/p>\n<p>\u30b5\u30e0\u30cd\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3001<code>thumbnails<\/code>\u30d5\u30a9\u30eb\u30c0\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n\u5168\u3066<code>92x92<\/code>\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4169\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_2.png\" alt=\"\" width=\"578\" height=\"135\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_2.png 578w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/screenshot_2-300x70.png 300w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/p>\n<p>\u203b \u3082\u3057\u4e0a\u624b\u304f\u884c\u304b\u306a\u3044\u5834\u5408\u306f\u3001\u304a\u305d\u3089\u304f\u5b9f\u884c\u6a29\u9650\u304c\u8db3\u308a\u3066\u3044\u306a\u3044\u5834\u5408\u304c\u307b\u3068\u3093\u3069\u3060\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u3093\u306a\u5834\u5408\u306f<code>chmod<\/code>\u30b3\u30de\u30f3\u30c9\u3067\u6a29\u9650\u3092\u5909\u66f4\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u30d8\u30c3\u30c9\u30ec\u30b9\u306e<code>Google Chrome<\/code>\u3092\u4f7f\u3063\u3066\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306f\u5168\u3066\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u304c\u3001<code>Ubuntu<\/code>\u3067\u3084\u308a\u307e\u3057\u305f\u306e\u3067\u30b5\u30fc\u30d0\u30fc\u5185\u3067\u3082\u304d\u3063\u3068\u3046\u307e\u304f\u3044\u304f\u306f\u305a\u3067\u3059\u3002\uff08\u306a\u3093\u306a\u3089\u72ec\u81ea\u306b\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210\u30b5\u30fc\u30d3\u30b9\u516c\u958b\u3057\u3066\u307f\u3088\u3046\u304b\u306a\u30fc\u3001\u3068\u3082\u601d\u3044\u307e\u3059\u304c<code>Blinky<\/code>\u3055\u3093\u3068\u306e\u5dee\u5225\u5316\u304c\u601d\u3044\u3064\u304b\u306a\u3044\u306e\u3082\u3042\u308a\u307e\u3059\u3057\u3001\u3082\u3046\u3072\u3068\u3064\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u5316\u30b5\u30fc\u30d3\u30b9<code>simpleAPI<\/code>\u306f\u3069\u3046\u3084\u3089\u3082\u3046\u52d5\u3044\u3066\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3001\u3042\u307e\u308a\u9700\u8981\u306f\u306a\u3044\u306e\u304b\u3082\u3001\u3001\u3001\u3068\u601d\u3063\u3066\u304a\u308a\u307e\u3059\ud83d\ude05\uff09<\/p>\n<p>\u306a\u304a\u3001\u4eca\u56de\u4f7f\u3063\u305f\u30d8\u30c3\u30c9\u30ec\u30b9<code>Google Chrome<\/code>\u3092\u4f7f\u3048\u3070<code>PDF<\/code>\u306e\u4f5c\u6210\u3084<code>DOM<\/code>\uff08\u3064\u307e\u308a<code>JavaScript<\/code>\u5b9f\u884c\u5f8c\u306e<code>HTML<\/code>\uff09\u306e\u53d6\u5f97\u3082\u3067\u304d\u308b\u306e\u3067\u4eca\u5f8c\u6a5f\u4f1a\u304c\u3042\u3063\u305f\u3089\u8a66\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u3044\u308d\u3044\u308d\u3068\u3084\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-427 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png\" alt=\"\" width=\"182\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png 182w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24-171x300.png 171w\" sizes=\"auto, (max-width: 182px) 100vw, 182px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u30d8\u30c3\u30c9\u30ec\u30b9\u3063\u3066\u3044\u3046\u540d\u524d\u3001\u51b7\u9759\u306b\u8003\u3048\u308b\u3068\u6016\u3044\u3067\u3059\u306d\uff08\u7b11\uff09\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u7a81\u7136PR\u307f\u305f\u3044\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3053\u306e\u30d6\u30ed\u30b0\u306e\u30e1\u30cb\u30e5\u30fc\u306b\u3042\u308bprerele\u3068\u3044\u3046\u7121\u6599\u30d7\u30ec\u30b9\u30ea\u30ea\u30fc\u30b9\u914d\u4fe1\u30b5\u30a4\u30c8\u306f\u79c1\u304c\u7ba1\u7406\u3092\u3057\u3066\u3044\u308b\u30b5\u30a4\u30c8\u3067\u3059\u3002 \u305f\u3060\u3001\u3053 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=4163\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel + Python \u3067\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":4174,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,39],"tags":[162],"class_list":["post-4163","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-python","tag-162"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4163"}],"version-history":[{"count":4,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4163\/revisions"}],"predecessor-version":[{"id":4173,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4163\/revisions\/4173"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/4174"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}