diff --git a/.gitignore b/.gitignore index e72cf9c..ef81856 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,6 @@ task/* !.gitkeep # ignore TODO file in root directory,not subdir/TODO /TODO -/Todo \ No newline at end of file +/Todo + +cache/* \ No newline at end of file diff --git a/composer.json b/composer.json index 7919a43..9f42fcf 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "sven/file-config": "^3.1", "hassankhan/config": "^2.2", "lkeme/inifile": "^3.4", - "adhocore/cli": "^0.9.0" + "adhocore/cli": "^0.9.0", + "fire015/flintstone": "^2.3" }, "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index e883710..8c16236 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ec8eee201c31224952f597aab5be4ea8", + "content-hash": "28d262a352d5f6367f17a5e73ab48ade", "packages": [ { "name": "adhocore/cli", @@ -392,6 +392,63 @@ "abandoned": "psr/container", "time": "2017-02-14T19:40:03+00:00" }, + { + "name": "fire015/flintstone", + "version": "v2.3.0", + "source": { + "type": "git", + "url": "https://github.com/fire015/flintstone.git", + "reference": "406bcaebb4c0e352aa097d141ffd90a2f57cf679" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fire015/flintstone/zipball/406bcaebb4c0e352aa097d141ffd90a2f57cf679", + "reference": "406bcaebb4c0e352aa097d141ffd90a2f57cf679", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9" + }, + "type": "library", + "autoload": { + "psr-4": { + "Flintstone\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jason M", + "email": "emailfire@gmail.com" + } + ], + "description": "A key/value database store using flat files for PHP", + "homepage": "https://github.com/fire015/flintstone", + "keywords": [ + "cache", + "database", + "files", + "flintstone", + "memory" + ], + "support": { + "issues": "https://github.com/fire015/flintstone/issues", + "source": "https://github.com/fire015/flintstone/tree/v2.3.0" + }, + "time": "2021-01-20T10:36:23+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.5.5", diff --git a/src/core/App.php b/src/core/App.php index 67f80e1..092173a 100644 --- a/src/core/App.php +++ b/src/core/App.php @@ -28,6 +28,7 @@ class App define('APP_DATA_PATH', $app_path . "/data/"); define('APP_LOG_PATH', $app_path . "/log/"); define('APP_TASK_PATH', $app_path . "/task/"); + define('APP_CACHE_PATH', $app_path . "/cache/"); } /** diff --git a/src/plugin/Dynamic.php b/src/plugin/Dynamic.php index fefa5e5..3369507 100644 --- a/src/plugin/Dynamic.php +++ b/src/plugin/Dynamic.php @@ -19,13 +19,21 @@ class Dynamic // Todo 活动订阅 // https://www.bilibili.com/blackboard/activity-WeqT10t1ep.html // https://api.vc.bilibili.com/topic_svr/v1/topic_svr/fetch_dynamics?topic_name=%E4%BA%92%E5%8A%A8%E6%8A%BD%E5%A5%96&sortby=2 - private static $tags = ['互动抽奖', '抽奖', '转发抽奖', '动态抽奖', '关注+转发']; + // https://t.bilibili.com/topic/name/%E5%8A%A8%E6%80%81%E6%8A%BD%E5%A5%96/feed - // 228584 14027 434405 7019788 3230836 private static $topic_list = [ - 3230836 => '', - 434405 => '', - 7019788 => '' + '互动抽奖' => '3230836', + '转发抽奖' => '434405', + '动态抽奖' => '7146512', + '关注抽奖' => '5608480', + // '关注+转发' => '7544627', + // '评论抽奖'=>'2630459', + // '转发关注评论抽奖'=>'8339319', + // '转发+评论抽奖'=> '7169938', + // '关注评论抽奖'=>'8078587', + // '转发评论抽奖' => '7019788', + // '抽奖'=>'228584', + ]; @@ -36,8 +44,8 @@ class Dynamic */ public static function getAwardTopic(): array { - - foreach (self::$topic_list as $t_id => $t_name) { + foreach (self::$topic_list as $t_name => $t_id) { + Log::info("获取关键字 {$t_name}-{$t_id}"); $url = 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new?topic_id=' . $t_id; $data = Curl::request('get', $url); $data = json_decode($data, true); @@ -47,7 +55,14 @@ class Dynamic $article_id = $article['desc']['dynamic_id']; // 获取 description $card = json_decode($article['card'], true); - if (array_key_exists("description", $card['item'])) { + + if (isset($card['category']) && isset($card['categories'])) { + // 处理专栏 提前处理 + continue; + } elseif (isset($card['aid']) && isset($card['cid'])) { + // 处理视频转发 + $description = $card['dynamic']; + } elseif (array_key_exists("description", $card['item'])) { // 主动态 $description = $card['item']['description']; } elseif (array_key_exists("content", $card['item'])) { @@ -77,7 +92,8 @@ class Dynamic // more ?? // https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_history?topic_name=转发抽奖&offset_dynamic_id=454347930068783808 } - print_r(count(self::$article_list)); + $num = count(self::$article_list); + Log::info("获取到 {$num} 条有效动态"); return self::$article_list; } diff --git a/src/tool/Cache.php b/src/tool/Cache.php new file mode 100644 index 0000000..0dd5d37 --- /dev/null +++ b/src/tool/Cache.php @@ -0,0 +1,60 @@ + APP_CACHE_PATH, + // 'gzip' => true, + 'formatter' => new JsonFormatter() + ]); + // self::$instance->set('bob', ['email' => 'bob@site.com', 'password' => '123456']); + } + + public static function get() + { + // Get a key + // $user = $users->get('bob'); + // echo 'Bob, your email is ' . $user['email']; + $args = func_get_args(); + return self::getInstance()->get(...$args); + } + + public static function set() + { + // Set a key + // $users->set('bob', ['email' => 'bob@site.com', 'password' => '123456']); + $args = func_get_args(); + self::getInstance()->set(...$args); + } + + +} \ No newline at end of file