From 990218238ea6aa73131cc10e33ff6a05b48cc4bf Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Tue, 16 May 2017 13:52:32 +0700 Subject: [PATCH] time cache --- .gitignore | 1 + bot.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index 555f91d..04e5c32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor config.yml +.lastrun diff --git a/bot.php b/bot.php index 37d97dd..eee43d5 100644 --- a/bot.php +++ b/bot.php @@ -3,6 +3,11 @@ require_once ("vendor/autoload.php"); use Symfony\Component\Yaml\Yaml; $config = Yaml::parse(file_get_contents('config.yml')); +$lastrun = 0; +if (file_exists('.lastrun')) { + $lastrun = file_get_contents('.lastrun'); +} +echo $lastrun; function get_text($url) { $curl = curl_init(); @@ -29,6 +34,9 @@ $articles = $service->parse($string)[0]['value']; unset($string); $pandoc = new \Pandoc\Pandoc(); foreach ($articles as $article) { + if (strtotime($article['pubDate']) <= $lastrun) { + continue; + } $title = $article['title']; $link = $article['link']; $description = $article['description']; @@ -52,3 +60,4 @@ foreach ($articles as $article) { echo $description; } } +file_put_contents('.lastrun', time());