forked from cpp/cWikiBot
74 lines
2 KiB
C
74 lines
2 KiB
C
/*
|
|
* main.c
|
|
*
|
|
* Copyright 2020 <cpp@zom.bi>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
* MA 02110-1301, USA.
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <json-c/json_object.h>
|
|
|
|
#include "lichess.h"
|
|
#include "http.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
// json_object *profile = malloc(1);
|
|
FILE *output = fopen("output.csv","w");
|
|
FILE *playersfile = fopen("players.csv","r");
|
|
if(playersfile == NULL)
|
|
{
|
|
fputs("Couldn't open players.csv\n",stdout);
|
|
return 1;
|
|
}
|
|
fputs("lichess_id,name\n",output);
|
|
char line [128];
|
|
int j=0;
|
|
while(fgets(line, 128, playersfile) != NULL)
|
|
{
|
|
printf("%i: ",j);
|
|
j++;
|
|
char outline[256];
|
|
line[strlen(line)-1] = '\0';
|
|
json_object *profile = query_lichess(line);
|
|
if(profile == NULL)
|
|
{
|
|
printf("No profile for %s\n", line);
|
|
continue;
|
|
}
|
|
const char *firstName = json_object_get_string(json_object_object_get(profile,"firstName"));
|
|
const char *lastName = json_object_get_string(json_object_object_get(profile,"lastName"));
|
|
if(firstName == NULL || lastName == NULL)
|
|
{
|
|
printf("No name for %s\n",line);
|
|
json_object_put(profile);
|
|
continue;
|
|
}
|
|
sprintf(outline, "%s,%s %s\n",line,firstName,lastName);
|
|
printf("OK\n");
|
|
fputs(outline,output);
|
|
json_object_put(profile);
|
|
}
|
|
fclose(output);
|
|
fclose(playersfile);
|
|
return 0;
|
|
}
|