#Help with CSV files..

7 messages · Page 1 of 1 (latest)

tribal hemlock
#

I am making a translator discord bot and I want to add charts into the bot, one of the features would be to draw a bar chart of some languages and I want a method that increments a specific language by 1. this is what the csv would look like

GuildID, Afrikaans, Albanian, Amharic, Arabic, Armenian, Assamese, Azerbaijani, Bangla, Bashkir, Basque, Bosnian, Bulgarian, Cantonese, Catalan, ChineseLiterary, ChineseSimplified, ChineseTraditional, chiShona, Croatian, Czech, Danish, Dari, Divehi, Dutch, English, Estonian, Faroese, Fijian, Filipino, Finnish, French, FrenchCanada, Galician, Georgian, German, Greek, Gujarati, HaitianCreole, Hausa, Hebrew, Hindi, HmongDaw, Hungarian, Icelandic, Igbo, Indonesian, Inuinnaqtun, Inuktitut, InuktitutLatin, Irish, Italian, Japanese, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, KlingonPlqaD, Konkani, Korean, KurdishCentral, KurdishNorthern, KyrgyzCyrillic, Lao, Latvian, Lithuanian, Lingala, LowerSorbian, Luganda, Macedonian, Maithili, Malagasy, MalayLatin, Malayalam, Maltese, Maori, Marathi, MongolianCyrillic, MongolianTraditional, Myanmar, Nepali, Norwegian, Nyanja, Odia, Pashto, Persian, PigLatin, Pirate, Polish, PortugueseBrazil, PortuguesePortugal, Punjabi, QueretaroOtomi, Romanian, Rundi, Russian, SamoanLatin, SerbianCyrillic, SerbianLatin, Sesotho, SesothoSaLeboa, Setswana, Sindhi, Sinhala, Slovak, Slovenian, SomaliArabic, Spanish, Swahili, Swedish, Tahitian, Tamil, TatarLatin, Telugu, Thai, Tibetan, Tigrinya, Tongan, Turkish, TurkmenLatin, Ukrainian, UpperSorbian, Urdu, UyghurArabic, UzbekLatin, Vietnamese, Welsh, Xhosa, Yoruba, YucatecMaya, Zulu
<whatever_guild_id>, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0... (more zeros / numbers)
 ```java

private static void incrementMostUsedLanguageCSV(long guildId, String language) {
String file = "C:\Users\fergj\IdeaProjects\TranslationsX\src\org\transl\translationsx\storage\MostUsedLanguages.csv";
String guild = String.valueOf(guildId);

        try {
            CSVReader reader = new CSVReader(new FileReader(file));
            List<String[]> lines = reader.readAll();
            reader.close();

            boolean guildFound = false;
            for (String[] line : lines) {
                if (line[0].equals(guild)) {
                    try {
                        int currentValue = Integer.parseInt(line[1]);
                        int newValue = currentValue + 1;
                        line[1] = String.valueOf(newValue);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                    guildFound = true;
                    break;
                }
            }

            if (!guildFound) {

            }

            CSVWriter writer = new CSVWriter(new FileWriter(file));
            writer.writeAll(lines);
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

i just dont know how to go about incrementing a specific language..
cloud cloudBOT
#

This post has been reserved for your question.

Hey @tribal hemlock! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

dense badger
#

Don't necessarily increment line[1]. Instead find out the correct index

tribal hemlock
#

how can i do that

dense badger
#

I'm guessing check the first line, the one that lists the languages

tribal hemlock
#

hmm