(function()
{
    "use strict";

    // tweet & delete oldest file
    // download it from s3 & delete it

    var s3 = require('./s3client');

    var R = require('ramda');

    var twit = require('./tweet-media');

    var msg = '#fractal #functal #digitalart';

    // var isDev = (process.env.TERM_PROGRAM === 'Apple_Terminal');

    var bucket = 'functal-images';
    var bucketJson = 'functal-json';

    s3.list('functal-images').then(function(result)
    {
        // console.log(result);

        if (result.count === 0)
        {
            console.log('No files');
        }
        else
        {
            var oldestKey = result.files[0].Key;

            console.log(oldestKey);

            var tmpFile = '/tmp/tweet-' + oldestKey;

            s3.download(bucket, oldestKey, tmpFile).then(function()
            {
                console.log('tweeting');

                twit.tweet(msg, tmpFile, function()
                {
                console.log('tweeted');

                    s3.delete(bucket, oldestKey)
                        .then(function()
                        {
                            return s3.delete(bucketJson, oldestKey.replace(/png$/, 'json'));
                        })
                        .done();
                });
            });
        }
    });
}());

@@ -108,18 +108,19 @@
     var 
-s3
+fsq
  = requi
@@ -129,29 +129,23 @@
 ('./
-s3client
+fsq
 ');%0A
-%0A
     var 
 R = 
@@ -140,17 +140,18 @@
     var 
-R
+s3
  = requi
@@ -158,18 +158,22 @@
 re('
-ramda
+./s3client
 ');%0A
-%0A
     
@@ -262,77 +262,8 @@
 ';%0A%0A
-    // var isDev = (process.env.TERM_PROGRAM === 'Apple_Terminal');%0A%0A
     
@@ -393,41 +393,8 @@
   %7B%0A
-        // console.log(result);%0A%0A
     
@@ -555,45 +555,8 @@
 y;%0A%0A
-            console.log(oldestKey);%0A%0A
     
@@ -691,50 +691,8 @@
   %7B%0A
-                console.log('tweeting');%0A%0A
     
@@ -777,32 +777,27 @@
     
-console.log('tweeted');%0A
+    // delete image
 %0A   
@@ -901,32 +901,75 @@
               %7B%0A
+                            // delete json%0A
                 
@@ -1072,16 +1072,215 @@
      %7D)%0A
+                        .then(function()%0A                        %7B%0A                            // delete local file%0A                            return fsq.unlink(tmpFile);%0A                        %7D)%0A
         

delete local file after tweeting