Skip to content

Instantly share code, notes, and snippets.

@Bolukan
Last active May 17, 2020 08:48
Show Gist options
  • Save Bolukan/8b49afa97f460549d526c641e8b75cac to your computer and use it in GitHub Desktop.
Save Bolukan/8b49afa97f460549d526c641e8b75cac to your computer and use it in GitHub Desktop.
Document libraries in platformio.ini
<!doctype html><html lang="en">
<head>
<title>Platformio Library comments</title>
</head>
<body>
<?php
// use: platformio.php?id=999
// Comments for platformio.ini on any library from platformio.org
function LibraryComments($id)
{
$api = "http://api.platformio.org/lib/info/";
$id = intval($id);
$response = file_get_contents($api . $id);
$json = json_decode($response, true);
$comments = "";
$authors = "unknown";
if (array_key_exists("authors", $json))
{
$authorid = 0;
$authors = $json["authors"][$authorid++]["name"];
while ($authorid < count($json["authors"]))
{
if ($authorid + 1 == count($json["authors"]))
{
$authors .= " and " . $json["authors"][$authorid++]["name"];
} else {
$authors .= ", " . $json["authors"][$authorid++]["name"];
}
}
}
// name
$comments .= sprintf("; %' 4d ", $id);
$comments .= wordwrap($json["name"], 73, "\n; ");
$comments .= "\n";
// version
$comments .= sprintf("; version %s, %s\n", $json["version"]["name"], gmdate("d-m-Y H:i:s", strtotime($json["version"]["released"])));
// authors
$comments .= "; by ";
$comments .= wordwrap($authors, 73, "\n; ");
$comments .= "\n";
// repository
$comments .= "; Repository: ";
$comments .= wordwrap($json["repository"], 73, "\n; ");
$comments .= "\n";
// description
$comments .= "; ";
$comments .= wordwrap(strip_tags($json["description"]), 73, "\n; ");
$comments .= "\n";
return $comments;
}
if (empty($_GET["id"]))
{
echo "Error: No valid ?id=xx";
exit();
} else {
$ids = preg_split("/[\s,]+/", $_GET["id"]);
echo "<pre>\n";
foreach ($ids as $id)
{
echo LibraryComments($id);
}
echo "</pre>\n";
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment