-
Notifications
You must be signed in to change notification settings - Fork 1
/
mr-fetch.php
81 lines (71 loc) · 2.12 KB
/
mr-fetch.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
require_once 'mr-common.php';
require_once 'mr-oauth.php';
$last_fetch = intval(fetchConfig('last_fetch'));
$time = time();
while (time() - $time < 300)
{
global $scope;
$c = '';
$xt = 'user/-/state/com.google/read';
$nt = $last_fetch + 60 * 60 * 24 * 7;
$ot = $last_fetch;
while (true)
{
$url = "$scope/0/stream/contents/user/-/state/com.google/reading-list" .
"?${c}xt=$xt&nt=$nt&ot=$ot&n=5&r=o&likes=false&comments=false";
list($http_code, $result) = requestOAuth($url, null, true);
if ($http_code == 200)
{
$json = json_decode($result, true);
if (count($json['items']) == 0)
break;
foreach ($json['items'] as $item)
{
if (!isset($item['title']))
$item['title'] = '(title unknown)';
if (ignoreItem($item))
continue;
saveItem($item['id'], $item['title'], $item['origin']['title'],
$item['crawlTimeMsec']);
}
if (isset($json['continuation']))
$c = 'c=' . $json['continuation'] . '&';
else
break;
}
else
{
sendMail();
exit;
}
}
$last_fetch = $nt;
if ($last_fetch < time() - 60 * 60 * 24)
saveConfig('last_fetch', $last_fetch);
else
break;
}
function sendMail()
{
global $app_url, $email;
echo mail($email, 'Google Reader need to be authorized.',
"Please visit <a href='$app_url/mr-item.php'>here</a>");
die("send mail...\n");
}
function saveItem($id, $title, $src, $time)
{
global $db;
$id = $db->quote($id);
$stmt = $db->query("select * from item where id=$id");
if ($stmt === false)
die($db->errorInfo());
elseif ($stmt->fetch(PDO::FETCH_NUM) === false)
{
$title = $db->quote($title);
$src = $db->quote($src);
$db->exec("insert into item (id, title, src, time) values ($id, $title, $src, $time)");
}
}
?>
<meta http-equiv="Refresh" content="0; url=mr-item.php" />