Friday, March 20, 2020


Warning: this post contains difficult subject matter.

I've never felt the need to put a warning about the contents of a post before but at the same time my twitter and blog have been pretty successful of flying under the radar, until recently that is. This blog doesn't deal in feel goods, I don't close off every post with some positive bullshit action you can take to make yourself feel better. The intended target of my posts has always been critical thinkers, people that can handle this information and make personal decisions with it. I don't aim to "save the world", hell I can barely save myself. I'm in the same boat as all of you, and in some ways my ability to identify problematic patterns in the system is a curse. I hate seeing them. I don't like writing, I don't like posting, I don't like tweeting, I'd rather relax and write code and enjoy my life and let those dedicated to the profession of writing handle delivering the bad news.

Not the way life works, unfortunately. The urge to write when I see patterns I feel others are ignoring is extraordinarily strong. If I don't direct my thoughts somewhere it tears my own life apart. I'll pace around my house, ranting to anyone or anything I see. Writing this blog, and recording these observations, helps me personally. Yet I still don't feel good about it. Every time I tweet, every time I post, I question it. I doubt if I should press send, or not. I then spend time reading, and re-reading, and re-reading what I wrote; to ensure the accuracy, to question my assumptions, and ultimately to decide if I should hit delete. The more traffic I attract the longer and harder I think about pressing send.

I'm a huge introvert, I don't like attention of any kind, I hate being in the spotlight. To give you an idea what this means: enacting social distancing in my life for COVID-19 has changed literally nothing, aside from now instead of working from home a few days a month it's every day for the foreseeable future. Otherwise, nothing has changed, my life feels the same. I do the same things, alone, that I always did alone. In the years since I've been an outlier of the Alberta political scene maybe a handful of people have actually met me in person.

For the last 8 years my work has been able to go relatively unnoticed, hitting the targeted folks. I've had a small but steady following of critical thinkers and that has been all I ever intended to reach. I don't aim to be published, I don't aim to do interviews, or provide advice. I deliberately make my work unprintable. There is nothing special about what I do that every other person can't also do (and of which I really wish they would) other than being open minded.

In the time since I restarted my blog for the express purpose of opposing the UCP I've been in awe at which the agenda I had originally identified - first in Alberta's Great Panderer and then in subsequent posts as more information became available and actions observed - has so quickly come into the public view. My forecasts are generally quite accurate, but usually over a time frame of years (unless a specify specifically a time frame) not a few short months. The obvious nature of Kenney's agenda and his hastily sloppy authoritarian approach to ramming his agenda through as quickly as possible regardless how it affects his popularity.

In fact events have now exceeded my forecasts, as now Stephen Harper himself has joined Jason Kenney's new "economic recovery panel".
So now Stephen Harper which as I discuss in Alberta's Great Panderer is, of Harper & Associates that advises corporations and works on their behalf to earn profit and which shares an office with Dentons law firm that is the corrupt sole sourced contract for the "public inquiry" into "foreign funded activists", chairman of the IDU that helps political campaigns win with the use of technology, strategy, and organization, and which had a meeting with investors prior to the UCP's election that was closed to media in which he discussed privately ways he could see the industry regaining ground; this person has a direct public hand in how this province will be handling it's "economic recovery". This is blatant fucking criminality folks. This panel is an absolute fucking scam. Stupid corrupt fuckwad UCP.
"Broad Picture". Yes, Albertans, think of a giant picture of the rich looting Alberta dry and leaving all of their junk assets in it's place, purchased by taxpayers. "It's not crisis work for them - it's broad picture stuff". Yea! You know.. broad picture! fucking dumb peasants, what do ya want... like... details? You're too stupid for anything beyond "broad picture", leave it to the experts like Jack Mintz to know the nitty gritties.

Anyway, as I was saying. Kenney's agenda has come into view at lightning speed. Fuckin' ludicrous speed. He's gone plaid.

