chore(plugins/community): move to community

This commit is contained in:
lowlighter
2022-01-16 19:33:32 -05:00
parent c361d93972
commit 3fd6b3ccc4
12 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
<!--header-->
<table>
<tr><th colspan="2"><h3>💉 Nightscout</h3></th></tr>
<tr><td colspan="2" align="center"><p>This plugin lets you display blood sugar values from a <a href="http://nightscout.info">Nightscout</a> site.</p>
</td></tr>
<tr><th>Authors</th><td><a href="https://github.com/legoandmars">@legoandmars</a></td></tr>
<tr>
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a></td>
</tr>
<tr>
<td><code>👤 Users</code></td>
</tr>
<tr>
<td><i>No tokens are required for this plugin</i></td>
</tr>
<tr>
<td colspan="2" align="center">
<img src="https://github.com/legoandmars/legoandmars/blob/master/metrics.plugin.nightscout.svg" alt=""></img>
<img width="900" height="1" alt="">
</td>
</tr>
</table>
<!--/header-->
## ➡️ Available options
<!--options-->
<table>
<tr>
<td align="center" nowrap="nowrap">Type</i></td><td align="center" nowrap="nowrap">Description</td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout</code></td>
<td rowspan="2"><p>Enable nightscout plugin</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
<br>
<b>default:</b> no<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout_url</code></td>
<td rowspan="2"><p>Nightscout URL</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br>
<b>default:</b> https://example.herokuapp.com<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout_datapoints</code></td>
<td rowspan="2"><p>Number of datapoints shown the graph</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>number</code>
<i>(0 ≤
𝑥)</i>
<br>
<b>zero behaviour:</b> disable</br>
<b>default:</b> 12<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout_lowalert</code></td>
<td rowspan="2"><p>Threshold for low blood sugar</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>number</code>
<i>(0 ≤
𝑥)</i>
<br>
<b>default:</b> 80<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout_highalert</code></td>
<td rowspan="2"><p>Threshold for high blood sugar</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>number</code>
<i>(0 ≤
𝑥)</i>
<br>
<b>default:</b> 180<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout_urgentlowalert</code></td>
<td rowspan="2"><p>Threshold for urgently low blood sugar</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>number</code>
<i>(0 ≤
𝑥)</i>
<br>
<b>default:</b> 50<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_nightscout_urgenthighalert</code></td>
<td rowspan="2"><p>Threshold for urgently high blood sugar</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>number</code>
<i>(0 ≤
𝑥)</i>
<br>
<b>default:</b> 250<br></td>
</tr>
</table>
<!--/options-->
## 🌐 Setup a Nightscout instance
The [nightscout website](http://www.nightscout.info/) details how to self-host a nightscout site.
Check out the instructions there.
## Examples workflows
<!--examples-->
```yaml
uses: lowlighter/metrics@latest
with:
token: ${{ secrets.METRICS_TOKEN }}
plugin_nightscout: yes
plugin_nightscout_url: ${{ secrets.NIGHTSCOUT_URL }}
```
<!--/examples-->

View File

@@ -0,0 +1,7 @@
- uses: lowlighter/metrics@latest
with:
token: ${{ secrets.METRICS_TOKEN }}
plugin_nightscout: yes
plugin_nightscout_url: ${{ secrets.NIGHTSCOUT_URL }}
prod:
skip: true

View File

@@ -0,0 +1,90 @@
//Setup
export default async function({q, imports, data, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled) || (!q.nightscout))
return null
//Load inputs
let {url, datapoints, lowalert, highalert, urgentlowalert, urgenthighalert} = imports.metadata.plugins.nightscout.inputs({data, account, q})
if (!url || url === "https://example.herokuapp.com")
throw {error:{message:"Nightscout site URL isn't set!"}}
if (url.substring(url.length - 1) !== "/")
url += "/"
if (url.substring(0, 7) === "http://")
url = `https://${url.substring(7)}`
if (url.substring(0, 8) !== "https://")
url = `https://${url}`
if (datapoints <= 0)
datapoints = 1
//Get nightscout data from axios
const resp = await imports.axios.get(`${url}api/v1/entries.json?count=${datapoints}`)
for (let i = 0; i < resp.data.length; i++) {
const {sgv} = resp.data[i]
//Add human readable timestamps and arrows
const date = new Date(resp.data[i].dateString)
resp.data[i].arrowHumanReadable = directionArrow(resp.data[i].direction)
resp.data[i].timeUTCHumanReadable = `${addZero(date.getUTCHours())}:${addZero(date.getUTCMinutes())}`
/*
* Add colors and alert names
* TODO: Maybe make colors better themed instead of just the "github style" - red and yellow could fit better than darker shades of green
*/
let color = "#40c463"
let alertName = "Normal"
if (sgv >= urgenthighalert || sgv <= urgentlowalert) {
color = "#216e39"
alertName = sgv >= urgenthighalert ? "Urgent High" : "Urgent Low"
}
else if (sgv >= highalert || sgv <= lowalert) {
color = "#30a14e"
alertName = sgv >= highalert ? "High" : "Low"
}
resp.data[i].color = color
resp.data[i].alert = alertName
}
return {data:resp.data.reverse()}
}
//Handle errors
catch (error) {
if (error.error?.message)
throw error
throw {error:{message:"An error occured", instance:error}}
}
}
function addZero(i) {
if (i < 10)
i = `0${i}`
return i
}
function directionArrow(direction) {
const dir = direction.toUpperCase()
switch (dir) {
case "NONE":
return ""
case "DOUBLEUP":
return "↑↑"
case "SINGLEUP":
return "↑"
case "FORTYFIVEUP":
return "↗"
case "FLAT":
return "→"
case "FORTYFIVEDOWN":
return "↘"
case "SINGLEDOWN":
return "↓"
case "DOUBLEDOWN":
return "↓↓"
case "NOT COMPUTABLE":
return ""
case "RATE OUT OF RANGE":
return ""
default:
return ""
}
}

View File

@@ -0,0 +1,52 @@
name: "💉 Nightscout"
category: community
description: This plugin lets you display blood sugar values from a [Nightscout](http://nightscout.info) site.
examples:
default: https://github.com/legoandmars/legoandmars/blob/master/metrics.plugin.nightscout.svg
authors:
- legoandmars
supports:
- user
scopes: []
inputs:
plugin_nightscout:
description: Enable nightscout plugin
type: boolean
default: no
plugin_nightscout_url:
description: Nightscout URL
type: string
default: https://example.herokuapp.com
plugin_nightscout_datapoints:
description: Number of datapoints shown the graph
type: number
default: 12
min: 0
zero: disable
plugin_nightscout_lowalert:
description: Threshold for low blood sugar
type: number
default: 80
min: 0
plugin_nightscout_highalert:
description: Threshold for high blood sugar
type: number
default: 180
min: 0
plugin_nightscout_urgentlowalert:
description: Threshold for urgently low blood sugar
type: number
default: 50
min: 0
plugin_nightscout_urgenthighalert:
description: Threshold for urgently high blood sugar
type: number
default: 250
min: 0

View File

@@ -0,0 +1,104 @@
<!--header-->
<table>
<tr><th colspan="2"><h3>💩 PoopMap plugin</h3></th></tr>
<tr><td colspan="2" align="center"><p>This plugin displays statistics from a <a href="https://poopmap.net">PoopMap</a> account.</p>
</td></tr>
<tr><th>Authors</th><td><a href="https://github.com/matievisthekat">@matievisthekat</a></td></tr>
<tr>
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a></td>
</tr>
<tr>
<td><code>👤 Users</code></td>
</tr>
<tr>
<td><code>🗝️ plugin_poopmap_token</code></td>
</tr>
<tr>
<td colspan="2" align="center">
<img src="https://github.com/matievisthekat/matievisthekat/blob/master/metrics.plugin.poopmap.svg" alt=""></img>
<img width="900" height="1" alt="">
</td>
</tr>
</table>
<!--/header-->
## ➡️ Available options
<!--options-->
<table>
<tr>
<td align="center" nowrap="nowrap">Type</i></td><td align="center" nowrap="nowrap">Description</td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_poopmap</code></td>
<td rowspan="2"><p>Enable poopmap plugin</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
<br>
<b>default:</b> no<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_poopmap_token</code></td>
<td rowspan="2"><p>PoopMap API token</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">🔐 Token<br>
<b>type:</b> <code>token</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_poopmap_days</code></td>
<td rowspan="2"><p>Time range</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>number</code>
<br>
<b>default:</b> 7<br>
<b>allowed values:</b><ul><li>7</li><li>30</li><li>180</li><li>365</li></ul></td>
</tr>
</table>
<!--/options-->
## 🗝️ Obtaining a PoopMap token
Install PoopMap app ([iOS](https://itunes.apple.com/us/app/poop-map/id1303269455?mt=8)/[Android](https://play.google.com/store/apps/details?id=net.poopmap)) and create an account.
Navigate to your profile in the app
<div align="center">
<img src="https://user-images.githubusercontent.com/45036977/143533812-c2776bcc-1fda-441e-bc96-cf21d4c69ca1.jpg" width="150" />
</div>
Tap "Share Profile" in the top right
<div align="center">
<img src="https://user-images.githubusercontent.com/45036977/143533849-b7e03b4d-2903-4339-bbb7-e1fc0ea9724e.jpg" width="150" />
</div>
Tap "Copy to Clipboard"
<div align="center">
<img src="https://user-images.githubusercontent.com/45036977/143533856-f4a9fc0d-7bde-48c2-b579-e8ee91804d78.jpg" width="150" />
</div>
It should result in something like `Haha, check out the places I've pooped on Poop Map https://api.poopmap.net/map?token=xxxxxxxxxx` copied.
Extract the `token` query paramater from the link and use it in `plugin_poopmap_token`.
This token will not expire and it will be able to access only public details.
## Examples workflows
<!--examples-->
```yaml
uses: lowlighter/metrics@latest
with:
token: ${{ secrets.METRICS_TOKEN }}
plugin_poopmap: yes
```
<!--/examples-->

View File

@@ -0,0 +1,6 @@
- uses: lowlighter/metrics@latest
with:
token: ${{ secrets.METRICS_TOKEN }}
plugin_poopmap: yes
prod:
skip: true

View File

@@ -0,0 +1,37 @@
//Setup
export default async function({q, imports, data, account}, {enabled = false, token = ""} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled) || (!q.poopmap))
return null
if (!token)
return {poops:[], days:7}
const {days} = imports.metadata.plugins.poopmap.inputs({data, account, q})
const {data:{poops}} = await imports.axios.get(`https://api.poopmap.net/api/v1/public_links/${token}`)
const filteredPoops = poops.filter(poop => {
const createdAt = new Date(poop.created_at)
poop.created_at = createdAt.toString()
return createdAt > new Date().getTime() - days * 24 * 60 * 60 * 1000
})
const hours = {max:0}
for (let i = 0; i < filteredPoops.length; i++) {
const poop = filteredPoops[i]
const hour = new Date(poop.created_at).getHours()
hours[hour] = (hours[hour] ?? 0) + 1
hours.max = Math.max(hours[hour], hours.max)
}
//Results
return {poops:hours, days}
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
}
}

