From 7bd0049e355492e85339c9efa88bf6f54e392110 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 18 Mar 2012 20:55:28 +0000 Subject: o Adding a utility script to read an atom feed and enqueue each entry. --- atom.php | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 atom.php diff --git a/atom.php b/atom.php new file mode 100644 index 0000000..dd93725 --- /dev/null +++ b/atom.php @@ -0,0 +1,106 @@ +message, "\n"; + } + exit(1); +} + +foreach($sxe->entry as $entry) { + $id = $entry->id; + $title = $entry->title; + $published = $entry->published; + $updated = $entry->updated; + + if($updated == NULL) { + $updated = $published; + } + $updated = DateTime::createFromFormat($format, $updated, $timezone); +# echo "updated=" . $updated->format($format) . "\n"; + + if(!isset($id)) { + echo "Invalid atom entry, missing from ."; + continue; + } + + if($updated === FALSE) { + echo "Invalid atom entry, missing/invalid or from ."; + continue; + } + + if($state != NULL && $state >= $updated) { +# echo "old entry: $id\n"; + continue; + } + + echo "New entry: $id\n"; + + if($newest == NULL || $newest < $updated) { + $newest = $updated; + } + + $entry_file = tmpfile() or exit("Unable to open temporary file"); + fwrite($entry_file, $entry->asXML()) or exit("Unable to write xml");; + fseek($entry_file, 0); + + $curl = curl_init() or exit("Unable to allocate cURL object"); + curl_setopt($curl, CURLOPT_URL, $queue); +# curl_setopt($curl, CURLOPT_VERBOSE, TRUE); + curl_setopt($curl, CURLOPT_INFILE, $entry_file); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/atom+xml;type=entry", "trygve: kul")); + curl_exec($curl) or exit("Error while executing cURL"); + + // if success, pick out Location headers. + + fclose($entry_file); + curl_close($curl); +} + +if(isset($newest)) { + file_put_contents($state_file, $newest->format($format) . "\n"); +} + +?> -- cgit v1.2.3