⌈⌋ branch:  freshcode


Artifact Content

Artifact cfc975a2f1c612ffd7745a3ba6cc6de2d9273b68:

  • File cron.daily/xfer.php — part of check-in [2f4cf1ea0f] at 2014-11-16 16:19:36 on branch mirror — Xfer cron.job for freshcode.clb JSON feed importing. (user: mario size: 1434)

<?php
/**
 * api: cli
 * title: XFER import
 * description: fetches central feed (freshcode.club), and imports new entries
 * version: 0.0
 * type: cron
 * x-cron: 0,6,12,18 * * * *
 * category: import
 * 
 * 
 * Fetches `http://freshcode.club/feed/xfer.json` for importing new entries.
 * Will forgo minor edits / t_changed entries, but import all new projects and
 * releases.
 *
 */


chdir(dirname(__DIR__));
include("./config.php");

// retrieve
$API = "http://freshcode.club/feed/xfer.json?num=100";
$json = curl($API)->exec();
$json = json_decode($json, TRUE);

// import
foreach ($json["releases"] as $r) {

    // if name+version combo unknown
    if (!release::exists($r["name"], $r["version"])) {

        // fetch any previous data
        $push = new release($r["name"]);

        // most fields come in reusable,
        // some need updating:
        array_walk($r["urls"], function(&$v, $k) { $v = "$k = $v"; });
        $r["urls"] = join("\n", $r["urls"]);

        // update DB fields
        $push->update(
            // newdata
            $r,
            // prefill
            [],
            // override flags
            [
               "hidden" => intval($r["hidden"]),
               "t_published" => strtotime($r["published"]),
               "t_changed" => strtotime($r["changed"]),
            ],
            //
            $_partial = FALSE
        );

        $push->store();
print_r($push);
    }
}