-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_pvalley.php
executable file
·49 lines (39 loc) · 1.04 KB
/
get_pvalley.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
<?php
/**
* Gets the tweets from the mongo DB and return jsons
*/
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
require_once 'mongo_connect.php';
// just toggle debug
$debug = false;
if(isset($_GET["debug"])){
$debug = true;
}
//$collection = $db->tweets;
$collection = $db->pvalley;
$rangeQuery = array();
$limit = 10;
if(isset($_GET["from"]) && $_GET["from"] !=0){
$rangeQuery=array("id_str" => array('$gt'=>$_GET["from"]));
$limit = 20;
}
$cursor = $collection->find($rangeQuery);
//$cursor = $collection->find();
$cursor = $cursor->limit($limit);
//order by id desc
$cursor->sort(array("id_str"=>-1));
//after_id?
// iterate through the results
echo json_encode(iterator_to_array($cursor));
if(false && $debug){
print_r(iterator_to_array($cursor));
/*
foreach ($cursor as $obj) {
echo $obj["user"]["screen_name"].": ".$obj["text"]." - ".$obj["created_at"]."<br>";
//print_r($obj);
}
*
*/
}