Integrating Twitter with my Laravel Based Dashboard

Image by Pixabay user 27707.
Image by Pixabay user 27707.

This post is part of my ongoing series documenting my explorations of Laravel to build my own online dashboard.

One of the many things I’m concerned about with free online services is that the service you are getting isn’t the product. You are the product, or more specifically the data about you that is made available to paying advertisers and other third parties.

This means that you are not in control of your data in their system. As such I try to keep a copy of the data that I put into the service, in a place that I control. Especially if that data is valuable to me.

For the longest time my Twitter account was something that didn’t have high value data in it for me. Recently I’ve realised that I engage with the service at a significant level, as such I’ve decided it is time for me to store a copy of the Tweets in an archive. Especially as now I have the basis of a system to make that easier.

To integrate my dashboard with Twitter, I have used the following two libraries:

Where possible I like to use existing libraries, as it means I can reach my goals faster.

To get started with integrating Twitter with my dashboard I first downloaded an archive of my data. I then wrote a small console command to import the data into the dashboard.

Next, I integrated the dashboard with the Twitter OAuth api using the socialite provider. This was similar to the way I integrated with the WordPress platform, and was surprisingly easy.

Lastly, I wrote a small console application that uses the Twitter API library to periodically check for new tweets, and import them into the archive. To date the console application has worked really well.

Below is a screen capture of what the Twitter archive page looks like at the moment.

Screen capture of my Twitter Archive page.
Screen capture of my Twitter Archive page.

The pagination bar at the bottom of the page is provided by code Laravel pagination functionality. The more I use the Laravel framework, and the libraries that have been built around it, the more I want to continue to develop with it.

I’m currently developing plans for the next set of features for the dashboard. Check back here soon for a post on my progress.

Console Command to Batch Create Database Records Using Models in Laravel

Photo By: StockSnap.
Photo By: StockSnap.

This post is part of a series on the development of my dashboard. I’m implementing a dashboard for my websites, and online activities, to explore the Laravel framework.

I this post I will briefly outline a console command that I have developed. The purpose of this command is to import the contents of a CSV file into the database.

The command uses the specified model to check to see if the record matching criteria exists. If no matching record is found, a new one is created.

In an earlier post I outlined how I have integrated statistics for my WordPress blogs in the dashboard. The OAuth2 based API allows me to get visits and view statistics for my blogs that cover the last thirty days. For a more complete dataset I wanted to add historical data as well. Unfortunately it is not possible to get data for a specific time period using this API.

An older API does allow access to historical data, and provides the data in a CSV format. I only needed to use this API twice, once for each blog, and I didn’t want to go to the effort of writing code that integrated with the API. Working with a plain CSV file is significantly easier.

I also didn’t want a single purpose console command. I wanted something that could be used with any of my models now and into the future. Especially, when I integrate additional services with my dashboard, and want to import historical data.

To meet these requirements, I wrote the following basic console command:

I’ve put the code here, in the hope that it proves useful to other people who are looking to achieve similar goals.

Please note that this is code that I wrote to meet my specific needs, in a personal project. As such it should be considered a starting point for others looking to implement similar functionality, rather than a fully implemented solution.

If you find this code useful, please let me know.

Adding WordPress Statistics to the Dashboard

Photo by: StockSnap.
Photo by: StockSnap.

This post is part of a series of posts I’m writing about the dashboard that I’m developing to explore web development with Laravel.

To increase the usefulness of the dashboard, and to get some experience with the some more technologies, I decided to collect, store and display statistics on my two WordPress blogs.

I use the excellent JetPack plugin to provide additional features on my blogs, including the collection of site statistics. The reports are great, but I wanted a simple overview of my sites in the dashboard.

To achieve my goal I needed to integrated my dashboard with the WordPress REST API to retrieve the statistics for my two blog, Thoughts by Techxplorer and  Elemental Fiction.

The technologies I needed to learn about included:

The end result is a page that looks something like this:

Screen capture of the WordPress Statistics page
Screen capture of the WordPress Statistics page

The development of this part of the dashboard was surprisingly easy. This was due to the hard work that other developers have put into the following libraries:

If anyone is thinking of doing something similar, I can highly recommend these libraries. They saved me a great deal of time, work and frustration.

Scheduling Tasks in Laravel, When You Can’t Run the Main Task Every Minute

Lego man sweeping. By: Michael Schwarzenberger.
Lego man sweeping. By: Michael Schwarzenberger.

Earlier this week I posted the first post, in what I hope will become a series of posts, on my explorations with Laravel and building my own dashboard. The first post focussed on the functionality records pings from my home server. It is a way to replace the need for a dynamic DNS service for my home server.

Each ping records the current external IP address of my home server, and a ping occurs once every twenty minutes. The table will quickly fill up with old records, which is not desirable. I need a way to periodically tidy up the table to remove old records.

The Laravel framework includes the task scheduling functionality. When this is combined with an artisan console command I have everything that I need to periodically tidy up the table.

Or so I thought…

The task scheduling functionality relies on a Cron entry that runs the main schedule command every minute. The trouble I have is that my hosting provider, Dreamhost, does not allow cron entries to run every minute on their shared hosting infrastructure. This is a perfectly reasonable restriction, and one I needed to work around.

When I considered the types of things that I’ll need to run via scheduled tasks, I realised that I only need to run tasks once every hour. I don’t need a more frequent schedule.

To work around this issue I now run the main task scheduler 29 and 59 minutes past the hour, every hour. I then use the when method to implement a ‘truth test’ constraint. The basis of my constraints are the following three functions, implemented as part of the App\Console\Kernel class:

Using a combination of these three functions I can schedule a task to run:

  1. Twice every hour.
  2. Twice on a specific hour.
  3. Every hour, only in the first half of the hour.
  4. Every hour, only in the last half of the hour.
  5. A specific hour, only in the first half of the hour.
  6. A specific hour, only in the last half of the hour.

This meets my needs, and doesn’t require the main schedule task to run every minute. For example I can schedule a task to run like this:

I hope this post helps others who need to schedule tasks, but cannot run the main schedule task to run every minute.

Learning Laravel by Building a Dashboard

Vintage Antique Truck Key and Gauge. By: Catherine Haugland.
Vintage Antique Truck Key and Gauge. By: Catherine Haugland.

One of the challenges for me with learning a new programming framework, or language, is having a project that keeps my interest.

To that end, I’ve started a new project to build what I’m calling a dashboard, for my online activities and websites. I’m using the latest version of Laravel as my framework, and Bootstrap with HTML5 for the user interface.

It has been surprisingly straightforward so far. I’m also using and building upon the lessons I’ve learnt while working on an internal project as part of my role as a Business Analyst at Flinders University.

The first item that I needed to develop was a replacement for my Dynamic DNS service, so that I can use SSH to access my Raspberry Pi based home server from anywhere. To that end I’ve developed a ‘Pings from home’ page in my dashboard. Below is a screen capture of the page.

Latest Pings From Home page in my Dashboard
Latest Pings From Home page in my Dashboard

The IP address of my home router is displayed, and is incorporated into a link that I can click that logs me in to my server.

Over the next few months I’ll add more functionality, as a way of exploring the capabilities of Laravel, integrations with other systems and APIs and exercising my programming skills.

Release of Techxplorer’s Content Tweaks Plugin

Original image by: Bryan Nielsen.
Original image by: Bryan Nielsen.

Today I am really pleased to announce the release of my latest plugin for WordPress. The plugin, called Techxplorer’s Content Tweaks, implements a few tweaks to content and media that I find useful. I’m releasing the plugin in the hopes that others may find these tweaks useful as well.