Kenney the plaid pandering cun-try-boy
This has resulted in a much larger following and far more attention than I was expecting as while normally my work would take years to pan out this all happened in a few months. It wasn't hard to piece together, you just had to look at the dots and see the world through the proper lens. A lens free of false idols, gods, ideologies. See the system for what the system is: not here for you.

Typically when I used to write, I didn't focus explicitly on battling a government. I analyzed geopolitics, and as far as I was concerned my work was complete. I already talked about everything that I know that is to come and none of it has changed. Nothing has changed. But to understand Kenney's agenda, you need to understand what is driving world events. The rich do not give two flying fucks about you. Neither do those who bootlick for the rich, for those are the ones that want to be the rich.

I have people looking to me for answers now and stuff, and I don't like it. Scares the shit outta me. All of my understanding I owe to Michael C. Ruppert, the guy was a fucking genius. I don't believe in leaders. Stop looking for leaders! These fucking idiots haven't lead shit except a march towards unsustainable infinite growth. This economic panel is to figure out how to keep infinite growth going at your expense.

They want to potentially suspend the carbon tax along with the bailout of the companies and the cleaning of the wells for them; which as I wrote about back in 2014 in my post "A carbon tax is never going to work for the same reason no carbon tax is never going to work" is exactly why carbon taxes or any real attempt to do anything will never work! As soon as infinite growth is threatened all regulations, controls, "red-tape" go out the window. What in the fuck is suspending it going to do anyway? Banks are just printing whatever currency they need to, the taps have been turned on full tilt. None of it means anything, and we can't print our way out of this crisis. But we're sure as fuck gunna try! None of the types of conversations that should be happening regarding this are happening. Instead it's all about "how do we get currency to companies, keep companies operating so they can pay their bills and loans". Etc.

All of this is to keep the infinite growth ponzi-conomy going, none of it has anything to do with making sure you're healthy, you're safe, you're taken care of. They don't care if you can get supplies, they just care that you and the corporations of course have money to pay the loans and to maybe buy some stuff.

Sure, for the moment some loans are on hold, mortgages on hold, all this is temporary while they sort out the liquidity and lockdowns take place. That won't last. Eventually we're coming out the other side of this into the true crisis: the remains of the fake fiat financial system.
Why aren't governments providing guidelines on supplies to survive lockdown or self-isolation? Instead you have them telling people not to "panic buy". Get fucked, don't let these assholes shame you into being unprepared. I'm not saying to go hoard all the toilet paper (how much do these people shit? a single 24 pack lasts me like 2 months) but at this point in time if you're able I'd say you probably want at least a 1-2 month supply of food just in case. Call me an alarmist if you want but it's food; you're gunna eat it in any event. I've also personally stocked up on items like propane for my portable BBQ, and emergency candles/lighters.

This isn't panic buying, it's pre-panic buying. I don't want to be buying during the real panic and I'd suggest you don't either. The real panic hits if supply lines collapse, that's what you need to be prepared for whether it comes or it doesn't because if it does then it's a little too late in'it? Statements like this don't give me much hope on the subject:
Like fucking duh. Yea, I know, food security is not compromised right now. That's why I'm buying my food right now. Don't listen to fuckwad Kenney, don't wait for it to be compromised before you "panic buy". Compromised supply chains aren't planned in advanced, you're not going to get advanced notice.

Do you see the pattern emerging?

You can see it in Trump too that has been downplaying the crisis despite the U.S. having ample warning. Trump is not the entire US government, I see everyone saying this is all because of Trump and his incompetence, much as I see people write Kenney's misdeeds off as incompetence. But the US is a giant apparatus, their response is not "Trump's fault". but it's convenient to blame him as the alternative reality, that the US has chosen not to prepare it's population despite them knowing full well what the results will be, might be pretty scary and upsetting to the bubble of freedumb a lot of folks live in. The US empire is good for you and cares about you and loves you and wants you to pay your loans, remember to repeat your mantra.
The 100-page report was published March 13 by the Department of Health and Human Services. The New York Times was the first to report on the document which was marked "unclassified" and "not for public distribution." 
The government's predictions about the pandemic included the following:
  • "A pandemic will last 18 months or longer and could include multiple waves of illness."
  • "Supply chain and transportation impacts due to ongoing COVID-19 outbreak will likely result in significant shortages for government, private sector, and individual U.S. consumers."
  • "Increasing COVID-19 suspected or confirmed cases in the U.S. will result in increased hospitalizations among at-risk individuals, straining the healthcare system."
These forecasts were part of a section of the report where the government offered several assumptions about the virus to help them craft a response plan.
Let me make this real clear folks: the government is not going to warn you of a pending supply shortage. Let me make something else clear: they are expecting you to revolt. This is as true in the U.S. as it is in Canada. We will not be warned. So if you're thinking: well people will get mad and they don't want that? Yea, they thought about that and that's why they armed all the police with military hardware and have been training them for 2 decades all around the world now to deal with the inevitable revolt of the collapse of the fiat infinite growth ponzi-conomy. Don't believe me? You don't think our police forces are ready to treat you like shit? Go watch Press for Truth's "Into The Fire".

This cute little training exercise wasn't just for fun.

I now very strongly believe that the economic fall out from the Russia/Saudi price war and COVID-19 will absolutely be used to cover for the final collapse of the US banking sector and the move away from the US dollar as a reserve currency as I described in the last post. An unprepared panicky public definitely doesn't hurt that process, does it? The more excuses the better, anything excuses, other than the truth: that the banking system is fraudulent, the derivative bubble never went away, and the reason for the 10 year "bull market" was entirely due to central banks. We never recovered from 2008, so no matter how much they print now, how much they loan, how low interest rates go, they can never do more than they already did to counter the last bubble, and now this bubble is collapsing due to a real global crisis, not just a severe problem like conventional peak oil.

We're at a crossroads now, globally. It's an opportunity and either the people, or the elite will be the ones to seize it. Whatever the world and economic system, and the winners and losers, look like coming out on the other side will be decided by those that seize the opportunity in front of us to advance change. The economic system has been exposed as naked, incapable of handling a real problem, don't fall in to the trap of asking for money. Now is the time to start talking about priorities, how things need to be organized, and lessons learned. Don't talk about cheques, talk about food. Don't talk about rent, talk about housing. If we don't I assure you those losing control of the system will and whatever they have in mind will be shitty for you, and me.

Regarding the price war the U.S. hilariously said it would "intervene". They'll try to put some diplomatic shit up Saudi's ass (won't work) and have said they will resort to sanctions against Russia. Yes, that's right, sanctions. Sanctions, an act of war, to raise oil prices. The US is at war and it's their currency under attack. Understand this. In response Putin basically said: fuck you. So that's that, Alberta better get comfortable - especially since the Canadian Energy Centre still hasn't written them a stern letter of it's own. What a stupid fucking "war room" eh? Can't even "war".

Click here to recommend this post on and help other people find this information.

Richard Fantin is a self-taught software developer who has mostly throughout his career focused on financial applications and high frequency trading. He currently works for CenturyLink

Nazayh Zanidean is a Project Coordinator for a mid-sized construction contractor in Calgary, Alberta. He enjoys writing as a hobby on topics that include foreign policy, international human rights, security and systemic media bias.

Monday, March 9, 2020

Russia moves for N.A. production and banking death blow while Kenney's agenda disintegrates over-night

The fuckwad UCP's social license and benefit of the doubt to do as they please to implement the Kenney agenda just expired. Kenney it would appear is out of time to get the rich off the hook and I suspect the next week is going to be an incoherent mess of announcements as he bides time figuring out what to do regarding the reinvigorated price war.

The Kenney propaganda machine is slow to adjust, a weakness of such a rigid and corrupt regime. As oil prices collapsed Sunday night Kenney was tweeting promotional pictures of himself and the young (and ironically, indoctrinating), probably now futureless, "Student Petroleum Society".
Congrats kiddos!

Six years ago when the Saudi's initiated their price war I wrote a post describing where I saw it going. In it I predicted that so long as the Saudis believed their plan was working oil would sit around a $60 price point. This prediction has turned out with OPEC+ in the last 6 years maintaining production levels to keep the price roughly around $60. I also predicted that as a result of sunk costs and mounting debt North American production would have no choice but to turn on the taps and levy expensive research.

What most analysts got wrong at the time (and still get wrong) is that while the war is taking place in the oil industry the real target was the U.S. banking sector. I've long been tracking the demise of the U.S. dollar and I've long believed Saudi Arabia has been slowly moving out of the shadow of the U.S. empire and into the shadow of the new rising economic alliance between Russia and China. An alliance which has routinely called for the USD to be replaced as the world reserve currency.

In recent years calls to drop the dollar have reached the main stream, with even Mark Carney calling last year for it to be replaced with an electronic blockchain currency. Shortly afterwards the Bank of Canada announced it was "exploring" a digital currency that would replace cash. They updated Canadians a few weeks ago announcing they were now moving to "lay the groundwork" for such a currency.
The Bank of Canada doesn’t see a compelling case for introducing a digital currency at the present time, but is getting ready to move quickly, should the need for one become more evident, Deputy Governor Tim Lane said. 
While Canadians are well-served by the present payment system, the central bank has begun to look at potential features and requirements of a digital currency, Lane said, according to the text of remarks to be delivered Tuesday in Montreal. The central bank is now actively developing a prototype digital currency, according to a background document. 
“We need to move forward to work out what a potential CBDC might look like and how it could be managed, if the decision were ever taken to issue one.” Lane said regarding preparations for a potential central bank digital currency in Canada. 
Central banks around the world are trying to get to grips with emerging payment technologies. Private-sector initiatives such as Facebook Inc.’s Libra are adding urgency to the debate over how digital currencies should be handled. 
The Bank for International Settlements and the International Monetary Fund have called for central banks to at least study the possibility of as private sector firms experiment with competing units of exchange.
If you're not aware, the BIS is basically the central bank of central banks, and is effectively the command and control system for the infinite growth ponzi-conomy. Of course the IMF need no explanation.

The article continues...
The Bank sees two main scenarios where the central bank could see the need to issue its own digital currency: firstly, if the use of cash is restricted or eliminated, and second, if private cryptocurrencies were to make serious inroads.
The second reason, is being used to justify the first.

I can assure you, as a software engineer and given the long documented history of slow moves away from the US dollar, if the Bank of Canada is actively putting man hours into developing this "alternative currency" then they intend to implement it. This is thousands of man hours were talking. This is being coordinated with the BIS and IMF who coordinate with Russia, Saudi Arabia, and China. All of their central banks operate under the BIS system, too.

The last six years of ~$60 WTI price has acted like a slow drain on the financials of North American oil companies, but it's also been a drain on the banks. There is a critical piece of information missing from western analysis of the recent Russia/OPEC spat. All of the western focus is on Saudi's response to Russia, no focus is being put however on why Russia split from the OPEC Pact in the first place: to target North American production. Thankfully Zero Hedge caught it.

Putin Dumps MBS to Start a War on America’s Shale Oil Industry
But the OPEC+ deal also aided America’s shale industry and Russia was increasingly angry with the Trump administration’s willingness to employ energy as a political and economic tool. It was especially irked by the U.S.’s use of sanctions to prevent the completion of a pipeline linking Siberia’s gas fields with Germany, known as Nord Stream 2. The White House has also targeted the Venezuelan business of Russia’s state-oil producer Rosneft.“The Kremlin has decided to sacrifice OPEC+ to stop U.S. shale producers and punish the U.S. for messing with Nord Stream 2,” said Alexander Dynkin, president of the Institute of World Economy and International Relations in Moscow, a state-run think tank. “Of course, to upset Saudi Arabia could be a risky thing, but this is Russia’s strategy at the moment – flexible geometry of interests.”
OPEC's response to drop prices pretty well simply obliges the Russian plan. This all comes as the liquidity crisis in the US banking sector has continued to worsen, making this - in combination with the economic effects of COVID-19 - a perfect opportunity to strike the death blow to US finance and production. And by extension.. Alberta's too.

Kenney is not prepared what-so-ever for these events, the UCP said just a few days ago they will be announcing "strategic investments" this month.

I believe these "strategic investments" was part of Kenney's agenda to transfer the remaining risk in the province to taxpayers. This is going to be a lot harder of a sell to the population of Alberta now, as will maintaining the war room, or the army of propagandists. Effectively Kenney's entire edifice built on the propaganda of a province under attack will now disintegrate as Albertans begin to realize what a real "attack" on our oil industry looks like, and how ineffective Kenney's fake "war" really is against such an attack.

Think Russia will listen?

Click here to recommend this post on and help other people find this information.

Richard Fantin is a self-taught software developer who has mostly throughout his career focused on financial applications and high frequency trading. He currently works for CenturyLink

Nazayh Zanidean is a Project Coordinator for a mid-sized construction contractor in Calgary, Alberta. He enjoys writing as a hobby on topics that include foreign policy, international human rights, security and systemic media bias.

Tuesday, March 3, 2020

Learn To Code Political Edition: Building @WBrettWellson Bot

A few weeks ago Duncan Kinney of Press Progress asked (possibly half jokingly?) if anyone can build a bot to pester Brett Wilson about his abandoned wells.

Naturally I thought this is a great idea, and a simple example of political programming I was talking about in the Learn to Code rational. It took me about 4 hours in total to come up with an initial version. Couple more hours to run it through some simple tests and fix bugs. It's now online on Twitter @WBrettWellson.

In this post I'm going to walk you through the source code of this simple bot so you can possibly replicate or expand upon it. You can in theory use this source to setup your own bot to pester Brett Wilson about his abandoned wells.

Also, if you have ideas for tweet templates for me to use with the bot comment them below.

A few years ago I was playing with the Twitter API, I built two bots. One spat out Ghostbusters Quotes. Just for fun and because it's got some good one liners. The other was used when I was tracking lots of news as I could use hash tags when i tweeted important links to have my bot automatically pick them up and store them in a database I could then reference later. Neither is operational anymore but I still had the source code. Seemed like a good base.

Both bots are written in PHP, one used the real time twitter api and one did it based on a scheduler. I opted for the scheduler approach with WBrettWellson bot. So on the system running the bot there is a cron job (cron is the scheduler on Linux) that fires off the bot script every 3 minutes. Logic inside the script further randomizes when the script sends a tweet and what the contents are.

It's nothing fancy just uses some keyword matching to vary the tweets, and randomization to offset the scheduler. I also put it together pretty quickly, so the code isn't designed to be very organized or reusable, just a quick proof of concept.

The bot source code can be downloaded here. I've removed the application key, user tokens, and the majority of the tweets from the downloaded source (you'll have to fill them in with your own). I also rely on Abraham's Twitter PHP library to interact with the REST API Twitter uses.

