forked from lupaelma/jenti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JentiCrawlerPage.php
130 lines (101 loc) · 2.96 KB
/
JentiCrawlerPage.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
<?php
// Copyright 2006-2015 - NINETY-DEGREES
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"/>
<link REL="STYLESHEET" TYPE="text/css" HREF="nd_style.css"/>
<title>JENTI CRAWL</title>
<script language="JavaScript" type="text/javascript">
function scroll_log()
{ log.scrollTop = log.scrollHeight;
}
function log_write( text)
{
var newDiv = document.createElement( "div");
newDiv.innerHTML = '<font class="SmallText">' + text + '</font>';
log.appendChild( newDiv);
log.scrollTop = log.scrollHeight;
}
</script>
</head>
<body class="StandardBody">
<p class="PageTitle">Jenti Crawler</p>
<DIV id="log" style="background:#FFFFFF; width:1000px; height: 400px; overflow:auto; white-space: nowrap">
</DIV>
<?php
require_once "JentiConfig.php";
require_once "JentiRequestWiktionary.php";
require_once "JentiWord.php";
//////////////////////////////////////////////////////////////////////////
// logging functions
//////////////////////////////////////////////////////////////////////////
function log_open()
{
global $config;
$log = fopen($config["log_file"], "w");
return $log;
}
function log_writeln($log, $txt)
{
fwrite($log, str_replace(PHP_EOL, " ", $txt) . PHP_EOL);
}
function log_close($log)
{
fclose($log);
}
//////////////////////////////////////////////////////////////////////////
// output string to scrolling log
//////////////////////////////////////////////////////////////////////////
function echo_msg_flush( $msg)
{
echo '<script language="JavaScript" type="text/javascript">'
. 'log_write( \''. str_replace( array( '\'', "\n", "\r")
, array( '"', "", "")
, $msg) .'\');'
. '</script>';
for($k=0; $k<50000; $k++)
{ echo ' ';
}
echo PHP_EOL;
}
// Turn off output buffering
ini_set('default_socket_timeout', 36000);
ini_set('max_execution_time', 36000);
$words = explode(PHP_EOL, "guerra
combattere
sanguinoso");
$request = new JentiRequestWiktionary($config);
$jenti_word = new JentiWord($config);
ob_implicit_flush( TRUE);
$log = log_open();
foreach ($words as $word)
{
$word_array = $request->get_word($word);
if ($request->error)
{
echo_msg_flush($request->error);
log_writeln($log, $request->error);
continue;
}
foreach($word_array as $word_info)
{
$jenti_word->add_word_and_definitions($word_info);
if (!$jenti_word->error)
{
echo_msg_flush(print_r($word_info, true));
log_writeln($log, print_r($word_info, true));
}
if ($jenti_word->error)
{
echo_msg_flush($jenti_word->error);
log_writeln($log, $jenti_word->error);
}
}
}
log_close($log);
ob_implicit_flush( FALSE);
?>
</body>
</html>