View File

@@ -0,0 +1,31 @@
name: "💩 PoopMap plugin"
category: community
description: This plugin displays statistics from a [PoopMap](https://poopmap.net) account.
examples:
default: https://github.com/matievisthekat/matievisthekat/blob/master/metrics.plugin.poopmap.svg
authors:
- matievisthekat
supports:
- user
scopes: []
inputs:
plugin_poopmap:
description: Enable poopmap plugin
type: boolean
default: no
plugin_poopmap_token:
description: PoopMap API token
type: token
default: ""
plugin_poopmap_days:
description: Time range
type: number
values:
- 7
- 30
- 180
- 365
default: 7

View File

@@ -0,0 +1,102 @@
<!--header-->
<table>
<tr><th colspan="2"><h3>📸 Website screenshot</h3></th></tr>
<tr><td colspan="2" align="center"><p>This plugin display a screenshot from any website.
It can either the full page or a portion restricted by a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors">CSS selector</a>.</p>
</td></tr>
<tr><th>Authors</th><td><a href="https://github.com/lowlighter">@lowlighter</a></td></tr>
<tr>
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a> <a href="/source/templates/repository"><code>📘 Repository template</code></a> <a href="/source/templates/terminal"><code>📙 Terminal template</code></a></td>
</tr>
<tr>
<td><code>👤 Users</code> <code>👥 Organizations</code> <code>📓 Repositories</code></td>
</tr>
<tr>
<td><i>No tokens are required for this plugin</i></td>
</tr>
<tr>
<td colspan="2" align="center">
<img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.screenshot.svg" alt=""></img>
<img width="900" height="1" alt="">
</td>
</tr>
</table>
<!--/header-->
## ➡️ Available options
<!--options-->
<table>
<tr>
<td align="center" nowrap="nowrap">Type</i></td><td align="center" nowrap="nowrap">Description</td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_screenshot</code></td>
<td rowspan="2"><p>Enable screenshot plugin</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
<br>
<b>default:</b> no<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_screenshot_title</code></td>
<td rowspan="2"><p>Title caption</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br>
<b>default:</b> Screenshot<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_screenshot_url</code></td>
<td rowspan="2"><p>Website url</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_screenshot_selector</code></td>
<td rowspan="2"><p>CSS Selector</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br>
<b>default:</b> body<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_screenshot_background</code></td>
<td rowspan="2"><p>Display background</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
<br>
<b>default:</b> yes<br></td>
</tr>
</table>
<!--/options-->
## Examples workflows
<!--examples-->
```yaml
name: XKCD of the day
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.screenshot.svg
token: ${{ secrets.METRICS_TOKEN }}
base: ""
plugin_screenshot: yes
plugin_screenshot_title: XKCD of the day
plugin_screenshot_url: https://xkcd.com
plugin_screenshot_selector: "#comic img"
```
<!--/examples-->

View File

@@ -0,0 +1,14 @@
- name: XKCD of the day
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.screenshot.svg
token: ${{ secrets.METRICS_TOKEN }}
base: ""
plugin_screenshot: yes
plugin_screenshot_title: XKCD of the day
plugin_screenshot_url: https://xkcd.com
plugin_screenshot_selector: "#comic img"
test:
timeout: 1800000
modes:
- action

View File

@@ -0,0 +1,43 @@
//Setup
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled) || (!q.screenshot))
return null
//Load inputs
let {url, selector, title, background} = imports.metadata.plugins.screenshot.inputs({data, account, q})
if (!url)
throw {error:{message:"An url is required"}}
//Start puppeteer and navigate to page
console.debug(`metrics/compute/${login}/plugins > screenshot > starting browser`)
const browser = await imports.puppeteer.launch()
console.debug(`metrics/compute/${login}/plugins > screenshot > started ${await browser.version()}`)
const page = await browser.newPage()
await page.setViewport({width:1280, height:1280})
console.debug(`metrics/compute/${login}/plugins > screenshot > loading ${url}`)
await page.goto(url)
//Screenshot
await page.waitForSelector(selector)
const clip = await page.evaluate(selector => {
const {x, y, width, height} = document.querySelector(selector).getBoundingClientRect()
return {x, y, width, height}
}, selector)
console.debug(`metrics/compute/${login}/plugins > screenshot > coordinates ${JSON.stringify(clip)}`)
const [buffer] = await imports.record({page, ...clip, frames:1, background})
const screenshot = await (await imports.jimp.read(Buffer.from(buffer.split(",").pop(), "base64"))).resize(Math.min(454 * (1 + data.large), clip.width), imports.jimp.AUTO)
await browser.close()
//Results
return {image:await screenshot.getBase64Async("image/png"), title, height:screenshot.bitmap.height, width:screenshot.bitmap.width, url}
}
//Handle errors
catch (error) {
if (error.error?.message)
throw error
throw {title:"Screenshot error", error:{message:"An error occured", instance:error}}
}
}

View File

@@ -0,0 +1,41 @@
name: "📸 Website screenshot"
category: community
description: |
This plugin display a screenshot from any website.
It can either the full page or a portion restricted by a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors).
examples:
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.screenshot.svg
authors:
- lowlighter
supports:
- user
- organization
- repository
scopes: []
inputs:
plugin_screenshot:
description: Enable screenshot plugin
type: boolean
default: no
plugin_screenshot_title:
description: Title caption
type: string
default: Screenshot
plugin_screenshot_url:
description: Website url
type: string
default: ""
example: https://metrics.lecoq.io
plugin_screenshot_selector:
description: CSS Selector
type: string
default: body
plugin_screenshot_background:
description: Display background
type: boolean
default: yes