// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; /** * Request testnet LINK and ETH here: https://faucets.chain.link/ * Find information on LINK Token Contracts and get the latest ETH and LINK faucets here: https://docs.chain.link/docs/link-token-contracts/ */ contract COVIDstats is ChainlinkClient { using Chainlink for Chainlink.Request; uint public confirmedCases; address private oracle; bytes32 private jobId; uint256 private fee; /** * Network: Kovan */ constructor() { setPublicChainlinkToken(); oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8; jobId = "d5270d1c311941d0b08bead21fea7747"; fee = 0.1 * 10 ** 18; // (Varies by network and job) } function requestCovidData() public returns (bytes32 requestId) { Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); // Set the URL to perform the GET request on request.add("get", "https://api.apify.com/v2/key-value-stores/603AyvQ8QjyqmnZx6/records/LATEST?disableRedirect=true"); // Set the path to find the desired data in the API response, where the response format is: //{ //testedCases 8094663 //infectedCases 322914 //numberOfDeath 5027 //dailyTested 37324 //dailyInfected 2292 //dailyDeaths 10 //dailyDischarged 45 //dailyHospitalized 510 //dailyIntensiveCare 131 //country "slovenia" //historyData "https://api.apify.com/v2/datasets/H6HKZRQr8I81bClnb/items?format=json&clean=1" //sourceUrl "https://www.gov.si/en/topics/coronavirus-disease-covid-19/actual-data/" //lastUpdatedAtApify "2021-11-03T10:00:00.000Z" //lastUpdatedAtSource "2021-10-26T09:54:00.000Z" //readMe "https://apify.com/dtrungtin/covid-si" //} request.add("path", "dailyInfected"); return sendChainlinkRequestTo(oracle, request, fee); } function requestCovidDatav2() public returns (bytes32 requestId) { Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); // Set the URL to perform the GET request on request.add("get", "https://covid19-api.com/country?name=slovenia&format=json"); // Set the path to find the desired data in the API response, where the response format is: // [ // { // "country": "Slovenia", // "code": "SI", // "confirmed": 383734, // "recovered": 333301, // "critical": 172, // "deaths": 4958, // "latitude": 46.151241, // "longitude": 14.995463, // "lastChange": "2021-11-16T11:01:10+01:00", // "lastUpdate": "2021-11-16T17:00:04+01:00" // } // ] request.add("path", "0.confirmed"); return sendChainlinkRequestTo(oracle, request, fee); } /** * Receive the response in the form of uint256 */ function fulfill(bytes32 _requestId, uint _data) public recordChainlinkFulfillment(_requestId) { confirmedCases = _data; } }