Compare commits

...

No commits in common. "2697a5f7fca61eb64fccc6892e94d53852125245" and "f65cede700318eb43198b404c15764b40e8867bf" have entirely different histories.

6 changed files with 37 additions and 6 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
cWikiBot cWikiBot
output.csv

12
Dockerfile Normal file
View file

@ -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]

5
docker-compose.yml Normal file
View file

@ -0,0 +1,5 @@
version: ' 2.4'
services:
cWikiBot:
build: .

3
http.c
View file

@ -5,7 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
int curl_setup = 0; int curl_setup = 0;
char* request(char *url ) char* request(char *url)
{ {
// initialize curl on the first call of this function // initialize curl on the first call of this function
if(curl_setup == 0) if(curl_setup == 0)
@ -30,7 +30,6 @@ char* request(char *url )
fprintf(stderr, "CURL Error"); fprintf(stderr, "CURL Error");
return NULL; return NULL;
} }
printf("%i\n",httpResponse.size);
if(return_code != CURLE_OK) if(return_code != CURLE_OK)
{ {
fprintf(stderr, "HTTP Error: %s",curl_easy_strerror(return_code)); fprintf(stderr, "HTTP Error: %s",curl_easy_strerror(return_code));

View file

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <json-c/json_tokener.h> #include <json-c/json_tokener.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
json_object* query_lichess(char* username) json_object* query_lichess(char* username)
{ {
@ -13,9 +14,14 @@ json_object* query_lichess(char* username)
char user_url[128]; char user_url[128];
strcpy(user_url,api_base); strcpy(user_url,api_base);
strcat(user_url,username); strcat(user_url,username);
printf("%s",user_url); printf("querying %s\n",user_url);
char* http_response = request(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 *lichessUser = json_tokener_parse(http_response);
json_object *profile = json_object_object_get(lichessUser,"profile"); json_object *profile = json_object_object_get(lichessUser,"profile");
return profile; return profile;

12
main.c
View file

@ -45,20 +45,28 @@ int main(int argc, char **argv)
{ {
char outline[256]; char outline[256];
char name[128]; char name[128];
line[strlen(line)-1] = '\0';
json_object *profile = query_lichess(line); 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 *firstName = json_object_get_string(json_object_object_get(profile,"firstName"));
char *lastName = json_object_get_string(json_object_object_get(profile,"lastName")); char *lastName = json_object_get_string(json_object_object_get(profile,"lastName"));
if(firstName == NULL || lastName == NULL) if(firstName == NULL || lastName == NULL)
{ {
printf("No name for %s",line); printf("No name for %s\n",line);
printf("object is: %s",json_object_get_string(profile));
continue; continue;
} }
strcpy(name,firstName); strcpy(name,firstName);
strcat(name," "); strcat(name," ");
strcat(name,lastName); strcat(name,lastName);
sprintf(outline, "%s,%s\n",line,name); sprintf(outline, "%s,%s\n",line,name);
printf("OK\n");
fputs(outline,output); fputs(outline,output);
} }
fclose(output);
fclose(playersfile);
return 0; return 0;
} }