mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-06 20:05:40 +01:00
new endpoint for Medium followers count
This commit is contained in:
parent
fc226ba570
commit
6bafc615e4
21
README.md
21
README.md
@ -11,6 +11,8 @@
|
||||
|
||||
- [Tasks](#tasks)
|
||||
- [Medium](#medium)
|
||||
- [Get Latest Posts](#get-latest-posts)
|
||||
- [Get Followers Count](#get-followers-count)
|
||||
- [YouTube](#youtube)
|
||||
- [Bounties](#bounties)
|
||||
- [MailChimp](#mailchimp)
|
||||
@ -30,6 +32,8 @@
|
||||
|
||||
**`webtask-medium.js`**: Generic task to fetch and reconstruct items from any medium publication.
|
||||
|
||||
#### Get Latest Posts
|
||||
|
||||
Requires the Medium username appended at the end of the url:
|
||||
|
||||
```bash
|
||||
@ -39,6 +43,23 @@ http://localhost:8080/:medium_username
|
||||
https://TASK_URL/TASK_NAME/:medium_username
|
||||
```
|
||||
|
||||
#### Get Followers Count
|
||||
|
||||
```bash
|
||||
http://localhost:8080/:medium_username/followers
|
||||
|
||||
# when published on webtask.io
|
||||
https://TASK_URL/TASK_NAME/:medium_username/followers
|
||||
```
|
||||
|
||||
**Response**
|
||||
|
||||
```json
|
||||
{
|
||||
"followers": 2528
|
||||
}
|
||||
```
|
||||
|
||||
### YouTube
|
||||
|
||||
**`webtask-youtube.js`**: Generic task to fetch and reconstruct items from any YouTube account. YouTube API key is provided via [secret environment variable](https://webtask.io/docs/issue_parameters) `YOUTUBE_API_KEY` setup in web editor of webtask.io.
|
||||
|
@ -50,4 +50,17 @@ app.get('/:username/raw', (req, res) => {
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/:username/followers', (req, res) => {
|
||||
const url = `https://medium.com/${req.params.username}?format=json`
|
||||
|
||||
request(url, (error, response) => {
|
||||
const json = JSON.parse(response.body.replace('])}while(1);</x>', ''))
|
||||
const { collection } = json.payload
|
||||
|
||||
if (error) return
|
||||
|
||||
res.send(`{ "followers": ${collection.metadata.followerCount} }`)
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = webtask.fromExpress(app)
|
||||
|
Loading…
Reference in New Issue
Block a user