Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we fix other/cryptocurrencies.json ? #81

Closed
RaptaG opened this issue Jan 20, 2024 · 1 comment
Closed

Can we fix other/cryptocurrencies.json ? #81

RaptaG opened this issue Jan 20, 2024 · 1 comment

Comments

@RaptaG
Copy link

RaptaG commented Jan 20, 2024

We already have other/currencies.json but other/cryptocurrencies.json has more currencies that the ones included. Could we fix other/cryptocurrencies.json to only include the currencies that the API has?

Then, we instruct in #40 to update other/cryptocurrencies.json as well

@RaptaG RaptaG changed the title Can you publish two extra JSONs every day, the one with all the national currencies you have and all the cryptocurrencies you have? Can we fix other/cryptocurrencies.json ? Jan 20, 2024
@RaptaG
Copy link
Author

RaptaG commented Jan 20, 2024

Using a Python script generated by ChatGPT I removed all matching entries from other/cryptocurrencies.json that match other/currencies.json

import json

def lowercase_names(json_data):
    """Lowercases the names of each value in a JSON file."""
    for key, value in json_data.items():
        json_data[key] = value.lower()
    return json_data

def remove_entries(json_data, names_to_remove):
    """Removes entries from a JSON file based on a list of names."""
    return {key: value for key, value in json_data.items() if value not in names_to_remove}

def main():
    # Read the first JSON file
    with open('first_file.json', 'r') as file1:
        json_data1 = json.load(file1)

    # Read the second JSON file
    with open('second_file.json', 'r') as file2:
        json_data2 = json.load(file2)

    # Lowercase names in the first JSON file
    json_data1_lowered = lowercase_names(json_data1)

    # Get a list of lowercased names from the first JSON file
    names_to_remove = list(json_data1_lowered.values())

    # Remove entries from the second JSON file based on the names
    result_json_data = remove_entries(json_data2, names_to_remove)

    # Write the result to a new file
    with open('result_file.json', 'w') as result_file:
        json.dump(result_json_data, result_file, indent=2)

if __name__ == "__main__":
    main()

The output showed that:

  • There are some cryptocurrencies in other/currencies.json (eg. "BTC": "Bitcoin",)
  • There are some codes that don't match:
    • Brazilian Real
    • Zimbabwean Dollar
    • and more

I will make a Pull Request fixing these issues, I would love if you reviewed it!

@RaptaG RaptaG closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2024
@fawazahmed0 fawazahmed0 transferred this issue from another repository Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant