From Instagram Archive to PHP Website

From Instagram Archive to PHP Website

Three years ago I stopped using Instagram because I was tired of seeing influencers and adverts rather than by the people I chose to follow. The cherry on the cake, that pushed me to dump Instagram is when they changed the location of the Post button from the left corner to the top right and changed the default from photo to story.


For ten years or more I used instagram and shared photos, and I enjoyed capturing at least an image or two every single day. It’s because Instagram was bought by Facebook that I fell out of love with the site and decided not to use it anymore. The community had been lost, so what good was there in sticking around? 


Instagram to WordPress


In 2020 I played around for two days and I developed a work flow to take my posts json file, and convert it to CSV before importing it to wordpress via a plugin. It worked well, but I never used it. 


The Laravel Concept


For a short time I was thinking of trying to get Laravel to drive the Instagram clone but soon changed my mind, due to the amount of learning it would required. I settled on a simpler, yet practical solution. The PHP Array. I had used PHP arrays for one or two sections of my page, as well as individual pages. It’s simple and intuitive to use, with few complications to debug. 


JSON to PHP array


Recently I saw discussions about how pixelfed made it possible to import the instagram json file to pixelfed and that’s what encouraged me to play with the Instagram json file. This time I tried a different tact. 


The first step was to download the most recent json file and save it locally. Once this was done I converted the json file 


I asked chatGPT for help. I asked it how to convert from json to php array. The answer summarised is “$json = json_encode($array);”


I then asked how I would generate a file:


$json = json_encode($array);

$file = ‘data.json’;

file_put_contents($file, $json);


After this It was a matter of trial and error to read the php array data. My idea was to create a loop that would cycle through each post individually and display the image, as well as the related data. Usually I would achieve this by trial and error, as I have done, in the past, with other projects. 


chatGPT Helps to Access Array Data


By myself I was able to retrieve the URI and display it. I struggled with the timestamp and exif data so I asked chatGPT to help me. It gave me examples of how to get the URI, the iso info, and the title. The arrays contain more info but I extrapolated that from the example chatGPT had provided me with. 


At this point the page was ready to experiment with displaying the content. At first it was just text. I then added the required html to display the image properly and to size it correctly. When that was working properly it was time to add pagination. 


In the past I would have spent time Googling for examples of pagination and selecting one that worked well but this time I asked chatGPT for help. 


It helped me with pagination, except that the pagination was from page one to one thousand six hundred or more. That’s excellent, if you want that, but I didn’t. I wanted the pagination to be paginated, so I asked chat GPT to help with this too. It did. I then noticed that I needed back and forth, so I asked chatGPT for help yet again. 


EXIF volatility


When the site was loading individual images and the relevant information I flicked through the images and noticed that some did not have exif data so I asked chatGPT to write an if else loop that would display exif info if it was available, and ignore it if it wasn’t. This worked well. 


Time Taken


chatGPT is a fantastic tool, when you know what you want, and you understand how to get it to work, but you’re not 100 percent on the code aspect. I had the basic functionality of the json to PHP site functional within an hour to an hour and a half. I then spent hours tidying things up, adding a little functionality here and there. With chatGPT if you know what you want to do but you’re not certain of how to do it, then it shines. 


During this process I asked a question, it gave an answer, when I saw the answer I tweaked my question, until the result was what I wanted. 


Adding CSS


When I was happy with how the site was behaving I changed from displaying three images, to five and then I added styling. For styling you can copy and paste from old projects, or various sources, or you can ask chatGPT to give you a black background with white text and white borders and it will provide you with the code. Within seconds your theme is ready. 


And Finally


I am comfortable with PHP. I have been redesigning my website to run off of PHP rather than html or a CMS and it works well. chatGPT didn’t provide me with the concept or direction. I did that. I thought of the steps and workflow, and got chatGPT to provide me with reminders of how to do things. It’s because I knew what I wanted to do, that I achieved my goal within a short amount of time. This is really a post about how I used prompt engineering to get chatGPT to help me achieve the goal I wanted to reach, within minutes, rather than hours, or days. 


i went from having a big, clunky wordpress blog, to a few lines of php, to do the same thing. I can add functionality with time. For now it shows my instagram photos efficiently.


The Result

Laravel and Context

Laravel and Context

There is value in studying Laravel and context. By this I mean that over a year ago I wanted to study Angular but after feeling lost in Javascript I decided to take a step back, to study JavaScript. I studied two or more courses over a period of months. I could have followed a single course and claimed that I knew and understood JavaScript but that would have been misleading.


The value in studying two, three or more courses is that each teacher, and each course takes a different approach, and each approach fills in gaps that are left open by others. By studying three or more courses on JavaScript I gained a better contextual understanding of what JavaScript can do, as well as how it works.


Eventually I did return to JavaScript but I encountered another challenge. I don’t understand the error messages yet, because I haven’t come across them. That’s when I decided to circle around and study PHP from the ground up and that’s where I found comfort. I like PHP because errors are clear. They are usually literal. There is an error at this line and it’s easy to debug.


After becoming more confident with PHP I started to rework my personal website so that pages went from being basic html pages that were decades old, with css added recently, they were php pages. Eventually I felt confident enough to step into the world or Laravel.


I began by experimenting with one laravel tutorial on the laravel website, before following the tutorial but changing certain names. It worked well. I was able to create website sections and update content and more. I did get stuck when I wanted to make content visible to non logged in users.


That’s when I decided to follow a course. The course is “Let’s Learn Laravel” by Brad Schiff. It is a comprehensive course, over fourteen and a half hours that teaches you how to create pages, users, models, use middleware, policies, how to create chat rooms and more. On the topic of chat rooms I find it interesting.


He often says “this is outside the scope of the course so I won’t go into the details” but I have already been into depth by following Vanilla JavaScript courses. I would struggle to write the code from scratch, but if I see the code in front of me then I do understand what it does, to some degree. On this specific topic he also points us to node.js packages that do most of the work for us.


The reason I follow Udemy coures, that I buy at 9.99 or 11USD, when they’re on sale, rather than follow hours of courses on YouTube is that they’re comprehensive. They also have to adhere to a certain standard. I also use Linkedin Learning for courses.


My website is decades old, and it has gone from html, to html with CSS, to static php. By learning to use Laravel it will become dynamic. It will serve to prove that I understand what I am doing. It will help to build up my confidence, and my portfolio.

Laravel and Chirper

Today I used Laravel to code a Twitter clone called Chirper via the tutorial you can find here. The tutorial took about two hours before I got the notifications section of the tutorial. The tutorial is easy to follow and with my contextual knowledge I was able to write most of the code with a minimum of errors. The tutorial follows the CRUD model, Create, read, update delete, and adds in notifications for good measure.


I chose to follow the Blade course rather than the React course because at the moment I feel more at ease with PHP thank JavaScript despite spending months on JS courses. What I like about PHP and Laravel is that when there is an error the code will show you the code with an error and you just need to understand what it is.


With JavaScript and especially with typescript the error message provides you with code that is hundreds of lines away from what is causing the code to fail. It takes seconds or minutes rather than hours to debug an issue.


Although building a twitter clone might not sound exciting, it is worth doing. Creating, reading, updating and deleting are key parts of Content Management systems so if you can do it for content with 255 characters you can easily expand it to blog posts, articles and more. It also means that you have a chat app to use within a small group of friends.


The next step, once I finish the course, is to adapt the code to get the content from my website to work via the Laravel framework. For the next step I want to read documentation. Watching video tutotirals is great sometimes, but it’s time consuming. The next step is to read documentation, and understand it. I have spent enough time building context. Now is the time to put this knowledge into practice.

Learning About Laravel and PHP
|

Learning About Laravel and PHP

Today I started to follow a course where someone turns a static html page into a Laravel blog. I experimented with home.blade and one or two other features and I got two pages to load, and the login to work, without more than that.


What makes today’s learning and experimenting interesting is that the time I spent creating PHP arrays for my website content is now easy to transfer to json files for use with dynamic websites. What this means is that content that was stuck on individual pages is now organised by website section. I am now free to do more.


The primary goal is to convert the static part of my website into a flexible content management system as well as to possibly swallow up the WordPress powered blogs. For at least a year I have disliked that Wordpress uses react, so if I can replace WordPress with Laravel then I will be happy. All websites that use React look the same to me, and I don’t want to use technology that was developed by Facebook, no matter how popular.


Having a website is not just about writing blog posts and creating content. It is also about playing with technology and learning new skills. I want to understand how laravel works, and to have a way to demonstrate that I have learned relevant skills for future job applications. This website isn’t small. It has quite a few sections, topics, content and more. It’s worth working on and improving this website.


And Finally


I am curious about playing with ActivityPub. It is still in early days but if and when it is ready, it will be a more advanced of interactive RSS. I want to see what possibilities it will open up.

Conservation and PHP

Today I have struggled with PHP. I struggled because I want to recreate the same table using loops with PHP as I did formatting with HTML. If I wasn’t up for a challenge I would let PHP loops format it according the default and I’d be done. In the end I did get the table to display as I wanted but not using for loops. I created a table page, laid it out using the data file I’ve been using for this section, and then using include to add that content where I wanted it to be on the page.


It works, and it’s elegant. I want it to be done by a loop. This is important to me because it requires me to learn more about how to use nested loops and this is an important element of programming. It’s a skill worth having.


Before : intermediate : After


Above you can see before css was added, the website looked simple. When CSS was added it looked better, and once it became php it looks similar but the code needed is much less, as data is with included files. The footer and the nav bar are always the same, and for most pages the usual loops are enough to display content on all pages.


With PHP you can just echo html and the page will display as you want it to. With variables and includes you can display the information you want to display automatically, rather than manually.


In most cases you can use “Title”, and “content” and use HTML to format all the data as you want it to be. By doing this the conservation page would be done within minutes but the content would be less flexible. By creating arrays within arrays I make things more modular. I can remove or add sections and it will just change that part of the site without affecting other parts.


The point with PHP, frameworks and javascript is to set everything up so that when changes are made they can be as small or as big as we want, in a modular manner. That’s why my struggling to get things to work today is important. Once I learn how to do this, I will be more confident with future challenges.

A Rainy Day Without Walking

Today the weather app said that it would start raining at 1500 so I didn’t go out for a walk. In the end the rain started at around 1630 or even later. I could have gone for a walk and I could have come back dry or almost dry.


For years I went for walks almost everyday, whatever the weather conditions. I grew tired of the habit. I have had this habit for five years or more, three of which have been during the pandemic.


I am tired of two things. The first is about walking into the building with muddy shoes. The building has no system to clean shoes after a walk in the mud so I can’t remove the mud easily. Usually if I walk in the mud it’s the next day that I leave a mess. I wouldn’t worry but apparently others do.


The second reason I don’t want to go for walks is that I’m tired of encountering people walking as couples or groups. If I encountered people walking alone, especially people my own age then it would be fun. Seeing couples, when you’re solitary during a pandemic is unpleasant. I often change route to avoid them, especially since they almost always take the entire width of the roads or other paths.


I spent today completing the conversion to php from html for the geography part of the website. I have moved from studying PHP to putting the knowledge into practice. Now I will work at having something to showcase, and to have something for the portfolio, to build confidence so that I can apply comfortably.

A Shift to PHP

PHP has been around for decades but I learned of a way to experiment with it easily recently so that is why I am playing with it now. The main page is php as is my first “blog” although it was part of a column for the student newspaper, that I converted to an electronic format and published frequently.


I tried to keep Surfing the World Wide Waves looking as it had back in the day. The aim is to practice with PHP and get some things to become automatic. I include one php file with the data, and a second for the footer. I use a loop to populate each blog post.


It looks like this


  • include data_file.php
  • echo header etc.
  • article title, content etc
  • include footer


