@@ -143,8 +143,28 @@ public function saveJsonFromApi($endpoint, $site, $sort) {
143
143
], 60 );
144
144
//Log::debug($responseJson);
145
145
$ filename = $ this ->clean ($ site ['site_name ' ]) . '/ ' . $ endpoint . '/page_ ' . str_pad ($ page , 4 , '0 ' , STR_PAD_LEFT ) . '.json ' ;
146
- $ this ->saveToStorage ($ filename , json_decode ($ responseJson , true ));
147
146
$ responseArray = json_decode ($ responseJson , true );
147
+ $ this ->saveToStorage ($ filename , $ responseArray );
148
+ foreach ($ responseArray ['items ' ] as $ item ){
149
+ $ url ='' ;
150
+ if (!isset ($ item ['question_id ' ])){
151
+ if ($ endpoint =="comments " ){
152
+ $ url =$ site ["site_url " ].'/a/ ' .$ item ['post_id ' ];
153
+ #$this->writeToOuput($endpoint.": ".$url);
154
+ } else if ($ endpoint =="mentioned " ){
155
+ # mentions are not needed, cause they are usually replies to own q,a or comments
156
+ # $this->writeToOuput($endpoint.": ".$site["site_url"].'/a/'.$item['post_id']);
157
+ } else {
158
+ #$this->writeToOuput("$endpoint has no question id and no post_id\n"; var_dump($filename));;die
159
+ }
160
+ }else {
161
+ $ url =$ site ["site_url " ].'/questions/ ' .$ item ['question_id ' ];
162
+ # $this->writeToOuput($endpoint.": ".$url);
163
+ }
164
+ if ($ url ){
165
+ $ this ->appendToStorage ("urls.html " , $ url );
166
+ }
167
+ }
148
168
} while ($ responseArray ['has_more ' ]); //https://api.stackexchange.com/docs/paging
149
169
}
150
170
@@ -179,6 +199,17 @@ public function saveToStorage($filename, $data) {
179
199
}
180
200
}
181
201
202
+ /**
203
+ * appends plain data to a file
204
+ * @param string $filename
205
+ * @param string $data
206
+ */
207
+ public function appendToStorage ($ filename , $ data ) {
208
+ $ filename = $ this ->filename_prefix . $ filename ;
209
+ Storage::disk ('local ' )->append ($ filename , $ data );
210
+ #$this->writeToOuput('Added '.$data.' to ' . $filename);
211
+ }
212
+
182
213
/**
183
214
*
184
215
* @param string $siteName
0 commit comments