Compare commits
No commits in common. "0189bcc0d0131f8f891b03a91a3ca9aa1046d2f9" and "a8c8b72e206c1547cf09b825e02fdb25efefa479" have entirely different histories.
0189bcc0d0
...
a8c8b72e20
2 changed files with 2 additions and 7 deletions
1
http.c
1
http.c
|
@ -22,7 +22,6 @@ char* request(char *url)
|
||||||
if(httpHandler) {
|
if(httpHandler) {
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_URL, url);
|
curl_easy_setopt(httpHandler,CURLOPT_URL, url);
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_WRITEFUNCTION, httpResponseCallback);
|
curl_easy_setopt(httpHandler,CURLOPT_WRITEFUNCTION, httpResponseCallback);
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_USERAGENT, "cWikiBot/0.1 (https://git.zom.bi/cpp/cWikiBot; cpp@zom.bi) libcurl4/7.64.0");
|
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_WRITEDATA, (void *)&httpResponse);
|
curl_easy_setopt(httpHandler,CURLOPT_WRITEDATA, (void *)&httpResponse);
|
||||||
return_code = curl_easy_perform(httpHandler);
|
return_code = curl_easy_perform(httpHandler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,15 @@ json_object* query_lichess(char* username)
|
||||||
*/
|
*/
|
||||||
char* api_base = "https://lichess.org/api/user/";
|
char* api_base = "https://lichess.org/api/user/";
|
||||||
char user_url[128];
|
char user_url[128];
|
||||||
int retries = 5;
|
|
||||||
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("querying %s\n",user_url);
|
||||||
char* http_response = request(user_url);
|
char* http_response = request(user_url);
|
||||||
while(http_response == NULL)
|
if(http_response == NULL)
|
||||||
{
|
{
|
||||||
printf("didn't receive HTTP response, we might be rate-limited. Waiting 60s");
|
printf("didn't receive HTTP response, we might be rate-limited. Waiting 60s");
|
||||||
sleep(60);
|
sleep(60);
|
||||||
http_response = request(user_url);
|
return NULL;
|
||||||
retries--;
|
|
||||||
if(retries == 0)
|
|
||||||
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");
|
||||||
|
|
Loading…
Reference in a new issue