Esempio n. 1
0
string get_round(int i) {
  string ret =  NO_ROUND;
  char buff[100];
  sprintf(buff, "https://old.jutge.org/competitions/AlbertAtserias:BolaDeDrac2015/round/%d", i);
  string url = buff;
  request.setOpt(curlpp::options::Url(url));

  request.perform();
  string re = responseStream.str();
  size_t found = re.find("Player out:");

  if (found != string::npos) {
    size_t inici = re.find("<p class='indent'>",found+1);
    size_t fi =  re.find("(",found+1);
    cout << " --> ";
    if (inici != string::npos and fi != string::npos) {
      ret =  re.substr(inici+18, fi-(inici+18));
      cout << ret << endl;
    }
  } else if (re.find("Turn 1") != string::npos) {
    ret = ONGOING;
  }

  responseStream.str(string());
  return ret;
}
int main(int argc, char *argv[]) {
     int PIN = 2;
     if(wiringPiSetup() == -1)
       return 0;
     mySwitch = RCSwitch();
     mySwitch.enableReceive(PIN);  // Receiver on inerrupt 0 => that is pin #2
     while(1) {
      if (mySwitch.available()) {
        int value = mySwitch.getReceivedValue();
        if (value == 0) {
          printf("Unknown encoding");
        } else {
          // Set the URL.
          myRequest.setOpt(new curlpp::options::Url(std::string("http://127.0.0.1:8080/sarah/detecteurs?code=" + patch::to_string(value) )));
          // Send request and get a result.
          myRequest.perform();
          printf("%d\n", value);
          sleep(5);
        }
        mySwitch.resetAvailable();
      }
     sleep(1);
     }
  exit(0);
}
Esempio n. 3
0
void curlpp_init() {
  list<string> headers;
  headers.push_back(HEADER_ACCEPT);
  headers.push_back(HEADER_USER_AGENT);
  request.setOpt(new curlpp::options::HttpHeader(headers));
  request.setOpt(new curlpp::options::FollowLocation(true));
  request.setOpt(curlpp::options::SslVerifyPeer(false));
  request.setOpt(curlpp::options::SslVerifyHost(false));

  curlpp::options::WriteStream streamWriter(&responseStream);
  request.setOpt(streamWriter);
}