Skip to content

Commit

Permalink
Add new users to data.json
Browse files Browse the repository at this point in the history
  • Loading branch information
maxontech committed Mar 11, 2024
1 parent 28d0f63 commit 01227cd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
48 changes: 48 additions & 0 deletions docs/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,53 @@
"githubProfile": "https://github.com/laxmena",
"githubReadme": "https://github.com/laxmena/laxmena) |\n\n\n## Readme Elements and Tools\n\nTODO: This section will have popular elements and tools to add to your profile. \n\n\n## Contribute\n\nWe encourage you to contribute to \"Best GitHub Profile READMEs\"!\n\nPlease check out the [Contributing guide](CONTRIBUTING.md",
"screenshotPath": "screenshots/laxmena.jpeg"
},
{
"timestamp": "2024-03-11T17:05:07.864Z",
"firstName": "Danny",
"lastName": "Koppenhagen",
"githubProfile": "https://github.com/d-koppenhagen",
"githubReadme": "https://github.com/d-koppenhagen/d-koppenhagen",
"screenshotPath": "screenshots/d-koppenhagen.jpeg"
},
{
"timestamp": "2024-03-11T17:05:07.864Z",
"firstName": "Nate",
"lastName": "Moore",
"githubProfile": "https://github.com/natemoo-re",
"githubReadme": "https://github.com/natemoo-re/natemoo-re",
"screenshotPath": "screenshots/natemoo-re.jpeg"
},
{
"timestamp": "2024-03-11T17:05:07.864Z",
"firstName": "Rahul",
"lastName": "Jha",
"githubProfile": "https://github.com/rahul-jha98",
"githubReadme": "https://github.com/rahul-jha98/rahul-jha98",
"screenshotPath": "screenshots/rahul-jha98.jpeg"
},
{
"timestamp": "2024-03-11T17:05:07.864Z",
"firstName": "Sagar",
"lastName": "Viradiya",
"githubProfile": "https://github.com/sagar-viradiya",
"githubReadme": "https://github.com/sagar-viradiya/sagar-viradiya",
"screenshotPath": "screenshots/sagar-viradiya.jpeg"
},
{
"timestamp": "2024-03-11T17:05:07.864Z",
"firstName": "Ari",
"lastName": "Hacks",
"githubProfile": "https://github.com/ari-hacks",
"githubReadme": "https://github.com/ari-hacks/ari-hacks",
"screenshotPath": "screenshots/ari-hacks.jpeg"
},
{
"timestamp": "2024-03-11T17:05:07.864Z",
"firstName": "Muhammedh",
"lastName": "Shadir",
"githubProfile": "https://github.com/muhammedh-shadir",
"githubReadme": "https://github.com/muhammedh-shadir/muhammedh-shadir",
"screenshotPath": "screenshots/muhammedh-shadir.jpeg"
}
]
22 changes: 20 additions & 2 deletions docs/parse-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ fs.readFile(filePath, 'utf8', (err, data) => {
return;
}

const regex = /\|\s*(\w+)\s*\|\s*(\w+)\s*\|\s*\[\w+\]\((https:\/\/github\.com\/[^\/]+)\)\s*\|\s*\[README\]\((https:\/\/github\.com\/[^\/]+\/[^\/]+)\)/g;
// Define a regular expression to match the user data
//const regex = /\|\s*(\w+)\s*\|\s*(\w+)\s*\|\s*\[\w+\]\((https:\/\/github\.com\/[^\/]+)\)\s*\|\s*\[README\]\((https:\/\/github\.com\/[^\/]+\/[^\/]+)\)/g;
const regex = /\|\s*([\w-]+)\s*\|\s*([\w-]+)\s*\|\s*\[[\w-]+\]\((https:\/\/github\.com\/[^\/]+)\)\s*\|\s*\[README\]\((https:\/\/github\.com\/[^\/]+\/[^\/]+)\)/g;
let match;
let users = [];

console.log(regex);
// Loop through the matches and push the user data to the users array
while ((match = regex.exec(data)) !== null) {
const profileName = match[3].split('/').pop();
users.push({
Expand All @@ -27,28 +32,41 @@ fs.readFile(filePath, 'utf8', (err, data) => {
const json = JSON.stringify(users, null, 2);
console.log(json);


// Read the file specified by dataFilePath
fs.readFile(dataFilePath, 'utf8', (err, data) => {

// If there's an error reading the file, log the error and exit
if (err) {
console.error(err);
return;
}

// Initialize an array to hold the existing users
let existingUsers = [];

// If the file has data, parse it as JSON and assign it to existingUsers
if (data) {
existingUsers = JSON.parse(data);
}

// Filter out the users that already exist in the data file
const newUsers = users.filter(user => !existingUsers.some(existingUser => existingUser.githubProfile === user.githubProfile));

// Combine the existing users and the new users
const allUsers = [...existingUsers, ...newUsers];

// Convert the allUsers array into a JSON string with a 2-space indentation
const json = JSON.stringify(allUsers, null, 2);

// Write the JSON string to the same file
fs.writeFile(dataFilePath, `${json}`, 'utf8', err => {

// If there's an error writing to the file, log the error and exit
if (err) {
console.error(err);
return;
}
// Log a success message
console.log('Data written to file');
});
});
Expand Down

0 comments on commit 01227cd

Please sign in to comment.