Trying To Read Nested Data From a JSON File

Over the last two evenings I have been attempting to read nested data. I have tried to parse the data and other methods but without success. I have browsed the web to try to find solutions but for now I am getting stuck. Learning is also about trial and error, and knowing where to find the right information. For now I am lost. At the end of this process I will be more self-sufficient.


Learning by watching courses is good, and we do make progress, but it doesn’t require us to think about problems in the same way. We learn to follow instructions but not problem solve, and that’s what I want to learn. So far I have spent two hours on this specific problem, and I could easily remove a few lines and it would no longer be nested. I will persevere.


Playing with Comments


Since I am trying and failing to accomplish what I am trying to accomplish I am now using comments to mark what I still need to achieve, whilst looking for solutions and ideas.


Prototypes and CSS


I have also continued studying prototypes, factories and more. I see some overlap between this topic and CSS. For those with experience and time both allow for more depth and complexity than is comfortable when you are starting out. The short version is that with prototypes and factories you can cut down on the lines of code in a project, making it easier to read, and lighter.


The Pandemic Continues


It is now the weekend but the pandemic is still alive and well. Governments are deciding not to do anything to stop the spread, preferring to tell people that for vaccinated people it’s no worse than the flu, whilst ignoring the fact that children from 0-18 have not been vaccinated. There is a certain degree of indifference by governments that is hard to observe. They expect the next few weeks to be difficult, and that’s as far as their sense of responsibility goes. It is a challenge not to be disappointed by this attitude.


JSON, Custom HTML and a Rainy Walk

JSON


Today I spent some time expanding my knowledge of JSON because understanding how JSON works, and how it works, opens doors. Every social network allows you to download your file as a JSON file. If you learn how to use JSON you can then re-use your data on a site of your own design, according to your own moral code.


WordPress and Custom HTML


I was also playing with static pages from the older parts of my website and trying to bring them into wordpress and for now it half, rather than fully works. My goal is to be able to have The Romans section with one look, the Geography section with another and the Environmental Systems with a third, to give just two examples. I found something promising but I haven’t understood it fully yet. It is a work in progress.


A Centralised Web and WEB 3.0


People are arguing that the world wide web needs to be decentralised, to become web 3.0 and yet the services we use are more and more centralised. Google, Amazon and Microsoft all have data centres and are getting a stranglehold on hosting and cloud solutions. Solutions like those by Infomaniak are much harder to learn about because they are still a small player, in contrast to the giants.


Facebook went down due to a misconfiguration error and two topics come to mind. The first is that Facebook shouldn’t have all three services on the same backbone because it becomes a single point of failure, and that was precisely what the Internet was designed to avoid. The second issue is that behemoths like Facebook should not exist, because they monopolise too much. When they went down IM went down for many, image sharing went down for many, and discussion groups went down for many. For a slice in time the world had to think of an alternative to communicate. Even Facebook had to.


This demonstrates that the Web, when it is too centralised, as it is via Facebook, has become fragile. I don’t mention Google, Amazon or Microsoft because they are giants, but they help the little guys be seen. Facebook doesn’t. It likes to capture and keep its traffic. We need to keep working on personal websites, to keep the web from being to vulnerable to outages.


And Finally – A Rainy Walk


As is usually the case, I did not set out on my walk in the rain, expecting to get rained on. I set off because although the weather app said there would be rain, did not say that it would be heavy, so I set off and for most of the walk the weather was nice. Not t-shirt weather nice, but bits of sun, and not too cold.


During the walk I took the Sigg original bottle. I put it in my coat pocket and forgot about it. By this I mean that it’s so small and light that it doesn’t get in the way of walking at full speed for an hour or two. It’s a good, small bottle, for when you want a drink, but you’re not in the middle of a heatwave.


And now for something else to read: Understanding How Facebook Disappeared from the Internet


How to Migrate from Instagram To WordPress

How to Migrate from Instagram To WordPress

Recently I migrated my photos from Instagram to a WordPress blog. The process took some trial and error. The first step is to understand how to read JSON files and format them in a way that WordPress can use. The next step is to import that data into Wordpress.


To request your data follow this link, request the data and wait for an e-mail telling you that the files are ready to download. When the files are ready to download download them and unzip the files.


Convert from JSON to CSV


You will find photo directories listed by year and month. You will also get a few JSON files but the ones you want are the media.json files. With a tool like the Konbert app you can convert the files from JSON to CSV files. When the CSV file or files are ready open them in Google Sheets or other spreadsheet software and look at the columns.


The fields you will find are


  • Caption
  • Taken At
  • Location
  • Path
  • Stories
  • Videos
  • Photos


Although not essential you can add fields like author. If you see “stories” and “videos” remove these columns. The CSV importer plugin I used cannot import videos and stories automatically.


When this is done you should have a CSV file that has caption, taken at, location, and path. Keep the photo file structure as it is.


Installing WordPress Locally


