Skip to content

Commit

Permalink
Cache media entries (related to #299)
Browse files Browse the repository at this point in the history
  • Loading branch information
dentoir committed Feb 20, 2018
1 parent 748470b commit 6063be3
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion analysis/mod.export_tweets.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
$header .= ",hashtags";
$csv->writeheader(explode(',', $header));

// cache all media data
$media_entities = 0;
if (array_search("media", $exportSettings) !== false) {
$media_data = array();
$sql = "SELECT * FROM " . $esc['mysql']['dataset'] . "_media";
$rec = $dbh->prepare($sql);
$rec->execute();
while ($data = $rec->fetch(PDO::FETCH_ASSOC)) {
if (!array_key_exists($data['tweet_id'], $media_data)) {
$media_data[$data['tweet_id']] = array();
}
$media_data[$data['tweet_id']][] = $data;
$media_entities++;
}
}

// make query
$sql = "SELECT * FROM " . $esc['mysql']['dataset'] . "_tweets t ";
$where = "";
Expand Down Expand Up @@ -85,7 +101,29 @@
$error[] = $res2['error_code'];
}
}
// lookup media from media table

// lookup media from media table which we have cached
if (array_search("media", $exportSettings) !== false) {
if (array_key_exists($id, $media_data)) {
foreach ($media_data[$id] as $res2) {
$urls[] = $res2['url'];
$expanded[] = $res2['url_expanded'];
$followed[] = '';
$domain[] = '';
$error[] = '';
$media_ids[] = $res2['id'];
$media_urls[] = $res2['media_url_https'];
$media_type[] = $res2['media_type'];
$photo_width[] = $res2['photo_size_width'];
$photo_height[] = $res2['photo_size_height'];
$photo_resize[] = $res2['photo_resize'];
$indice_start[] = $res2['indice_start'];
$indice_end[] = $res2['indice_end'];
}
}
}

/*
if (array_search("media", $exportSettings) !== false) {
$sql2 = "SELECT * FROM " . $esc['mysql']['dataset'] . "_media WHERE tweet_id = " . $id;
$rec2 = $dbh->prepare($sql2);
Expand All @@ -106,6 +144,7 @@
$indice_end[] = $res2['indice_end'];
}
}
*/

if (array_search("media", $exportSettings) !== false && array_search("urls", $exportSettings) !== false) {
// full export of urls with media information
Expand Down Expand Up @@ -171,6 +210,7 @@
exit(0);
}
// Rest of script is the HTML page with a link to the cached CSV/TSV file.

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Expand Down

0 comments on commit 6063be3

Please sign in to comment.