Browse Source

Add export script and exported data

master
Chris Smith 13 years ago
parent
commit
3a5d22cb3f
2 changed files with 31 additions and 0 deletions
  1. BIN
      res/data.sql.bz2
  2. 31
    0
      website/export.php

BIN
res/data.sql.bz2 View File


+ 31
- 0
website/export.php View File

@@ -0,0 +1,31 @@
1
+<?PHP
2
+
3
+ require('auth.php');
4
+ require('common.php');
5
+
6
+?>
7
+<h1>Export</h1>
8
+
9
+<?PHP
10
+
11
+ $sql = 'SELECT log_headers, log_data FROM sensorlogger';
12
+ $res = mysql_query($sql);
13
+
14
+ $fh = fopen('compress.bzip2://' . dirname(dirname(__FILE__)) . '/res/data.sql.bz2', 'w'); 
15
+
16
+ $users = array();
17
+
18
+ while ($row = mysql_fetch_assoc($res)) {
19
+  preg_match('/IMEI: (.*?)$/m', $row['log_headers'], $m);
20
+  if (!isset($users[$m[1]])) {
21
+   $users[$m[1]] = count($users);
22
+  }
23
+  $row['log_headers'] = str_replace($m[0], 'USER: ' . $users[$m[1]], $row['log_headers']);
24
+
25
+  fputs($fh, "INSERT INTO sensorlogger (log_headers, log_data) VALUES ('" . mysql_real_escape_string($row['log_headers']) . "', '" . mysql_real_escape_string($row['log_data']) . "')\n");
26
+ }
27
+
28
+ fclose($fh);
29
+
30
+ echo 'Wrote ', filesize(dirname(dirname(__FILE__)) . '/res/data.sql.bz2'), ' Bytes.';
31
+?>

Loading…
Cancel
Save