Compare commits
No commits in common. "2697a5f7fca61eb64fccc6892e94d53852125245" and "85c73cba2a3e8ef3227e8b51dd1f021830966625" have entirely different histories.
2697a5f7fc
...
85c73cba2a
4 changed files with 12 additions and 60867 deletions
19
http.c
19
http.c
|
@ -7,35 +7,24 @@
|
|||
int curl_setup = 0;
|
||||
char* request(char *url )
|
||||
{
|
||||
// initialize curl on the first call of this function
|
||||
if(curl_setup == 0)
|
||||
if(!curl_setup)
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl_setup=1;
|
||||
url +=1;
|
||||
}
|
||||
|
||||
struct httpResponse_t httpResponse;
|
||||
httpResponse.response = malloc(1);
|
||||
httpResponse.size = 0;
|
||||
CURL *httpHandler = curl_easy_init();
|
||||
CURLcode return_code;
|
||||
if(httpHandler) {
|
||||
curl_easy_setopt(httpHandler,CURLOPT_URL, url);
|
||||
curl_easy_setopt(httpHandler,CURLOPT_WRITEFUNCTION, httpResponseCallback);
|
||||
curl_easy_setopt(httpHandler,CURLOPT_WRITEDATA, (void *)&httpResponse);
|
||||
return_code = curl_easy_perform(httpHandler);
|
||||
curl_easy_perform(httpHandler);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "CURL Error");
|
||||
return NULL;
|
||||
}
|
||||
printf("%i\n",httpResponse.size);
|
||||
if(return_code != CURLE_OK)
|
||||
{
|
||||
fprintf(stderr, "HTTP Error: %s",curl_easy_strerror(return_code));
|
||||
return NULL;
|
||||
}
|
||||
return "Lol, fehler";
|
||||
return httpResponse.response;
|
||||
}
|
||||
size_t httpResponseCallback(char *data, size_t wordlength, size_t bytecount, void *out)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <stdio.h>
|
||||
|
||||
json_object* query_lichess(char* username)
|
||||
{
|
||||
|
@ -12,10 +11,8 @@ json_object* query_lichess(char* username)
|
|||
char* api_base = "https://lichess.org/api/user/";
|
||||
char user_url[128];
|
||||
strcpy(user_url,api_base);
|
||||
strcat(user_url,username);
|
||||
printf("%s",user_url);
|
||||
char* http_response = request(user_url);
|
||||
printf("\n%p\n",http_response);
|
||||
char* http_response = request(strcat(
|
||||
user_url,username));
|
||||
json_object *lichessUser = json_tokener_parse(http_response);
|
||||
json_object *profile = json_object_object_get(lichessUser,"profile");
|
||||
return profile;
|
||||
|
|
31
main.c
31
main.c
|
@ -32,33 +32,8 @@
|
|||
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];
|
||||
while(fgets(line, sizeof line, playersfile) != NULL)
|
||||
{
|
||||
char outline[256];
|
||||
char name[128];
|
||||
json_object *profile = query_lichess(line);
|
||||
char *firstName = json_object_get_string(json_object_object_get(profile,"firstName"));
|
||||
char *lastName = json_object_get_string(json_object_object_get(profile,"lastName"));
|
||||
if(firstName == NULL || lastName == NULL)
|
||||
{
|
||||
printf("No name for %s",line);
|
||||
printf("object is: %s",json_object_get_string(profile));
|
||||
continue;
|
||||
}
|
||||
strcpy(name,firstName);
|
||||
strcat(name," ");
|
||||
strcat(name,lastName);
|
||||
sprintf(outline, "%s,%s\n",line,name);
|
||||
fputs(outline,output);
|
||||
}
|
||||
json_object *profile = query_lichess("alireza2003");
|
||||
printf("%s\n",json_object_get_string(profile));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
60816
players.csv
60816
players.csv
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue