Compare commits

...

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

6 changed files with 6 additions and 37 deletions

1
.gitignore vendored
View file

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

View file

@ -1,12 +0,0 @@
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]

View file

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

1
http.c
View file

@ -30,6 +30,7 @@ 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,7 +3,6 @@
#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)
{ {
@ -14,14 +13,9 @@ 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("querying %s\n",user_url); printf("%s",user_url);
char* http_response = request(user_url); char* http_response = request(user_url);
if(http_response == NULL) printf("\n%p\n",http_response);
{
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,28 +45,20 @@ 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\n",line); printf("No name for %s",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;
} }