The simplest Wordpress installation I found is Local. Within minutes you can have a wordpress blog setup and running on your local machine. The reason you want a local install is that JSON to CSV conversions can be messy so if you make a mistake it is easy to reset and start again.


It took several attempts before I managed to import all the images and get them to display properly. If I had imported those files to my production Wordpress Blog I would have spent hours deleting thousands of posts more than once.


Folder Structure


When you import your images to WordPress with the CSV importer tool you have the option of leaving them where they are or of importing them into the uploads/year/month folder structure. Be warned that if you let the importer tool import the images itself it will import all of the images and generate thumbnails. If you have 3900 images you will end up with 12,000 images in a single folder as thumbnails are generated.


I would recommend:


  • creating a folder for every year that you were on Instagram
  • renaming every Instagram folder from /yearmonth/ to month, for example from 202006 to /06/ in the 2020 folder.
  • placing each month in the appropriate year/month folder in uploads.


Preparing the CSV file.


For the next step, I would recommend saving a copy of the document as it is so that you can go back to it if you make a mistake.


If you have changed all of the yearmonth folders to a year/month/ folder structure then you can use find and replace to update the folder names. You can find and replace 202006 with 2020/06 and work recursively. This will take more time, but be tidier. The CSV importer tool does not keep imports tidy. If I had known this ahead of time I would have taken this additional step.


In the CSV file the path is relative. To be tidy I put the photo folders in /wp-content/uploads/photos/ and had to update the CSV document to reflect that. Although you can find and replace in Google Sheets I used Visual Studio code for the next step.


Originally the path will be something like photos/202006/filename.jpg. but as the images are in wp-content/uploads/photos WordPress will look in the wrong place. With Find and Replace I selected “/photos/” and replaced it with “http://localhost:10003/wp-content/uploads/photos/”. At this point, the CSV files were ready to be imported.


Import CSV to WordPress


Although I tried a few tools the one I settled on is WP Ultimate CSV Importer.


The fields you will get when importing the CSV file.


If the CSV file is prepared correctly you should see Caption, Taken at, Location and Path. When I imported I mapped it so that so that Title and Content and slug would be the caption and for slug to be the caption. I then mapped Taken On to Publish date and featured image to the image path.


Select “Use media images if already available and “download post content external images to media


If you have kept the image folders as they were when you unzipped the Instagram download then select “Use media images if already available” and “download post content external images to media.” The images will be copied from the photos folder into the correct folder for WordPress to use.


If you have already organised your images by year and month in the uploads folder then you do not need to check “download external images to your media as they are already there.


The Final Step


The Final Step is to find a theme that reflects how you. want your images to be displayed and share the new location of your photo library to your various social media profiles and networks.


As a final step if you find that an image does not load for single posts you can add this line of code after the PHP tag.


if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'full' );
}


This is a lot faster than going through 3900 posts and adding an image to each individual post.


Conclusion


If everything works as expected you can now export a CSV file of your test blog and upload it and the appropriate files to your online photo blog.

Close to Success – Exporting Instagram images to WordPress Natively
| |

Close to Success – Exporting Instagram images to WordPress Natively

When Instagram was a self-run startup I loved the product. I loved that it was a way of sharing images with friends. I loved that it was fast and that it was light. I also liked that it had it’s own community. I liked that it was a way of sharing real life with people we conversed with online.


When Facebook bought Instagram that slowly changed. Algorithms and popularity contests became more important than sharing between friends and so the sense of community was lost and we were posting for strangers rather than friends.


For months, or even a number of seasons now, I have felt that Instagram is just a way of forcing us to see images by people we are not that interested in, with the hope that we will eventually see images that are relevant to us. That time investment we make is devalued when you consider that the Facebook behemoth is making millions from our mindless scrolling.


During the pandemic my patience for social media finally fizzled out and I’ve been playing with my website. By playing I mean, experimenting, learning, and developing and trying new ideas.


One of those ideas was to export my Instagram account and find a way to flip it over to Wordpress. Why Wordpress, rather than another social network? WordPress is an open-source social network that we control. We control advertising, we control posting frequency, we control layout, and best of all, there is no group of investors holding our… …I’ll leave that to your creative imagination, over the fire.


I tried finding tools to import from JSON to WordPress but in one case I needed to install wp-cli and that was complicated, and I wasn’t confident that it would be tolerated by the web host. I could have asked but instead, I set myself the challenge of installing MySQL on the laptop and running the localhost for experimenting. I failed to connect my localhost WordPress install with MySQL and eventually after two days of trial and error I decided to take a break and try something easier. I tried XAMPP but then I found what looked like a simpler tool, with WP-CLI integrated.


I settled on LocalWP. With this, I tried the GitHub project I thought would help me import the JSON files but that failed so I looked for another solution and it got me 90 percent of the way to achieving what I wanted to achieve. When I confirm that this process works I will post a How-To guide.