diff --git a/.gitignore b/.gitignore index d4d5cbd..7ed6506 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ cWikiBot +output.csv diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..87caffa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM debian:stable +MAINTAINER Linuro <cpp@zom.bi> + +RUN apt-get update && apt-get install build-essential gcc libjson-c-dev libcurl4-openssl-dev + +ADD . /code + +WORKDIR /code + +RUN ./build.sh + +CMD [cWikiBot] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..96fe919 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +version: ' 2.4' + +services: + cWikiBot: + build: . diff --git a/http.c b/http.c index e536e55..bbfc027 100644 --- a/http.c +++ b/http.c @@ -5,7 +5,7 @@ #include <stdlib.h> int curl_setup = 0; -char* request(char *url ) +char* request(char *url) { // initialize curl on the first call of this function if(curl_setup == 0) @@ -30,7 +30,6 @@ char* request(char *url ) 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)); diff --git a/lichess.c b/lichess.c index c1b8d9a..8519bbc 100644 --- a/lichess.c +++ b/lichess.c @@ -3,6 +3,7 @@ #include <string.h> #include <json-c/json_tokener.h> #include <stdio.h> +#include <unistd.h> json_object* query_lichess(char* username) { @@ -13,9 +14,14 @@ json_object* query_lichess(char* username) char user_url[128]; strcpy(user_url,api_base); strcat(user_url,username); - printf("%s",user_url); + printf("querying %s\n",user_url); char* http_response = request(user_url); - printf("\n%p\n",http_response); + if(http_response == NULL) + { + printf("didn't receive HTTP response, we might be rate-limited. Waiting 60s"); + sleep(60); + return NULL; + } json_object *lichessUser = json_tokener_parse(http_response); json_object *profile = json_object_object_get(lichessUser,"profile"); return profile; diff --git a/main.c b/main.c index c26ff66..8fde49b 100644 --- a/main.c +++ b/main.c @@ -45,20 +45,28 @@ int main(int argc, char **argv) { char outline[256]; char name[128]; + line[strlen(line)-1] = '\0'; json_object *profile = query_lichess(line); + if(profile == NULL) + { + printf("No profile for %s\n", line); + continue; + } 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)); + printf("No name for %s\n",line); continue; } strcpy(name,firstName); strcat(name," "); strcat(name,lastName); sprintf(outline, "%s,%s\n",line,name); + printf("OK\n"); fputs(outline,output); } + fclose(output); + fclose(playersfile); return 0; }