Skip to content

Commit

Permalink
🚖💡 Add charts
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch (dev-article-analysis) committed Jan 18, 2020
1 parent a430e04 commit 5667af8
Show file tree
Hide file tree
Showing 10 changed files with 598 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .glitch-assets
Expand Up @@ -4,3 +4,7 @@
{"uuid":"adSBq97hhhpFNUna","deleted":true}
{"uuid":"adSBq97hhhpFNUnb","deleted":true}
{"uuid":"adSBq97hhhpFNUnc","deleted":true}
{"name":"preview.png","date":"2020-01-18T17:00:50.274Z","url":"https://cdn.glitch.com/5a7fc508-f6fb-4cbb-83ad-e048e030fb0d%2Fpreview.png","type":"image/png","size":39397,"imageWidth":544,"imageHeight":749,"thumbnail":"https://cdn.glitch.com/5a7fc508-f6fb-4cbb-83ad-e048e030fb0d%2Fthumbnails%2Fpreview.png","thumbnailWidth":240,"thumbnailHeight":330,"uuid":"Bro471IxvEztn00r"}
{"uuid":"Bro471IxvEztn00r","deleted":true}
{"name":"preview.png","date":"2020-01-18T17:36:08.660Z","url":"https://cdn.glitch.com/5a7fc508-f6fb-4cbb-83ad-e048e030fb0d%2Fpreview.png","type":"image/png","size":54751,"imageWidth":790,"imageHeight":758,"thumbnail":"https://cdn.glitch.com/5a7fc508-f6fb-4cbb-83ad-e048e030fb0d%2Fthumbnails%2Fpreview.png","thumbnailWidth":330,"thumbnailHeight":317,"uuid":"bOwp5gCdtYYVX3L5"}
{"uuid":"bOwp5gCdtYYVX3L5","deleted":true}
21 changes: 21 additions & 0 deletions LICENSE.md
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Andrew Healey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 37 additions & 16 deletions README.md
@@ -1,27 +1,48 @@
Welcome to Glitch
DEV Article Analysis
=================

Click `Show` in the header to see your app live. Updates to your code will instantly deploy and update live.
A tool to analyze a [DEV](https://dev.to) user's articles (readability, complexity and grade level, semantic analysis) over time.

**Glitch** is the friendly community where you'll build the app of your dreams. Glitch lets you instantly create, remix, edit, and host an app, bot or site, and you can invite collaborators or helpers to simultaneously edit code with you.
The data is displayed in interactive charts.

Find out more [about Glitch](https://glitch.com/about).
<br>

### Install

Your Project
------------
`npm i`

On the front-end,
- edit `public/client.js`, `public/style.css` and `views/index.html`
- drag in `assets`, like images or music, to add them to your project
<br>

On the back-end,
- your app starts at `server.js`
- add frameworks and packages in `package.json`
- safely store app secrets in `.env` (nobody can see this but you and people you invite)
### Setup

Setup the application port, and DEV API key ([https://dev.to/settings/account](https://dev.to/settings/account))

Made by [Glitch](https://glitch.com/)
-------------------
**Linux/macOS**
```
export PORT=3000
export DEV_KEY=abc123
```

\ ゜o゜)ノ
**Command Prompt**
```
set PORT=3000
set DEV_KEY=abc123
```

**PowerShell**
```
$env:PORT = "3000"
$env:DEV_KEY = "abc123"
```

<br>

### Run

`npm run start`

<br>

### License

MIT.
44 changes: 30 additions & 14 deletions devApi.js
Expand Up @@ -2,30 +2,33 @@ const got = require("got");
const removeMarkdown = require("remove-markdown");
const sentimentAnalysis = require("sentiment");
const textReadability = require("text-readability");
const emojis = require("./emojis");

// Written for DEV API beta v0.5.9
const API = "https://dev.to/api/articles";
const KEY = process.env.DEV_KEY;

// Pass a DEV username and a WebSocket (ws) connection.
// Send updates of progress and finally the results:
// Various text statistic of a user's published articles
// Take a DEV username and a WebSocket (ws) connection.
// Send updates of progress and finally the results,
// various textual statistics of a user's published articles
module.exports = (user, ws) => {
// Get the plaintext content of user's published articles
const getArticles = async user => {
let articleIds = [];
let pageCount = 0;
while (true) {
// Get a list of user's article ids
console.log(`${API}?username=${user}&page=${pageCount}`);
const response = await got(`${API}?username=${user}&page=${pageCount}`, {
"api-key": KEY
});
const body = JSON.parse(response.body);
if (body.length === 0) break;
articleIds = articleIds.concat(body.map(article => article.id));
ws.send(
JSON.stringify({ msg: `Got page no. ${pageCount + 1} of article ids` })
JSON.stringify({
msg: `Progress: got page no. ${pageCount +
1} of article ids ${emojis.random()}`
})
);
pageCount += 1;
}
Expand All @@ -34,36 +37,49 @@ module.exports = (user, ws) => {
let articles = [];
let articleCount = 0;
// TODO: Fix duplicate ids coming back from API
articleIds = Array.from(new Set(articleIds));
articleIds = [...new Set(articleIds)].sort((a, b) => a - b); // sort old to new
for (const id of articleIds) {
articleCount += 1;
const response = await got(`${API}/${id}`, {
"api-key": KEY
});
ws.send(
JSON.stringify({ msg: `Got text of article no. ${articleCount}` })
JSON.stringify({
msg: `Progress: got text of article no. ${articleCount} ${emojis.random()}`
})
);
articles.push(JSON.parse(response.body).body_markdown);
articles.push(JSON.parse(response.body));
}

return articles.map(article => removeMarkdown(article));
return articles.map(article => {
return {
title: article.title,
text: removeMarkdown(article.body_markdown)
};
});
};

// Get text statistics for a list of plaintext
const getStats = articles => {
ws.send(JSON.stringify({ msg: `Progress: analyzing ${emojis.random()}` }));
const analyze = new sentimentAnalysis().analyze;
return articles.map(article => {
return {
title: article.title,
readability: {
fleschReadingEase: textReadability.fleschReadingEase(article),
fleschKincaidGrade: textReadability.fleschKincaidGrade(article)
fleschReadingEase: textReadability.fleschReadingEase(article.text),
fleschKincaidGrade: textReadability.fleschKincaidGrade(article.text)
},
sentiment: analyze(article).comparative
sentiment: analyze(article.text).comparative
};
});
};

getArticles(user)
.then(articles => ws.send(JSON.stringify({ result: getStats(articles) })))
.catch(err => console.error(err));
.then(articles =>
ws.send(JSON.stringify({ msg: "", result: getStats(articles) }))
)
.catch(err => {
console.error(err);
});
};
63 changes: 63 additions & 0 deletions emojis.js
@@ -0,0 +1,63 @@
// Positive
const emojis = [
"😀",
"😁",
"😂",
"🤣",
"😃",
"😄",
"😆",
"🙃",
"😍",
"😘",
"🤩",
"😺",
"😸",
"😹",
"😻",
"🙌",
"👏",
"👍",
"👌",
"🤟",
"🖖",
"🧚‍♀️",
"🧚‍♂️",
"👼",
"👸",
"🤴",
"💃",
"🕺",
"👯",
"👯‍♂️",
"🦄",
"🦋",
"🍀",
"⭐",
"🌟",
"✨",
"☀️",
"🎆",
"🌈",
"💎",
"🎁",
"🎊",
"🎉",
"💌",
"🏳️‍🌈",
"❤️",
"💜",
"💕",
"💓",
"💗",
"💖",
"💘",
"💝",
"💯"
]

module.exports = {
random: function () {
return emojis[Math.floor(Math.random() * emojis.length)]
}
}
Binary file added preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions public/apexcharts.js

Large diffs are not rendered by default.

0 comments on commit 5667af8

Please sign in to comment.