3 * Table Definition for cash_costing_map
5 require_once 'DB/DataObject.php';
8 class Pman_Reddit_DataObjects_Reddit_livefeed extends DB_DataObject
11 /* the code below is auto generated do not remove the above tag */
13 public $__table = 'reddit_livefeed'; // table name
14 public $id; // int(11) not_null primary_key auto_increment
15 public $body; // string(254) not_null
16 public $uid; // int(11) not_null
17 public $created_dt; // int(11) not_null
18 public $embeds; // int(11) not_null
19 public $body_html; // int(11) not_null
23 /* the code above is auto generated do not remove the tag below */
26 function fetchFrom($from='')
29 $base = "https://www.reddit.com/live/tnc30xhiiqom.json";
30 $after = strlen($from) ? ('after=LiveUpdate_' . $from) : '';
31 $count = strlen($from) ? 'count=75' : '';
32 $url = $base . '?' . implode('&', array($after, $count));
36 $raw = file_get_contents($url);
38 $data = json_decode($raw);
39 if (!count($data->data->children)) {
43 echo date('Y-m-d H:i:s', $data->data->children[0]->data->created) . "\n";
58 embeds: array(url / width / height)
67 foreach($data->data->children as $child) {
70 $ch->body_html = html_entity_decode($ch->body_html);
71 $ch->prev_uid = $last;
72 $ch->created_dt = date('Y-m-d H:i:s', $ch->created);
73 $ch->embeds = json_encode($ch->embeds);
78 $x = DB_DataObject::factory('reddit_livefeed');
79 if ($x->get('uid', $ch['uid'])) {
93 // if we did not add any....??
94 // look for the oldest???
102 $r = json_decode($this->embeds);
103 return $r[0]->height;
107 $r = json_decode($this->embeds);
113 $r = json_decode($this->embeds);
117 function convertEmbed(){
118 $r = json_decode($this->embeds);
119 //DB_DataObject::debugLevel(1);
120 foreach($r as $i=>$em) {
121 //echo $i . "\n\n\n";
122 $x = DB_DataObject::factory('reddit_livefeed_embed');
123 $x->feed_id = $this->id;
128 $x->feed_id = $this->id;
136 function fetchEmbed()
139 $r = json_decode($this->embeds);
141 foreach($r as $i=>$em) {
142 //$file = /home/reddit/ date('Y/m/d', strtotime($this->created_dt . " - 8 HOURS")) . "/" . $this->uid . '.' . $i . ".pdf"
143 if (file_exist)($file) {
146 $dir = dirname($file);
147 if (!file_exist($dir)) {
148 mkdir($dir,660, true);
150 $url = http://redit.......
151 $cmd = "/usr/bin/wkhtmltopdf $url $file";
155 $r = json_decode($this->embeds);
156 foreach($r as $i=>$em) {
158 $file = '/home/reddit/' . date('Y/m/d',strtotime($this->created_dt . " - 8 HOURS")) . "/" . $this->uid . '.' . $i . ".pdf";
159 if(file_exists($file)){
160 echo "file exists already.";
163 $dir = dirname($file);
164 if(!file_exists($dir)){
166 mkdir($dir,0775,true);
168 $url='http://roojs.com/reddit/index.php/Embedly?url=' . $em->url;
170 //escapeshellarg('http://www.redditmedia.com/mediaembed/liveupdate/tnc30xhiiqom/LiveUpdate_' . $this->uid . '/' . $i);
171 //$cmd = "/usr/bin/xvfb-run /usr/local/bin/wkhtmltopdf --javascript-delay 10000 --load-error-handling ignore '" . $url . "' " . $file;
173 $cmd = "seed main.js -u " . $url . " -d 5000 -f " . $file;