Skip to content

Commit 479f818

Browse files
committed
Store all links to all related questions in file
1 parent 1b02f0e commit 479f818

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/ExportStackExchangeHelper.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,28 @@ public function saveJsonFromApi($endpoint, $site, $sort) {
143143
], 60);
144144
//Log::debug($responseJson);
145145
$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));
147146
$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+
}
148168
} while ($responseArray['has_more']); //https://api.stackexchange.com/docs/paging
149169
}
150170

@@ -179,6 +199,17 @@ public function saveToStorage($filename, $data) {
179199
}
180200
}
181201

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+
182213
/**
183214
*
184215
* @param string $siteName

0 commit comments

Comments
 (0)