Permalink
Browse files

add a script for importing mappings into the DB

  • Loading branch information...
1 parent 023788c commit a8a46bd76d329d65d778c5de09d50dbc2854165c @cygri committed May 6, 2011
Showing with 27 additions and 1 deletion.
  1. +2 −1 lib/namespaces.class.php
  2. +25 −0 scripts/import.php
View
@@ -160,7 +160,8 @@ function add_declaration($prefix, $uri) {
if (!$this->is_valid_namespace_URI($uri)) {
throw new Exception("not a valid namespace URI: '$uri'");
}
- $sql = sprintf("INSERT INTO prefixcc_namespaces (prefix, uri, date, ip, upvotes, downvotes) VALUES ('%s', '%s', NOW(), '%s', 5, 0)", $this->escape($prefix), $this->escape($uri), $this->escape($_SERVER['REMOTE_ADDR']));
+ $ip = empty($_SERVER['REMOTE_ADDR']) ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];
+ $sql = sprintf("INSERT INTO prefixcc_namespaces (prefix, uri, date, ip, upvotes, downvotes) VALUES ('%s', '%s', NOW(), '%s', 5, 0)", $this->escape($prefix), $this->escape($uri), $this->escape($ip));
$this->execute($sql);
}
View
@@ -0,0 +1,25 @@
+<?php
+
+if ($argc != 2) {
+ echo "Usage: php scripts/import.php hostname\n";
+ echo " where 'hostname' is the site to import from (usually 'prefix.cc')\n";
+ die(1);
+}
+
+$host = $argv[1];
+
+$lines = file("http://$host/popular/all.file.txt");
+
+include "config.php";
+require_once('lib/namespaces.class.php');
+$namespaces = new Namespaces($config);
+
+$count = 0;
+foreach ($lines as $line) {
+ if (substr($line, 0, 1) == '#') continue;
+ list($prefix, $uri) = explode("\t", trim($line));
+ $namespaces->add_declaration($prefix, $uri);
+ $count++;
+}
+
+echo "Imported $count prefix mappings from $host\n";

0 comments on commit a8a46bd

Please sign in to comment.