forked from foodcoop-rostock/html-to-sharedlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
77 lines (65 loc) · 1.91 KB
/
index.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
<?php
date_default_timezone_set('Europe/Berlin');
setlocale(LC_ALL, 'de');
require_once("env.php");
require_once("fetch.php");
require_once("parse.php");
require_once("format_bnn.php");
require_once("format_csv.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML2Sharedlists</title>
<style type="text/css">input { font-size: 500%; }</style>
</head>
<body>
<form method="post">
<fieldset>
<input type="hidden" name="refresh" value="refresh" />
<input type="submit" value="Refresh" onclick="this.disabled = true; this.value='Refreshing...';" />
</fieldset>
</form>
<?php
if(isset($_POST['refresh']) || isset($_GET['always_refresh'])) {
echo '<pre>';
$missing_producer_keys = [];
$article_write_counts = [];
foreach($kind_sources as $kind => $sources) {
$articles = array();
foreach($sources as $src) {
// fetch
$html = fetch_html($src);
// parse
$articles = array_merge(
$articles,
parse_articles($html)
);
}
// format
$csv = format_csv($articles);
file_put_contents('out/' . $kind . '.csv', $csv);
// format
$bnn = format_bnn($articles);
$bnn = mb_convert_encoding($bnn, 'CP850', 'UTF-8');
file_put_contents('out/PL' . $kind . '.BNN', $bnn);
$article_write_counts[$kind] = count($articles);
if(count($missing_producer_keys) > 0) {
echo "WARNING: possibly missing producer keys.<br />\n";
var_dump($missing_producer_keys);
echo "<br />\n";
$missing_producer_keys = [];
}
}
echo '</pre>';
echo '<h1>Refresh succeeded for:</h1>';
echo '<dl>';
foreach($article_write_counts as $kind => $count) {
echo "<dt>$kind</dt><dd>$count articles</dd>";
}
echo '</dl>';
}
?>
</body>
</html>