feat(plugins/community/poopmap): add poopmap plugin support (#675)

This commit is contained in:
Matthew Stead
2021-11-27 00:53:36 +02:00
committed by GitHub
parent e4ff40453a
commit 2d144f4ba9
7 changed files with 183 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
/**Mocked data */
export default function({faker, url, options, login = faker.internet.userName()}) {
//Wakatime api
if (/^https:..api.poopmap.net$/.test(url)) {
//Get user profile
if (/public_links\/MOCKED_TOKEN/.test(url)) {
console.debug(`metrics/compute/mocks > mocking poopmap api result > ${url}`)
return ({
status:200,
data:{
poops:new Array(12 + faker.datatype.number(6)).fill(null).map(_ => ({
id:79744699,
latitude:faker.address.latitude(),
longitude:faker.address.longitude(),
created_at:faker.date.past().toISOString(),
note:"",
place:"",
rating:faker.datatype.number(5),
followers_count:faker.datatype.number(100),
comments_count:faker.datatype.number(12)
}))
},
})
}
}
}

View File

@@ -0,0 +1,53 @@
### 💩 PoopMap plugin
The *poopmap* plugin displays statistics from your [PoopMap](https://poopmap.net) account
<table>
<td align="center">
<img src="https://github.com/matievisthekat/matievisthekat/blob/master/metrics.plugin.poopmap.svg">
<img width="900" height="1" alt="">
</td>
</table>
<details>
<summary>💬 Obtaining a PoopMap token</summary>
First, install the 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" the copy the link to your clipboard
<div align="center">
<img src="https://user-images.githubusercontent.com/45036977/143533856-f4a9fc0d-7bde-48c2-b579-e8ee91804d78.jpg" width="150" />
</div>
You should have 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
You now have your PoopMap token! This token will not expire and it can only access public details.
</details>
#### Examples workflows
[➡️ Available options for this plugin](metadata.yml)
```yaml
- uses: lowlighter/metrics@latest
with:
# ... other options
plugin_poopmap: yes
plugin_poopmap_token: ${{ secrets.POOPMAP_TOKEN }} # Required
plugin_poopmap_days: 7 # Display last week stats
```

View File

@@ -0,0 +1,36 @@
//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,29 @@
name: "💩 PoopMap plugin"
category: social
index: ~
supports:
- user
inputs:
# Enable or disable plugin
plugin_poopmap:
description: Display PoopMap stats
type: boolean
default: no
# PoopMap API token
plugin_poopmap_token:
description: PoopMap API token
type: token
default: ""
# Time range to use for displayed stats
plugin_poopmap_days:
description: PoopMap time range
type: string
values:
- 7 # Last week
- 30 # Last month
- 180 # Last 6 months
- 365 # Last year
default: 7

View File

@@ -0,0 +1,5 @@
- name: Poopmap plugin (default)
uses: lowlighter/metrics@latest
with:
token: MOCKED_TOKEN
plugin_poopmap: yes

View File

@@ -33,5 +33,6 @@
"achievements", "achievements",
"screenshot", "screenshot",
"code", "code",
"sponsors" "sponsors",
"poopmap"
] ]

View File

@@ -0,0 +1,32 @@
<% if (plugins.poopmap) { %>
<section>
<div class="row">
<% if (plugins.poopmap.error) { %>
<section>
<div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg>
<%= plugins.poopmap.error.message %>
</div>
</section>
<% } else { %>
<section class="column chart largeable">
<h3>Poops per hour of day</h3>
<small>over the last <%- plugins.poopmap.days %> days</small>
<div class="chart-bars">
<% let displayedValues = []; %>
<% let poops = plugins.poopmap.poops %>
<% for (let h = 0; h < 24; h++) { displayedValues.push([h, (poops[h] || 0)/(poops.max || 1), poops[h]]) } %>
<% for(const [h, percentage, value] of displayedValues) { %>
<div class="entry">
<span class="value"><%= value %></span>
<div class="bar" style="height: <%= percentage*50 %>px; background-color: var(--color-calendar-graph-day-L<%= Math.ceil(percentage/0.25) %>-bg)"></div>
<%= `${h}`.padStart(2, 0) %>
</div>
<% } %>
</div>
</section>
<% } %>
</div>
</section>
<% } %>