Skip to content

Instantly share code, notes, and snippets.

@doersino
Last active August 29, 2015 14:06
Show Gist options
  • Save doersino/23743cb4763a8b8dc02f to your computer and use it in GitHub Desktop.
Save doersino/23743cb4763a8b8dc02f to your computer and use it in GitHub Desktop.
Quick-and-dirty script for getting the source of articles added to a local install of ReAD before this commit: https://github.com/doersino/ReAD/commit/80f08d303f0b2cad7c9263b82ad59794c46208a9
<!-- gets source of your previously ReAD articles
before executing this file, update your database according to the
import.sql file (i.e. add a column "source" of type MEDIUMTEXT to the
"read" table) -->
<meta charset="UTF-8"><body style="overflow-x: scroll;"><pre><?php
error_reporting(E_ALL);
ini_set('max_execution_time', 30);
ini_set("user_agent", "Mozilla/5.0 (compatible; ReAD/1.0; +https://github.com/doersino/ReAD)");
require_once "lib/meekrodb.2.3.class.php";
require_once "Helper.class.php";
if (!isset($_GET["offset"]))
die('no offset, <a href="?offset=0&limit=10">go to first page</a>');
if (!isset($_GET["limit"]))
die('no limit, <a href="?offset=0&limit=10">go to first page</a>');
$offset = intval($_GET["offset"]);
$limit = intval($_GET["limit"]);
$query = DB::query("SELECT `id`, `url`, `title` FROM `read` ORDER BY `time` DESC LIMIT %i OFFSET %i", $limit, $offset);
$i = 0;
for (; $i < count($query); ++$i) {
$url = $query[$i]["url"];
$id = $query[$i]["id"];
if (strpos($url, "fuckjetpacks.com/read/")) // fuck fuck jetpacks
$source = false;
else
$source = Helper::getSource($url);
if (empty($source))
$source = "";
DB::query("UPDATE `read` SET `source` = %s WHERE `id` = %i", $source, $id);
echo "<em>" . ($i + $offset) . "</em>\t" . $id . "\t<strong>" . strlen($source) . "</strong>\t\t<a href=\"" . htmlspecialchars($url, ENT_QUOTES, "UTF-8") . "\">" . htmlspecialchars($url, ENT_QUOTES, "UTF-8") . "</a> [" . trim(str_replace("\n", "", $query[$i]["title"])) . "]\n";
}
?>
done <em><?php echo $offset . "</em>-<em>" . ($i + $offset - 1); ?></em> of <em><?php echo DB::queryFirstField("SELECT COUNT(*) AS 'count' FROM `read`") - 1; ?></em>
<form action="update.php" method="get">next <input type="hidden" name="offset" value="<?php echo $offset + $limit; ?>"><input type="text" name="limit" value="<?php echo $limit; ?>" autofocus="autofocus"><input type="submit" value="go"></form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment