Commit 22a4e81b authored by ZhuChunYang's avatar ZhuChunYang

update

parent 8609825e
......@@ -7,6 +7,7 @@
*/
namespace console\controllers;
use common\models\psources\Coin;
use yii\console\Controller;
......@@ -15,14 +16,48 @@ class CrawlerController extends Controller
public function actionCoinInfo()
{
$feixiaohao_url = "https://www.feixiaohao.com/currencies/vechain";
$content = file_get_contents($feixiaohao_url);
$patt = "/<li><span class=tit>发行时间:<\/span> <span class=value>(.+?)<\/span><li>/";
preg_match($patt, $content, $res);
var_dump($res);
$sidItems = array_column(Coin::find()->select('sid')->asArray()->all(),'sid');
foreach($sidItems as $sid){
if($sid){
$coinInfo = Coin::find()->where(['sid' => $sid])->one();
$release = $this->getReleaseTime($sid);
$isDate = $this->isDateTime($release);
if(!$isDate){
$release = '';
}
$coinInfo->release = $release;
$coinInfo->save();
echo '币种名称: '.$coinInfo->name.'--'.$coinInfo->nickname.'--sid: '.$sid.PHP_EOL;
echo '发行时间: '.$release.' 更新成功'.PHP_EOL;
}
}
}
private function getReleaseTime($sid)
{
try{
$feixiaohao_url = "https://www.feixiaohao.com/currencies/".$sid;
$content = file_get_contents($feixiaohao_url);
//preg_match 只匹配一次就返回
$patt = "/<li><span class=tit>发行时间:<\/span> <span class=value>(.+?)<\/span><li>/";
preg_match($patt, $content, $res);
$release_time = $res[1];
return $release_time;
}catch (\Exception $e){
echo $sid.'-----非小号上不存在';
return '';
}
}
private function isDateTime($dateTime){
$ret = strtotime($dateTime);
return $ret !== FALSE && $ret != -1;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment