James Bachini

First Steps in Automation

One of the great things about this industry is the lifestyle flexibility it offers you. The dream is to setup a campaign or website, let it run itself and live off the money tree you’ve made. In reality it rarely works like this but automation can release hours off your daily routines and go some way to releasing you from the office.

Look at your daily/weekly/monthly jobs and think about how many of them could be completed by a computer.automation

  • Collecting Stats
  • Updating Blogs
  • Collecting Images
  • Updating Databases
  • Cleaning/Wiping Databases
  • Analysing Tracking Stats
  • SEO i.e. link building

There’s a few tools you can use to complete these various tasks, probably the most versatile is Selenium which is an open source browser controler. It’s also one of the most complex softwares I’ve used, especially once you start with Selenium Grid. If you are getting started out you can go along way with just php and curl.

PHP & CURL

Here’s a simple php/curl script which will find out how an offer on Neverblue converted last month using their api:

<?php
if (!function_exists(‘curl_init’)){ die(‘You need to install curl dope!’); }

$key = ‘asdf1234’; // enter your own api key

$url = ‘http://api.neverblue.com/service/aff/v2/rest/?function_name=runReport&output_format=format_xml&key=’.$key.’&rel_date=last_month&columns=clicks,conversions&aggregators=campaign’;

//curl
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_TIMEOUT, 600);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
curl_close($ch);

//formating – an xml formatter would probably do a better job.
$pieces = explode(“LiveLinks”, $result); //Checking the offer livelinks
$pieces2 = explode(‘<cell>’, $pieces[1]);
$clicks = explode(‘</cell>’, $pieces2[1]);
$conversions = explode(‘</cell>’, $pieces2[2]);
$cvr = round(($conversions[0] / $clicks[0]) * 100, 4).’%’;

echo ‘Edates Clicks = ‘.$clicks[0].'<br />’;
echo ‘Edates Conversions = ‘.$conversions[0].'<br />’;
echo ‘Edates Conversion Rate = ‘.$cvr.'<br />’;
?>

You could modify this to do anything with the data. You could add a bit of php code to format and email you a report. You could get data from a range of sources and analyse it together in your own chart with pretty little custom graphs. Instead of working with an api you could be ripping blog posts or databases and updating your own sites automatically.

CRON JOBS

Once you have the script working you are going to want to setup your server to run it for you. If you are using a linux server this is done with cron. There are a million and one ways to setup a cron job but I’ve found the easiest and most reliable (but probably not safest) is to ssh in as root and set them up with crontab -e

So log in and run crotab -e then enter something along the lines of:
2 17 * * * php /var/www/mydomain.com/httpdoc/getstats.php
(This will run at 17:02 every single day.)

Here’s a breakdown:

*    *     *   *    *   command to be executed
|    |     |   |    |
|    |     |   |    +—– day of week (0 – 6) (Sunday=0)
|    |     |   +——- month (1 – 12)
|    |     +——— day of        month (1 – 31)
|    +———– hour (0 – 23)
+————- min (0 – 59)

Examples:
45 7 * * 1-5 php /etc/home/getmecoffee.php       // This will run every weekday morning at 7:45am
0 10 1 * * ruby /etc/home/firstofmonthupdate.rb   // This will run on the 1st of each month at 10:00am


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

by