[fix] Dynamic

This commit is contained in:
Lkeme 2021-08-14 12:21:37 +08:00
parent 641ae05f33
commit dd5abf7c8d
6 changed files with 149 additions and 12 deletions

4
.gitignore vendored
View File

@ -36,4 +36,6 @@ task/*
!.gitkeep
# ignore TODO file in root directory,not subdir/TODO
/TODO
/Todo
/Todo
cache/*

View File

@ -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": [

59
composer.lock generated
View File

@ -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",

View File

@ -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/");
}
/**

View File

@ -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;
}

60
src/tool/Cache.php Normal file
View File

@ -0,0 +1,60 @@
<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2021 ~ 2022
* Source: https://github.com/fzaninotto/Faker/
*/
namespace BiliHelper\Tool;
use Flintstone\Flintstone;
use Flintstone\Formatter\JsonFormatter;
class Cache
{
private static $instance;
private static function getInstance()
{
if (is_null(self::$instance)) {
self::configureInstance();
}
return self::$instance;
}
private static function configureInstance()
{
self::$instance = new Flintstone(
'BHP', [
'dir' => 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);
}
}