cWikiBot/main.c

75 lines
2 KiB
C
Raw Normal View History

2020-12-26 16:50:29 +01:00
/*
* main.c
2020-12-27 00:11:03 +01:00
*
2020-12-26 16:50:29 +01:00
* Copyright 2020 <cpp@zom.bi>
2020-12-27 00:11:03 +01:00
*
2020-12-26 16:50:29 +01:00
* 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.
2020-12-27 00:11:03 +01:00
*
2020-12-26 16:50:29 +01:00
* 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.
2020-12-27 00:11:03 +01:00
*
2020-12-26 16:50:29 +01:00
* 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.
2020-12-27 00:11:03 +01:00
*
*
2020-12-26 16:50:29 +01:00
*/
2020-12-27 00:11:03 +01:00
2020-12-26 16:50:29 +01:00
#include <stdio.h>
#include <stdlib.h>
2020-12-27 00:11:03 +01:00
#include <unistd.h>
2020-12-26 16:50:29 +01:00
#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];
2020-12-26 23:09:38 +01:00
int j=0;
2020-12-27 00:11:03 +01:00
while(fgets(line, 128, playersfile) != NULL)
2020-12-26 16:50:29 +01:00
{
2020-12-27 00:11:03 +01:00
printf("%i: ",j);
2020-12-26 23:09:38 +01:00
j++;
2020-12-26 16:50:29 +01:00
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;
}
2020-12-27 00:11:03 +01:00
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"));
2020-12-26 16:50:29 +01:00
if(firstName == NULL || lastName == NULL)
{
printf("No name for %s\n",line);
2020-12-27 00:11:03 +01:00
json_object_put(profile);
2020-12-26 16:50:29 +01:00
continue;
}
2020-12-27 00:11:03 +01:00
sprintf(outline, "%s,%s %s\n",line,firstName,lastName);
2020-12-26 16:50:29 +01:00
printf("OK\n");
fputs(outline,output);
2020-12-27 00:11:03 +01:00
json_object_put(profile);
2020-12-26 16:50:29 +01:00
}
fclose(output);
fclose(playersfile);
return 0;
}