⌈⌋ ⎇ branch:  freshcode


Check-in [5fd866ffb3]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Reuse API I-O to fetch social bookmarking counts.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5fd866ffb3cd9fc0e0bd185dffd3e2008283dce1
User & Date: mario 2014-07-10 01:49:10
Context
2014-07-11
01:26
Workaround [END] for Apache 2.2 check-in: c6f6993121 user: mario tags: trunk
2014-07-10
01:49
Reuse API I-O to fetch social bookmarking counts. check-in: 5fd866ffb3 user: mario tags: trunk
01:48
Minor presentational fixes. check-in: 37295db074 user: mario tags: trunk, 0.4.5
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added cron.daily/social_links.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
<?php
/**
 * api: freshcode
 * title: Social links count
 * description: Queries api.i-o/links for project homepages
 * version: 0.1
 *
 * Retrieve social media sharing site links for project homepages.
 * Stores them in `release`.`social_links`
 *
 * Only updates latest DB entry, so a versioned history of link counts
 * will be retained. (Not that it's needed, ...)
 *
 */

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

// use "remotely" for implicit caching
define("IO_LINKS", "http://api.include-once.org/links/social.ajax.php");

// traverse projects
foreach (db("SELECT *, MAX(t_changed) FROM release_versions GROUP BY name ORDER BY t_published DESC") as $project) {

    // homepage
    $url = $project["homepage"];
    
    // request counts
    $counts = curl()
        ->url(IO_LINKS . "?url=$url")
        ->UserAgent("cron.daily/social_links (0.1; http://freshcode.club/)")
        ->exec();
    
    // summarize
    $counts = json_decode($counts, TRUE);
    $counts = array_sum($counts);
    print "$url = $counts\n";
    
    // store
    $project["social_links"] = $counts;
    #$project->store("REPLACE");
    db("UPDATE release SET social_links=? WHERE :&",
        $counts,
        array(
            "name" => $project["name"],
            "t_changed" => $project["t_changed"],
            "t_published" => $project["t_published"],
        )
    );

}