-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate.php
executable file
·161 lines (143 loc) · 5.91 KB
/
populate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
require_once("mysql.php");
mysql_select_db("ainews") or die ("Unable to select db: " . mysql_error());
foreach (array("all_1st_accession_20111209.json", "all_2nd_accession_20111209.json") as $jsonfile) {
print "$jsonfile ...\n";
$fp = fopen($jsonfile,'r');
$count = 0;
while (($line_of_json = fgets($fp)) !== false) {
print $line_of_json;
$arr = json_decode($line_of_json);
//var_dump($arr);
$druid_str = $arr->druid;
if ( ! (preg_match("/[a-z]{2}\d{3}[a-z]{2}\d{4}/", $druid_str, $matches) ) ) {
var_dump($matches);
print "No druid found in [$druid_str]. Skipping...\n";
continue;
} else {
$druid = $matches[0];
}
$url = "texts/${druid}.txt";
// Store notes if any
$notes = '';
if ($arr->notes and $arr->notes != '' ) {
$notes = "NOTE:\n" . implode("\nNOTE:\n",$arr->notes);
$safe_notes=mysql_real_escape_string("$notes");
$q = "update urllist set notes = '$safe_notes' where url = '$url'";
//print "$q\n";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found title
if ($arr->title) {
$title=$arr->title;
$safe_title=mysql_real_escape_string($title);
$q = "update urllist set title = '$safe_title' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found tags
$tags = '';
if ($arr->tags) {
$tags = implode(", ",$arr->tags);
$safe_tags=mysql_real_escape_string($tags);
$q = "update urllist set tags = '$safe_tags' where url = '$url'";
//print "$q\n";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found originator
$originator = '';
if ($arr->originator) {
$originator = implode("; ",$arr->originator);
$safe_originator=mysql_real_escape_string($originator);
$q = "update urllist set originator = '$safe_originator' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found date
if ($arr->date) {
$date=$arr->date;
$safe_date=mysql_real_escape_string($date);
$q = "update urllist set date = '$safe_date' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found document_type
if ($arr->document_type) {
$document_type=$arr->document_type;
$safe_document_type=mysql_real_escape_string($document_type);
$q = "update urllist set document_type = '$safe_document_type' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found document_subtype
if ($arr->document_subtype) {
$document_subtype=$arr->document_subtype;
$safe_document_subtype=mysql_real_escape_string($document_subtype);
$q = "update urllist set document_subtype = '$safe_document_subtype' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found containing_work
if ($arr->containing_work) {
$containing_work=$arr->containing_work;
$safe_containing_work=mysql_real_escape_string($containing_work);
$q = "update urllist set containing_work = '$safe_containing_work' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found corporate_entity
if ($arr->corporate_entity) {
$corporate_entity=$arr->corporate_entity;
$safe_corporate_entity=mysql_real_escape_string($corporate_entity);
$q = "update urllist set corporate_entity = '$safe_corporate_entity' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found number
if ($arr->number) {
$number=$arr->number;
$safe_number=mysql_real_escape_string($number);
$q = "update urllist set number = '$safe_number' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found extent
if ($arr->extent) {
$extent=$arr->extent;
$safe_extent=mysql_real_escape_string($extent);
$q = "update urllist set extent = '$safe_extent' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found language
if ($arr->language) {
$language=$arr->language;
$safe_language=mysql_real_escape_string($language);
$q = "update urllist set language = '$safe_language' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found abstract
if ($arr->abstract) {
$abstract=$arr->abstract;
$safe_abstract=mysql_real_escape_string($abstract);
$q = "update urllist set abstract = '$safe_abstract' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
// Do somthing if we found EAF_hard_drive_file_name
if ($arr->EAF_hard_drive_file_name) {
$EAF_hard_drive_file_name=$arr->EAF_hard_drive_file_name;
$safe_EAF_hard_drive_file_name=mysql_real_escape_string($EAF_hard_drive_file_name);
$q = "update urllist set EAF_hard_drive_file_name = '$safe_EAF_hard_drive_file_name' where url = '$url'";
$result = mysql_query($q);
if (!$result) die ("DB write failed 11: " . mysql_error());
}
$count++;
}
fclose ($fp);
print "\nDone with $jsonfile\n";
print "Processed $count json records\n";
}