The bot consists of two main source files, and we will go through them so you can understand how it works.

File: /Twitter.php
  require_once "twitteroauth/autoload.php";

  use Abraham\TwitterOAuth\TwitterOAuth;



  function twitter_gettweets($sinceId) {
    $twitter = new TwitterOAuth(KEY, KEY_PRIVATE, TOKEN, TOKEN_PRIVATE);
    $tweets = $twitter->get("statuses/user_timeline",
      array('screen_name' => 'WBrettWilson',

            'since_id' => $sinceId,
            'trim_user' => true,
            'exclude_replies' => true,
            'include_rts' => false));

    return $tweets;

  function twitter_posttweet($string, $quoteid = null) {
    $twitter = new TwitterOAuth(KEY, KEY_PRIVATE, TOKEN, TOKEN_PRIVATE);
    $params = array('status' => $string);

    if (!is_null($quoteid)) {
      $params['attachment_url'] = sprintf("", $quoteid);

    $twitter->post('statuses/update', $params);

The Twitter.php file provides wrapper functions for the required facilities to access Twitter. It contains a reference to Abraham's Twitter OAuth library needed to access the Twitter API, definitions of the API access keys and tokens that are required to access the Twitter API, as well as two functions: twitter_gettweets() and twitter_posttweet() to facilitate the needed operations of the bot.

Now again, when I built this bot I aimed to do it in a single evening. I did not write it in a reusable way as you can see I've hardcoded references to the target WBrettWilson directly into the code. These could easily be changed to be defined constants like the tokens and keys, or command line arguments.

The two functions are quite simple comprising only 3-4 lines each.

Both functions begin by creating a new instance of the TwitterOAuth class, passing in the tokens and keys, and assigning it to the $twitter variable.

This function has a single argument; $sinceId is a 64bit integer value of the ID of the last tweet the bot used. This is passed to the Twitter API to only return new tweets.

Next after the creation of the OAuth connection we request from the twitter API all tweets since the specified ID; we trim out user information with 'trim_user' => true as the bot doesn't need it, we also exclude any tweets Brett is making in response to another user with 'exclude_replies' => true and finally we exclude retweets with 'include_rts' => false. We then store the result in the $tweets variable, and return it.

This function has two arguments; $string is simply the text of the tweet that is to be posted, there is also an optional $quoteId argument that defaults to null. The $quoteId argument is a 64bit integer ID of a tweet to attach as a quoted tweet, which gives me the flexibility in the future to have the bot post tweets not directly quoting Brett Wilson.

In this function we use a separate $params variable to store the API arguments for Twitter so that we can optionally add the quoted tweet attachment_url. We initialize $params with the $string as the tweet status text.

Next we test if $quoteId is not null, and if it isn't we assume it contains a valid 64bit integer ID of a tweet to quote and generate a status URL to attach with sprintf("", $quoteid). We then post the tweet and return the post result.

This makes up our Twitter-centric library functions, the real meat of the bot is in the next file.

File: /WBrettWellsonBot.php
  require_once "Twitter.php";

  $tweets = array();
  $tweetinfo = array(0, null);
  $lastId = file_get_contents("lastid.dat");
  $tweeturl = '';
  $tweethash = '#cdnpoli #ableg';
  $tweettemplates = array(
    # Generic tweets
    "generic1" => 'And don\'t forget: Making money is easier when you leave the wells behind! #investmenttips',
    "generic2" => 'I say a lot of stuff! All of it is way more important to me than cleaning my abandoned wells.',

    # Tweets about protesters
    "protesters1" => 'Ugh, protesters. Don\'t they know that if they just abandon the problem it goes away? Worked with my now abandoned wells!',
    "protesters2" => 'Can you believe protesters get paid to care about stuff? What bums! Job creators like me get rich creating problems not caring about them! Duh!'
First we include a reference to our Twitter library functions above, and also initialize some variables we will be using in the script. The script starts with a reference to #!/usr/bin/php which on Linux systems (where I'm running the bot) indicates that this script should be executed with the designated interpreter, in my case php command line interface (CLI). This file is executed each time the scheduler triggers it, so every 3 minutes in my current configuration.

$tweets and $tweetinfo are initialized with default values, while $lastId is read from a file called lastid.dat which is a simple text file containing only the ID. The ID of the last tweet the bot quoted is the only piece of data that is persisted between executions. The bot also later writes this file when it successfully posts a tweet.

$tweeturl and $tweethash separately store data that is included in every tweet. $tweettemplates is where I store the actual tweet text. Each tweet is given a key so I can look it up later, such as "generic1", or "protesters2". Single apostrophe's in the tweet text need to be "escaped" with a backslash as a single quote also marks the beginning and end of the string.

  $tweetmap = array(
    "default" => array(
    "protesters" => array(
    "protestors" => array(
Next we have the $tweetmap definition. The tweet map associates tweets to keywords, or default if no keyword match is found. If a tweet is quoted that does not contain a keyword a "default" tweet will be used. Here you can see that as the spelling of protester, or protestor, is often interchanged on Brett's timeline I have associated the same two "protester" tweets to the two different spellings.
  function match_best_tweet_for_pidge($_tweets, $_tweetmap) {
    global $lastId;
    $mapKey = "default";
    $tweetId = 0;
    $keywordTweets = array();

    foreach(array_keys($_tweetmap) as $key) {
      if (strcmp($key, "default") == 0)

      foreach ($_tweets as $tweet) {
        $matches = array();
        $pattern = sprintf("/%s/i", $key);
        if ($tweet->id < $lastId)
        if (preg_match($pattern, $tweet->text, $matches) == 1) {
          $keywordTweets[] = array($key, $tweet);

    if (count($keywordTweets) > 0) {
      $keywordTweetSet = $keywordTweets[rand(0, count($keywordTweets) - 1)];
      $mapKey = $keywordTweetSet[0];
      $tweetId = $keywordTweetSet[1]->id;
    } else if ($_tweets[count($_tweets) - 1]->id >= $lastId) {
      $tweetId = $_tweets[count($_tweets) - 1]->id;

    return array($tweetId, $_tweetmap[$mapKey][rand(0, count($_tweetmap[$mapKey]) - 1)]);
Next we have a simple function for the bot to determine which of the latest tweets is best to respond to. It's nothing fancy, it's just meant to provide some variation. We begin by importing the $lastId definition from the global scope as I later found I needed to verify the ID was truly newer. The function also takes two arguments, $_tweets and $_tweetmap which in our case will be the collection of tweets returned from twitter_gettweets() and our $tweetmap defined above.

We then iterate through all of the keys in the map, skipping default. For each possible keyword we then iterate through all of the tweets returned from the API and re-validate that the ID is in fact newer than the last tweet we responded to. If it is, we use a regular expression pattern match that simply checks if the keyword is contained in the tweet and if the keyword is found we store that keyword and the associated tweet ID in $keywordTweets.

Once we are done iterating we check if any keyword tweets were found, if one or more was we randomly select one otherwise we select the newest tweet and associate the default keyword to it.

We then randomly select one of the applicable tweets, such as "generic1", or "generic2" if we ended up with default as the keyword for instance. We then return the tweet text we intend to send, along with the ID of the tweet we selected to respond to.

Fun fact: The title of this function is called "match_best_tweet_for_pidge" because Pidge is my girlfriend's nickname and she wanted me to include it in the source.
  if (rand(1, 30) != 15)

  $tweets = twitter_gettweets($lastId);
  if (count($tweets) == 0)

  $tweetinfo = match_best_tweet_for_pidge($tweets, $tweetmap);
  twitter_posttweet(sprintf("%s %s %s", $tweetinfo[1], $tweeturl, $tweethash), $tweetinfo[0]);

  $lastId = sprintf("%d", (integer)$tweetinfo[0]);
  file_put_contents("lastid.dat", ++$lastId);
And these 9 lines? This is basically all the bot does. This, right here, is the bot.

The first thing it does is generate a random number between 1 and 30, and tests if the number generated is 15. This has the effect of running roughly 1 in 30 times, which combined with a 3 minute scheduler (3 times 30 = 90) means that the bot will potentially be able to send a tweet roughly every 1 and half hours, but is randomized enough that it's unpredictable. Sometimes it may be a shorter time, sometimes longer upwards of 2 hours.

Next, if the randomization passes we test if there are even any new tweets since the last we responded to.

If there are we then execute our match_best_tweet_for_pidge() matching algorithm above on the collection and determine which is best to respond to and what the tweet should say. We combine this information with the $tweeturl and $tweethash, and then post it to Twitter.

Finally we write the ID of the tweet were responding to plus 1 to the lastid.dat file.

And that's it!

Click here to recommend this post on and help other people find this information.

Richard Fantin is a self-taught software developer who has mostly throughout his career focused on financial applications and high frequency trading. He currently works for CenturyLink

Nazayh Zanidean is a Project Coordinator for a mid-sized construction contractor in Calgary, Alberta. He enjoys writing as a hobby on topics that include foreign policy, international human rights, security and systemic media bias.