Created
July 17, 2024 13:22
-
-
Save kiang/8971ffee127b437455bc8943b998e2e2 to your computer and use it in GitHub Desktop.
redmine api sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$basePath = dirname(__DIR__); | |
require_once $basePath . '/vendor/autoload.php'; | |
$rawPath = $basePath . '/raw/media'; | |
if (!file_exists($rawPath)) { | |
mkdir($rawPath, 0777, true); | |
} | |
$pageFile = $rawPath . '/page1.html'; | |
$page = file_get_contents('https://www.tpp.org.tw/media?page=1'); | |
file_put_contents($pageFile, $page); | |
$client = new \Redmine\Client\NativeCurlClient('redmine_url', 'redmine_user', 'redmine_token'); | |
$pos = strpos($page, '/newsdetail/'); | |
while (false !== $pos) { | |
$posEnd = strpos($page, '"', $pos); | |
$url = substr($page, $pos, $posEnd - $pos); | |
$rawFile = $rawPath . '/' . str_replace('/', '_', $url) . '.html'; | |
if (!file_exists($rawFile)) { | |
$content = file_get_contents('https://www.tpp.org.tw' . $url); | |
file_put_contents($rawFile, $content); | |
$data = [ | |
'project_id' => 'tpp001', | |
]; | |
$cPos = strpos($content, '<div class="content_topic">'); | |
$cPosEnd = strpos($content, '</div>', $cPos); | |
$data['subject'] = substr($content, $cPos, $cPosEnd - $cPos); | |
$data['subject'] = trim(strip_tags($data['subject'])); | |
$cPos = strpos($content, '<div class="row">', $cPosEnd); | |
$cPosEnd = strpos($content, '<span class="btn_goback"', $cPos); | |
$data['description'] = substr($content, $cPos, $cPosEnd - $cPos); | |
$data['description'] = trim(strip_tags($data['description'])); | |
$data['description'] .= "\n\nhttps://www.tpp.org.tw{$url}"; | |
$client->getApi('issue')->create($data); | |
} | |
$pos = strpos($page, '/newsdetail/', $posEnd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment