Git Product home page Git Product logo

Comments (7)

noelb1 avatar noelb1 commented on May 26, 2024

I'd Like to know more

from get-pair-extraordinaire.

Prakash4844 avatar Prakash4844 commented on May 26, 2024

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

from get-pair-extraordinaire.

noelb1 avatar noelb1 commented on May 26, 2024

GitHub Copilot: Sure, here's a step-by-step plan in pseudocode:

  1. Define a function update_files(user).
  2. 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.
  3. 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.
  4. 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.
  5. 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()

from get-pair-extraordinaire.

noelb1 avatar noelb1 commented on May 26, 2024

i used my subscription to to copilot for tis code, let me know what you think

from get-pair-extraordinaire.

Prakash4844 avatar Prakash4844 commented on May 26, 2024

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.

from get-pair-extraordinaire.

noelb1 avatar noelb1 commented on May 26, 2024

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

from get-pair-extraordinaire.

Prakash4844 avatar Prakash4844 commented on May 26, 2024

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.

from get-pair-extraordinaire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.