1 Star 0 Fork 0

falcon / bark-pan-icu

加入 Gitee
与超过 600 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未指定开源许可证,未经作者的许可,此代码仅用于学习,不能用于其他用途。
克隆/下载
run.php 2.05 KB
一键复制 编辑 Web IDE 原始数据 按行查看 历史
falcon 提交于 2021-01-05 03:04 . touch episode_file to update filemtime
<?php
require __DIR__.'/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$config = include __DIR__ .'/config.php';
$episode_file = $config['episode_file'];
$feed_url = $config['feed_url'];
$client = new Client([
'allow_redirects' => true,
'connect_timeout' => 20,
'read_timeout' => 20,
'timeout' => 40,
'cookies' => true,
//'debug' => true,
//'proxy' => 'http://127.0.0.1:8123',
'headers' => [
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 ', //
],
]);
try {
if( !$config['debug'] ) {
$response = $client->get($feed_url);
$feed = (string) $response->getBody();
}else{
$feed = file_get_contents('pan.test.xml');
}
$reader = new Sabre\Xml\Reader();
$reader->xml($feed);
$result = $reader->parse();
$latest_item = $result['value'][0]['value'][13]['value'];
$latest = array();
$latest['episode'] = $latest_item[1]['value'];
if( !file_exists($episode_file) || intval(file_get_contents($episode_file)) < $latest['episode']) {
$latest['title'] = $latest_item[0]['value'];
$latest['name'] = $latest_item[2]['value'];
$latest['link'] = $latest_item[4]['value'];
$latest['pubDate'] = $latest_item[7]['value'];
$latest['enclosure'] = $latest_item[8]['attributes']['url'];
$latest['update'] = sprintf('内核恐慌更新了%d期:《%s》',$latest['episode'],$latest['name']);
$bark_url = $config['bark']['tpl'];
foreach(array_keys($latest) as $key) {
$bark_url = str_replace('{'.$key.'}',urlencode($latest[$key]),$bark_url);
}
$bark_res = $client->get($bark_url);
file_put_contents($config['episode_file'],$latest['episode']);
}else{
touch($episode_file);
}
} catch (RequestException $e) {
echo $e->getRequest();
if ($e->hasResponse()) {
echo $e->getResponse();
}
}
exit;

评论 ( 0 )

你可以在登录后,发表评论

PHP
1
https://gitee.com/falcon/bark-pan-icu.git
git@gitee.com:falcon/bark-pan-icu.git
falcon
bark-pan-icu
bark-pan-icu
master

搜索帮助

182229 41614e54 1850385 182230 7885ed45 1850385