-
Notifications
You must be signed in to change notification settings - Fork 163
/
YoutubeViews.sol
37 lines (30 loc) · 1000 Bytes
/
YoutubeViews.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pragma solidity >= 0.5.0 < 0.6.0;
import "github.com/provable-things/ethereum-api/provableAPI.sol";
contract YoutubeViews is usingProvable {
string public viewsCount;
event LogYoutubeViewCount(string views);
event LogNewProvableQuery(string description);
constructor()
public
{
update(); // Update views on contract creation...
}
function __callback(
bytes32 _myid,
string memory _result
)
public
{
require(msg.sender == provable_cbAddress());
viewsCount = _result;
emit LogYoutubeViewCount(viewsCount);
// Do something with viewsCount, like tipping the author if viewsCount > X?
}
function update()
public
payable
{
emit LogNewProvableQuery("Provable query was sent, standing by for the answer...");
provable_query("URL", 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(@class, "watch-view-count")]/text())');
}
}