Permalink
Browse files

Initial checkin/proof of concept.

  • Loading branch information...
cbenard committed Jul 31, 2015
0 parents commit 3dac0bed67b5d4f727273ad78267855ab5319326
Showing with 105 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +20 −0 app.yaml
  3. +4 −0 cron.yaml
  4. BIN favicon.ico
  5. +1 −0 index.html
  6. +11 −0 index.yaml
  7. +2 −0 php.ini
  8. +3 −0 scripts/common.php
  9. +53 −0 scripts/fetch_dilbert.php
  10. +6 −0 scripts/view.php
@@ -0,0 +1,5 @@
# Google App Engine generated folder
appengine-generated/
# Visual Studio Code
.settings/
@@ -0,0 +1,20 @@
application: comicfeeds
version: 1
runtime: php55
api_version: 1
threadsafe: no
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /view/(dilbert|pennyarcade)/(.+)
script: scripts/view.php
- url: /fetch/(dilbert|pennyarcade)/?
script: scripts/fetch_\1.php
- url: /.*
static_files: index.html
upload: index\.html
@@ -0,0 +1,4 @@
cron:
- description: Fetch Dilbert
url: /fetch/dilbert
schedule: every 2 hours
Binary file not shown.
@@ -0,0 +1 @@
Nothing to see here.
@@ -0,0 +1,11 @@
indexes:
# AUTOGENERATED
# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
@@ -0,0 +1,2 @@
google_app_engine.enable_functions = "libxml_disable_entity_loader"
output_buffering = "Off"
@@ -0,0 +1,3 @@
<?php
libxml_disable_entity_loader(false);
@@ -0,0 +1,53 @@
<?php
header("Content-Type: text/plain");
require_once("common.php");
$feed = "http://dilbert.com/feed.rss";
$doc = simplexml_load_file($feed) or die('Unable to load XML');
$count = count($doc->entry);
for ($i = $count - 1; $i >= 0; $i--) {
$entry = $doc->entry[$i];
if (strpos($entry->title, "Comic for ") === FALSE) {
unset($doc->entry[$i]);
}
else {
echo "Processing $entry->title...\n";
$newContents = get_entry_content($entry);
$entry->content = '';
$entry->content['type'] = "html";
$domNode = dom_import_simplexml($entry->content);
$owner = $domNode->ownerDocument;
$domNode->appendChild($owner->createCDATASection($newContents));
echo "\tDone.\n";
}
}
function get_entry_content($entry) {
$url = $entry->link['href'];
echo "\tFetching URL: $url\n";
$contents = file_get_contents($url);
$imageUrl = get_image_url($contents);
$newContents = "<img src=\"$imageUrl\"/>";
return $newContents;
}
function get_image_url($contents) {
$pattern = '/data-image="(.+?)"/';
preg_match($pattern, $contents, $matches);
$imageUrl = $matches[1];
echo "\tFound image URL: $imageUrl\n";
return $imageUrl;
}
$outputXml = $doc->asXml();
print_r($outputXml);
file_put_contents("gs://#default#/feed_dilbert_default", $outputXml);
@@ -0,0 +1,6 @@
<?php
require_once("common.php");
header("Content-Type: application/rss+xml");
echo file_get_contents("gs://#default#/feed_dilbert_default");

0 comments on commit 3dac0be

Please sign in to comment.