The format is simple and I could have made everything a for each loop so that each page is generated automatically but for the sake of learning and persistance I updated each page individually.


Aside from learning how to use PHP it was also an opportunity to practice using VIM.


List of PHP files accessed with vim.


VIM is great for this process because you type vim name of file and you edit the little lines. I used shift V to use visual edit. I bulk deleted the old code I wanted to replace with the include footer line. It’s a repetitive task but that’s good for learning, and for a skill to practice and become habit.


Now that this repetitive task has been done I have more flexibility to edit the footer without having to edit every other individual file. I would have tried with the header element but I need to think about how to do this without losing meta data etc. It should be added to the data file and I could access it as a variable in a different part of the page.


With time I will fine tune all of these ideas and it will be reusable for future projects.

|

PHP from the Command Line

Recently I learned that PHP has a built in server. You don’t need xampp or any of the other solutions. All you need is terminal open, have the current directory be the one with the PHP files you want to serve and type: “php -S localhost:8000”


This might sound obvious to some but it took years for me to come across this. When you have to install xampp or other solutions you need to dedicate HD space, run the servers and more.


With just one line in terminal we can start the server and start experimenting with and learning PHP. With this you can be up and running within seconds or minutes, rather than hours, and it is flexible.


I’m sharing this with you now because I wish that at least once course had mentioned it. This is the simplest and most elegant solution I have found. Best of all it’s free.


For more info: https://www.php.net/manual/en/features.commandline.webserver.php

Learning To Code By Building CMSs
|

Learning To Code By Building CMSs

It’s easy to use Facebook or other CMS every day without thinking about how the code works. This summer I have coded two CMS using Linkedin Learning. One of these CMS was running with PHP and MySQL and the other was running with Ruby On Rails and MySQL.


The PHP CMS


In the process I learned how to install MySQL, how to get MySQL and PHP to talk to each other. How to organise files between private and public folders on a web server and more. Getting MySQL to talk with the web server was a challenge that took a few days to get right.


With the PHP CMS I learned about arrays, about interacting between PHP and MySQL and I learned to be attentive to using the correct syntax. Sometimes though, a single typo would block my progress for a period of time. It wasn’t rare for me to compare the code I wrote with the code written by the instructor line by line to find my typos.


I could have cut and pasted the code but I found that simply typing the code character by character was enough to force me to read the code carefully. When I made typos it taught me to attentive to details as well as to be more aware of the syntax.


Ruby On Rails


Ruby on Rails was an interesting learning challenge. I got stuck before I even finished setting up the project. As a result of this I went back and followed a course on essential Ruby. This worked as a nice complement to what I learned from that point on.


During the project configuration process I got stuck because I created the project with the wrong database connection type. I left it on the default and when I tried to correct this I failed, and failed, and failed again. Eventually I decided to delete the application and create a new one, with the right database connection and this time it worked well.


The challenges I faced were that the Puma Server wouldn’t start because a gem was missing, that the CMS wouldn’t start because of a mistake in the routing file and more. Eventually I would restart the server but I spent a lot of time debugging.


One of the most persistant problems I had with Ruby on Rails is that it’s hundreds of lines of code across multiple files and although the error messages are obvious you need to learn to read them. For two or three days I couldn’t find what the error was, despite looking through every page and its code. Eventually I found that I had written “visible” and forgotten a “:visible”. That error crashed the Puma server consistently.


With Ruby On Rails, I learned to work within a framework. This knowledge is transferrable to working with other frameworks. I’ve gone from knowing how to install and use a CMS like WordPress, Joomla, and Drupal to learning how to create one and to understand how arrays and functions work. I have also learned how to think about security and how to use blowfish and other encryption technology to keep passwords etc. more secure.


With Ruby Gems I could work on projects of my own and be less reliant on other websites. One project I would like to work on is creating a heatmap of all my walking activities and the easiest way to do this would be to find some code and adapt it to have the functionality I desire.


The Next Step


The next step is to learn to use JavaScript. I will then know how to use HTML/PHP for content, CSS for layout and finally JS for interactivity.



