$app->get("/comment-user/{userId}/{page}", function (Request $request, Response $response, $userId, $page) { try { return ResultWrapper::getResult(Comment::getByUser($userId, $page), $response); } catch (Exception $e) { return ResultWrapper::getError($e->getMessage(), $response); } }); $app->delete('/comment/{id}', function (Request $request, Response $response, $id) { try { $token = $request->getHeader('token'); return ResultWrapper::getResult(Comment::del($token, $id), $response); } catch (Exception $e) { return ResultWrapper::getError($e->getMessage(), $response); } }); //For scraping data from the website only $app->get('/scrap-data/{category}/{page}', function (Request $request, Response $response, $category, $page) { try { return ResultWrapper::getResult(Scraper::scrapListPromo($category, $page), $response); } catch (Exception $e) { return ResultWrapper::getError($e->getMessage(), $response); } }); $app->get('/fill-empty-desc', function (Request $request, Response $response) { try { return ResultWrapper::getResult(Scraper::fillDescriptionPromo(), $response); } catch (Exception $e) { return ResultWrapper::getError($e->getMessage(), $response); } }); $app->run();
public static function fillDescriptionPromo() { $i = 0; foreach (Capsule::table(Promo::TABLE_NAME)->where('fullDescription', '=', '')->limit(3)->get() as $item) { $promo = Promo::find($item->id); $desc = Scraper::scrapDetailPromoWithId($promo->id); $promo->fullDescription = $desc; $promo->save(); if ($desc != '') { $i++; } } return "Filled {$i} Promos"; }