Compare commits
No commits in common. "f65cede700318eb43198b404c15764b40e8867bf" and "2697a5f7fca61eb64fccc6892e94d53852125245" have entirely different histories.
f65cede700
...
2697a5f7fc
6 changed files with 6 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
cWikiBot
|
||||
output.csv
|
||||
|
|
12
Dockerfile
12
Dockerfile
|
@ -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]
|
|
@ -1,5 +0,0 @@
|
|||
version: ' 2.4'
|
||||
|
||||
services:
|
||||
cWikiBot:
|
||||
build: .
|
1
http.c
1
http.c
|
@ -30,6 +30,7 @@ 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));
|
||||
|
|
10
lichess.c
10
lichess.c
|
@ -3,7 +3,6 @@
|
|||
#include <string.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
json_object* query_lichess(char* username)
|
||||
{
|
||||
|
@ -14,14 +13,9 @@ json_object* query_lichess(char* username)
|
|||
char user_url[128];
|
||||
strcpy(user_url,api_base);
|
||||
strcat(user_url,username);
|
||||
printf("querying %s\n",user_url);
|
||||
printf("%s",user_url);
|
||||
char* http_response = request(user_url);
|
||||
if(http_response == NULL)
|
||||
{
|
||||
printf("didn't receive HTTP response, we might be rate-limited. Waiting 60s");
|
||||
sleep(60);
|
||||
return NULL;
|
||||
}
|
||||
printf("\n%p\n",http_response);
|
||||
json_object *lichessUser = json_tokener_parse(http_response);
|
||||
json_object *profile = json_object_object_get(lichessUser,"profile");
|
||||
return profile;
|
||||
|
|
12
main.c
12
main.c
|
@ -45,28 +45,20 @@ 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\n",line);
|
||||
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);
|
||||
printf("OK\n");
|
||||
fputs(outline,output);
|
||||
}
|
||||
fclose(output);
|
||||
fclose(playersfile);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue