blob: 504b39ea14d0c94d1745fda47010957a9c8524bf (
plain) (
blame)
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
|
<?php
function runInBackground($command)
{
$pid = shell_exec("nohup $command > lastRun.log 2>&1 & echo $!");
file_put_contents("pidFile", $pid);
return $pid;
}
function isProcessRunning($pid)
{
exec("ps $pid", $state);
return(count($state) >= 2);
}
$pid = @file_get_contents("pidFile");
$totalLines = @file_get_contents("totalLines");
$running = ($pid !== false && $totalLines !== false && isProcessRunning($pid));
if ($_GET["action"] == "progress") {
if (!$running) {
echo "Complete! Your spreadsheet has been e-mailed to you. (You may also <a href=\"MovieStats.csv\">download it from here</a>.)<br><a href=\"index.php\">Click here</a> to run again.";
exit();
}
$statsFile = @fopen("MovieStats.csv", "r");
if ($statsFile === false) {
echo "Waiting to begin...";
exit();
}
$lines = -1;
while (!@feof($statsFile)) {
@fgets($statsFile);
$lines++;
}
if ($lines <= $totalLines)
echo "Progress: $lines movies out of $totalLines completed.";
else
echo "Finished... sending e-mail.";
exit();
}
if ($running && $_GET["action"] == "terminate") {
exec("kill $pid");
$running = false;
}
if (!$running && $_GET["action"] == "start" && $_POST["forreal"] == "yeah") {
@exec("kill $pid");
file_put_contents("input.txt", $_POST['list']);
file_put_contents("totalLines", (string)count(split("\n", $_POST['list'])));
@unlink("MovieStats.csv");
runInBackground("/home/zx2c4/opt/bin/python MovieSearchStats.py input.txt MovieStats.csv '".$_POST['email']."'");
$running = true;
}
?>
<html>
<head>
<title>AnyClip Movie Statistics Generator</title>
</head>
<body>
<h2>AnyClip Movie Statistics Generator</h2>
<?php if ($running): ?>
<h4>Statistics are currently being generated. They will be e-mailed to you when complete. You may close this window, and statistics will continue to be generated; you may then return to this page at any time to check the progress.</h4>
<h3 id="progress"></h3>
<h5><br><br><br><br><a href="index.php?action=terminate">Click here</a> to terminate current stats job.</h5>
<script language="JavaScript">
var requestObj;
if(navigator.appName == "Microsoft Internet Explorer")
requestObj = new ActiveXObject("Microsoft.XMLHTTP");
else
requestObj = new XMLHttpRequest();
function updateProgress()
{
requestObj.open('GET', "index.php?action=progress");
requestObj.onreadystatechange = function()
{
if (requestObj.readyState == 4) {
document.getElementById("progress").innerHTML = requestObj.responseText;
setTimeout(updateProgress, 1000);
}
}
requestObj.send(null);
}
updateProgress();
</script>
<?php else: ?>
<form action="index.php?action=start" method="POST">
<input type="hidden" name="forreal" value="yeah">
<p><label>E-mail: <input type="text" name="email" value="Chris@anyclip.com"></label></p>
<p><label>Movie list:<br>
<textarea name="list" rows="20" cols="25">
Gone with the Wind
Snow White
Star Wars New Hope
Bambi
Jaws
...fill me up...
</textarea></label></p>
<input type="submit" value="Start">
</form>
<?php endif; ?>
</body>
</html>
|