fawazahmed0 / exchange-api

Free Currency Exchange Rates API with 200+ Currencies & No Rate Limits
https://github.com/fawazahmed0/exchange-api#readme
Creative Commons Zero v1.0 Universal
601 stars 37 forks source link

Can we fix other/cryptocurrencies.json ? #81

Closed RaptaG closed 7 months ago

RaptaG commented 8 months ago

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 fawazahmed0/exchange-api#40 to update other/cryptocurrencies.json as well

RaptaG commented 8 months ago

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:

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