Skip to content

Commit

Permalink
Update data.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxRohowsky committed Mar 9, 2024
1 parent b95a495 commit f7be91f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run hello.js
run: node hello.js
- name: Run parse-readme.js
run: node parse-readme.js

- name: Commit and push if changed
uses: EndBug/add-and-commit@v4
with:
author_name: 'GitHub Actions'
author_email: '[email protected]'
message: 'Update data.js'

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Made by [Max](maxontech.io)
| Jonathan | Gin | [jonathangin52](https://github.com/jonathangin52) | [README](https://github.com/jonathangin52/jonathangin52) |
| Kavish | Hukmani | [DoubleGremlin181](https://github.com/DoubleGremlin181) | [README](https://github.com/DoubleGremlin181/DoubleGremlin181) |
| Lee | Reilly | [leereilly](https://github.com/leereilly) | [README](https://github.com/leereilly/leereilly) |
| Max | Rohowsky | [maxontech](https://github.com/maxontech/maxontech) | [README](https://github.com/maxontech/maxontech) |
| Max | Rohowsky | [maxontech](https://github.com/maxontech) | [README](https://github.com/maxontech/maxontech) |
| Michael | Hoffmann | [mokkapps](https://github.com/mokkapps) | [README](https://github.com/mokkapps/mokkapps) |
| Monica | Powell | [M0nica](https://github.com/M0nica) | [README](https://github.com/M0nica/M0nica) |
| Nate | Moore | [natemoo-re](https://github.com/natemoo-re) | [README](https://github.com/natemoo-re/natemoo-re) |
Expand Down
12 changes: 0 additions & 12 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
[
{
"githubUrl": "https://github.com/sw-yx",
"nickName": "Shawn Wang",
"filePath": "screenshots/sw-yx.jpeg"
},
{
"githubUrl": "https://github.com/thmsgbrt",
"nickName": "Thomas Guibert",
"filePath": "screenshots/thmsgbrt.jpeg"
}
]
2 changes: 0 additions & 2 deletions hello.js

This file was deleted.

55 changes: 55 additions & 0 deletions parse-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'readme.md');
const dataFilePath = path.join(__dirname, 'data.json');

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}

const regex = /\|\s*(\w+)\s*\|\s*(\w+)\s*\|\s*\[\w+\]\((https:\/\/github\.com\/[^\/]+)\)\s*\|\s*\[README\]\((https:\/\/github\.com\/[^\/]+\/[^\/]+)\)/g;
let match;
let users = [];
while ((match = regex.exec(data)) !== null) {
const profileName = match[3].split('/').pop();
users.push({
timestamp: new Date().toISOString(),
firstName: match[1],
lastName: match[2],
githubProfile: match[3],
githubReadme: match[4],
screenshotPath: `screenshots/${profileName}.jpeg`
});
}

const json = JSON.stringify(users, null, 2);
console.log(json);


fs.readFile(dataFilePath, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}

let existingUsers = [];
if (data) {
existingUsers = JSON.parse(data);
}

const newUsers = users.filter(user => !existingUsers.some(existingUser => existingUser.githubProfile === user.githubProfile));

const allUsers = [...existingUsers, ...newUsers];
const json = JSON.stringify(allUsers, null, 2);

fs.writeFile(dataFilePath, `${json}`, 'utf8', err => {
if (err) {
console.error(err);
return;
}
console.log('Data written to file');
});
});
});

0 comments on commit f7be91f

Please sign in to comment.