Get-Pair-Extraordinaire
Get-Pair-Extraordinaire copied to clipboard
Make it so that `streak.json` and `Extraordinary. MD` do not have duplicate entry for same account.
Although we can add an extra field in json "Times" to show how many times user has used the repo. Same can be done with Extraordinary.MD
I'd Like to know more
This repo can be used multiple time for same account and each time it will add to open further rank for Pair-Extraordinaire badge. But for each time there will be a separate entry for same person in extraordinary.md
and streak.json
Basically what I want to do is if a user decide to reuse the repo it does do all the steps, but while updating the streak.json
and Extraordinary.md
It check if user has previously used the repo, if they have then it add an extra entry to their json block instead of adding a new block altogether, this will keep json from having entry for same account over and over, and something similar can also be done for Extraordinary.md
GitHub Copilot: Sure, here's a step-by-step plan in pseudocode:
- Define a function
update_files(user)
. - In this function, first check if the user has previously used the repo.
- Open the
streak.json
file and read its content. - Parse the content to a JSON object.
- Check if the user's account is in the JSON object.
- Open the
- If the user's account is in the JSON object, add an extra entry to their JSON block.
- Find the user's block in the JSON object.
- Add a new entry to the block.
- Convert the JSON object back to a string.
- Write the string back to the
streak.json
file.
- If the user's account is not in the JSON object, add a new block for the user.
- Create a new block with the user's account and the entry.
- Add the block to the JSON object.
- Convert the JSON object back to a string.
- Write the string back to the
streak.json
file.
- Repeat similar steps for the
Extraordinary.md
file.
Here's a Python code snippet that implements the above pseudocode:
import json
def update_files(user, entry):
# Open the streak.json file and read its content
with open('streak.json', 'r+') as file:
data = json.load(file)
# Check if the user's account is in the JSON object
if user in data:
# Add a new entry to the block
data[user].append(entry)
else:
# Add a new block for the user
data[user] = [entry]
# Write the string back to the streak.json file
file.seek(0)
json.dump(data, file)
file.truncate()
# Repeat similar steps for the Extraordinary.md file
with open('Extraordinary.md', 'r+') as file:
content = file.readlines()
# Check if the user's account is in the file
if any(user in line for line in content):
# Add a new entry to the user's line
for i, line in enumerate(content):
if user in line:
content[i] += '\n' + entry
break
else:
# Add a new line for the user
content.append(user + '\n' + entry)
# Write the content back to the Extraordinary.md file
file.seek(0)
file.writelines(content)
file.truncate()
You can call the update_files
function with the user's account and the new entry as arguments:
update_files('user_account', 'new_entry')
This code assumes that the streak.json
file is a dictionary where the keys are the user accounts and the values are lists of entries, and that the Extraordinary.md
file is a text file where each line starts with a user account followed by the entries for that user.
import json
def update_files(user, entry): # Open the streak.json file and read its content with open('streak.json', 'r+') as file: data = json.load(file)
# Check if the user's account is in the JSON object
if user in data:
# Add a new entry to the block
data[user].append(entry)
else:
# Add a new block for the user
data[user] = [entry]
# Write the string back to the streak.json file
file.seek(0)
json.dump(data, file)
file.truncate()
# Repeat similar steps for the Extraordinary.md file
with open('Extraordinary.md', 'r+') as file:
content = file.readlines()
# Check if the user's account is in the file
if any(user in line for line in content):
# Add a new entry to the user's line
for i, line in enumerate(content):
if user in line:
content[i] += '\n' + entry
break
else:
# Add a new line for the user
content.append(user + '\n' + entry)
# Write the content back to the Extraordinary.md file
file.seek(0)
file.writelines(content)
file.truncate()
i used my subscription to to copilot for tis code, let me know what you think
Hey, please test the code on your end by forking the repo and doing the suggested changes, I also have copilot subscription but this code will most likely not work.
The streak.json is multilevel nested dict and we need to update extraordinary.md file too. Also if you are new to coding, I would suggest not using the copilot. As it will hinder in your skill development.
I know how to do the changes for the issue, I am just not getting enough time to do this.
OK Thanks, for your advice, yes i am new to coding and enjoying it very much, i work in IT but don't get to code so I'm teaching myself, i've forked the repo
Yeah, Please familiarize yourself with code first. Use the README.md and provided graphs in documentation to understand the workflow. Then it will be much easier to do the changes.