The tweaks that version 1.0.1 of the the plugin implements are:

  • Automatically adding WordPress tags to posts based on hashtags found on the post content.
  • Adding three custom fields to uploaded media to make it easier to track attribution. The fields are:
    1. Author name.
    2. Author profile URL.
    3. Source URL.
  • Automatically calculating, and displaying, various statistics on an individual post. The statistics include:
    1. Word count.
    2. Estimated reading time.
    3. Date and time of last update.
  • Adding a notice to posts which are 6, 9 or 12 months old.

More information on the plugin is available on the plugin project page, as well as the plugin page in the WordPress Plugin Directory.

Asrar the Veiled Chameleon at Adelaide Zoo

Yesterday the family and I visited Adelaide Zoo. Not the best day to go as it rained in the early afternoon. Before it rained I had the opportunity to get some good photos.This is the last gallery of photos from the visit. This is Asrar a Veiled Chameleon.

Not the best set of photos I’ll admit, it was a little too dark and I had the wrong lens on my camera (I’d left the other lens at home). But Asrar was too beautiful to not at least attempt to get some photos.

White-checked Gibbons at Adelaide Zoo

Yesterday the family and I visited Adelaide Zoo. Not the best day to go as it rained in the early afternoon. Before it rained I had the opportunity to get some good photos.This gallery is of photos of a White-checked Gibbon and what I assume is one of her offspring. The female is a lovely golden colour, and the male offspring has black colouring.

Brush Tailed Rock Wallabies at Adelaide Zoo

Yesterday the family and I visited Adelaide Zoo. Not the best day to go as it rained in the early afternoon. Before it rained I had the opportunity to get some good photos.This gallery is of photos of Brush Tailed Rock Wallabies.

My Brief Reflections on Workshop Wednesdays

Image by: Gerd Altmann.
Image by: Gerd Altmann.

Brief Reflections on Workshop Wednesdays

Ever since I saw a link to this article in the Twitter feed of my friend Kahiwa Sebire a few weeks ago, I’ve had this post percolating in the back of my mind.

The article is a humorous piece about the evils of all staff meetings. The article was particularly amusing because I was, and still am, reflecting on a regular meeting that I’m advocating, and organising within my team at Flinders University.

With the support of senior management, I started an initiative early this year which I called Workshop Wednesdays. The purpose of the meetings, as I outlined in my original proposal, is to try to foster a culture of collaboration, cooperation and knowledge sharing.

I can’t go into too much detail, as I don’t have the permission of the team. The one hour, fortnightly meetings, are divided into three main sections.

First, is any administrivia that needs to be shared with the team, as well as an update on any issues raised in the previous meeting. In this section we have also covered updates on mini projects that the group has started. I was particularly excited by our first few meetings where we identified changes to the login process to the student information system that we believe has improved the student experience.

Second, is the standups. We’ve adapted the concept of standup meetings from the agile software development methodology. Each team member focusses on the following three questions:

  1. What did I accomplish in the past two weeks?
  2. What will I do in the next two weeks?
  3. What obstacles are impeding my progress?

Each team member has two minutes to work through the above questions. To help us focus, I developed the Workshop Wednesday standup helper webpage.

I feel that these two minute overviews by each staff member are very important. And some very valuable, and sometimes robust, discussions have been sparked  by them. A constant challenge is striking the right balance between the need to keep people to time, and to give people the opportunity to contribute and feel they’ve been heard.

The third and final section is a discussion section. During these sessions we’ve reflected on this such as ways to improve the student experience, and what the team needs from a possible change in issue tracking and project management systems.

These workshops are challenging, and it is a challenge that I take seriously. I am always seeking feedback, and looking for ways to improve.

In June this year the workshops will have been going for a little under six months. During that time we will have a formal review. The goal of the review is to identify ways to improve the workshops, outside the regular requests for feedback. Additionally the team, in conjunction with senior management, will decide if we continue to have these sessions.

While I can appreciate the sentiment of the article that Kahiwa tweeted about. I also feel that some all staff meetings can be beneficial. A sentiment that I hope is shared by the rest of my team.