2020 – The Golden Opportunity to Be A Recluse

2020 – The Golden Opportunity to be a Recluse. If you’ve ever wanted a reason not to be social then open society’s behaviour, in regards to the COVID-19 virus, has provided us with a fantastic opportunity to enjoy being reclusive.


During a normal Spring and Summer I would be driving to the mountains to hike, climb and enjoy via ferrata with people but this year those plans have been destroyed. This year we can’t share the same room as others to sleep. We can’t even eat within two meters of other people.


There are no handshakes, no hugs and no “bises”. This year if you live alone you’re without physical contact. This year, the more solitary you like to be, the stronger the appeal of such a year.


In a normal year if you were single or below a certain age you’d be pressured to go out and be social, rather than staying at home to work on projects, read books or otherwise be solitary. This year there is no pressure to go out on Thursday and Friday night, and there is no pressure to go out to do group activities during the weekend.


With its single minded desire to reopen too early society has destroyed any chance of a normal summer being possible. Until the 21st of June it looked as if Switzerland was three or four weeks away from the pandemic being over, or at least wonderfully under control. There was a brief window with just 10-20 infections a day.


Speaking as an idealist I believe that we were so close to Switzerland getting to tens of new cases a day but recently the seven-day average is back to 100 cases a day.


Silver Linings


Source: https://www.corona-data.ch/


One of the silver linings is that the number of ventilated people declined to zero for several days, the number of intensive hospital cases is staying low and finally, that the number of regular COVID-19 patients was in decline, until two days ago.


At its maxium number of active infections Switzerland was at 98 percent of ICU capacity. Two more percent and triage would have been required.


Depending on whether you work for the airport or think as an environmentalist Geneva airport expects to be at 19 percent of capacity this summer, due to so few people travelling at the moment. It’s great for the environment, but a shame for jobs.


Societal Self Harm


Speaking from a strictly theoretical point of view we have centuries of pandemics to look back on. We have books such as La Peste by Camus, to turn back to. In theory, we know what to do in the case of pandemics, and how to avoid them. We also know how to control them.


We know that in Medieval times villages would shut down to the outside world for weeks or months at a time. We know that ships were quarantined offshore. In some cases, places of infection were marked.


As we watch the current pandemic we get the impression that lessons were never learned. We get the impression that people never studied plagues and other epidemics and pandemics. We get the impression that people are flying blind. This is a shame.


It’s a shame because we are in the 21st century. We live in an age where we have thousands of hours of documentaries about plagues, disease and epidemics. We live in an age where people can get advice and information straight from medical health professionals. We live in an age where everything can be ordered online. We live in an age where being trapped at home does not mean having conversations has to stop. We live in an age where many of us are information workers.


In light of all of this it seems illogical that we would live through the worst pandemic in human history.


I have seen a lot of discussion about rights but responsibilities have been skirted. The responsibility to wear a mask, the responsibility to keep human to human interactions to a minimum, the responsibility to avoid people rather than expect them to make the effort to be safe.


The self-sacrifice of not going on holiday, the self-sacrifice of not going to sit in a park half a meter from others…


With everything that society, as a whole knows, it is a shame that the pandemic coalesced into such a serious problem because we had the tools and knowledge to ensure that it would be dealt with as swiftly as the epidemics we have already lived through, in our own lifetimes.


At its core Switzerland, until the 21st of June Switzerland was doing everything right, and to a serious degree it is still doing the right thing, with the number of ventilated people being at zero and the number of serious cases also dropping.


At it’s core my only issue is with having a third summer with limited opportunities to meet new people. As long as the pandemic is around it seems more logical to give in, and use dating apps, to meet new people, instead.


The Up-Skilling opportunity.


A few weeks ago I sad that I would try to create my own WordPress theme, but I overshot that goal by learning CSS and redesigning my entire website. I have learned to create a CMS from scratch using PHP and MySQL. Now I’m learning Ruby On Rails and it’s going well. Ruby on Rails looks like an intuitive framework to work with. I’m working on changing my career path.