diff --git a/helpers.class.php b/helpers.class.php
index b7e9f7e..d7d257d 100644
--- a/helpers.class.php
+++ b/helpers.class.php
@@ -46,4 +46,9 @@ function getClient()
}
+function debug($message)
+{
+ if (DEBUG==1) echo $message,'
'; flush();
+}
+
?>
\ No newline at end of file
diff --git a/scrape.php b/scrape.php
index 1966932..b657276 100644
--- a/scrape.php
+++ b/scrape.php
@@ -5,6 +5,7 @@
find('.table-list li',2)->getElementByTagName('span')->plaintext);
$projects[$i]["proponent"]=trim($htmlchild->find('.table-list li',3)->getElementByTagName('span')->plaintext);
$projects[$i]["proponentidnumber"]=trim($htmlchild->find('.table-list li',4)->getElementByTagName('span')->plaintext);
+ debug($projects[$i]["name"]);
// if screenshot API key exists, make lots of additional effort
if ($config["screenshot-apikey"])
{
@@ -85,6 +87,7 @@
if (strpos($text,'Oznámenie o predložení zámeru:')!==FALSE)
{
$infofile=$text->parent->parent->find('li',0)->find('a',0)->href;
+ debug('zamer');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, 'https://www.enviroportal.sk'.$infofile);
@@ -93,6 +96,7 @@
curl_setopt($ch, CURLOPT_NOBODY, 1);
$content=curl_exec ($ch);
$contenttype=curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
+ debug($contenttype.' detected ');
if ($contenttype=='application/rtf')
{
$rtfcontent=file_get_contents('https://www.enviroportal.sk'.$infofile);
@@ -114,6 +118,7 @@
// basic info RTF exists, extract exact location and pull a screenshot
if ($rtfcontent)
{
+ debug('in rtf');
$content=rtf2text($rtfcontent);
$content=str_replace('?','',$content);
$content=preg_replace_callback("/([0-9]+;)/", function($m) { return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); }, $content);
@@ -176,6 +181,7 @@
}
}
}
+ debug($location);
/*
if (!$long AND !$lat) echo('location not identified');
echo $location;
@@ -206,6 +212,8 @@
$mail->Body="";
$existingprojectstate=0;
+debug('processing finished; starting mailing');
+
foreach($projects as $project)
{
$mail->Subject = $config["subject"];
@@ -214,6 +222,7 @@
// arbitraty set number of existing (3) projects between already found project in the same state
if ($hashkey AND $hashkeysetValue('ico',$project["proponentidnumber"]);
$filename=uniqid().".docx";
$templateProcessor->saveAs($config["tempdir"].$filename);
- echo 'File generated';
+ debug('generating document');
}
if ($config["gdrive-clientid"] AND !$existingprojectstate)
{
@@ -295,22 +305,28 @@
}
}
$mail->Body.="\nEdit: https://docs.google.com/document/d/".$createdfileid."/edit\n";
- echo ', uploaded to GDrive';
+ debug('uploaded to GDrive');
}
if ($config["template"] AND !$existingprojectstate)
{
unlink($config["tempdir"].$filename);
}
- if ($mail->send())
+ try
+ {
+ if ($mail->send())
+ {
+ debug('email '.$mail->Subject.' has been sent');
+ }
+ }
+ catch (phpmailerException $e)
{
- echo ', email '.$mail->Subject.' has been sent';
+ debug('error sending mail: '.$e->errorMessage());
}
if ($config["screenshot-apikey"] AND isset($project["long"]) AND isset($project["lat"]))
{
unlink($config["tempdir"].$filename);
}
$mail->clearAttachments();
- echo '
';
}
}