Indexing my movie collection

#FirstWorldProblems – having so many DVDs that you forget what you already own and end up buying multiple copies of the same movie.  While 126 movies isn’t a massive collection, it’s enough for me to sometimes forget what I have when I’m pillaging the $5 bins at Best Buy and Target.
To solve for this, I created a Google Sheets list of my collection so I could check what I have from my phone.  After typing all the titles into the list, I realized it’d be very easy for me to use the code I wrote for my DirecTV project to scrape additional details for the movies and create a nice, simple UI….so I did:
v1

What it does

  1. Using The Movie DB API, I pull several pieces of information about the film and store it locally: title, image, release date, rating, budget, revenue, runtime, synopsis, genres, cast, etc.
  2. Storing it locally reduces repetitive, slow API calls and allows me to cleanly add additional attributes like whether it’s DVD, Blu-Ray, Google Movies, Amazon Video, etc.
  3. Adding new titles is easy – I just type in the name and the rest of the details populate immediately.

 
There are two views: one shown above for desktop and another, more compact view, when a tablet or mobile device is detected:
v2
I’m not sure what’s next for this but it was a quick and fun project that connected my inner home automation and movie geeks.

Location to HTTP – Send GPS data to remote script

I wanted to capture my phone’s location information and store it remotely (on my server) so I could do with it as I please.  Most of the apps I found were severely limited in that they only mapped within the app, were riddled with ads, crashed frequently, or were untrustworthy (they’re storing my location, after all).  So, I decided to build my own app that did what I wanted.

Location to HTTP

banner-edit
Get it on Google Play
Location to HTTP is an app I’m working on which allows users to input a remote script URL to capture a device’s location information via POST.

How it works

  1. Create a remote script to capture the variables $lat and $lon via POST (example below).
  2. Download the app and enter the URL of that script.
  3. The app will automatically send the location information every 5-10 minutes to the script.

Possible Uses

  • Track your phone’s location so you can retrace your steps if you lose it.
  • Store your location history for displaying in custom interfaces.
  • Share your location with friends/family when travelling or hiking.
  • Trigger home automation events based on your location (turn on the heat, turn on the lights, unlock the doors, feed the pets, water the plants, etc.).
  • Measure the amount of time you spend at specific locations.

Sample Script

The beauty (and utility) of this app is that you can do whatever you like with the output.  In my use case, I want to store my location history to track my travel history.  I do this using a simply PHP script and MySQL database.
Database Structure

CREATE TABLE IF NOT EXISTS `phone_location` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lat` varchar(200) NOT NULL,
`lon` varchar(200) NOT NULL,
`time` varchar(200) NOT NULL,
`address` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

PHP Script

<?
//Prevent caching and set content-type to json so app can display it correctly.
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/json');
//Pull address for latitude and longitude from Google API (max 25,000 calls per day for free)
function getaddress($lat,$lon) {
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lon);
$json = @file_get_contents($url);
$data=json_decode($json);
$status = $data->status;
if($status=="OK"){
return $data->results[0]->formatted_address;
} else {
return false;
}
}
//Set the response we want to display in the app
date_default_timezone_set('America/Los_Angeles');
$timestamp = date('Y-m-d h:i:s');
$success_response = "Successfully captured location @ $timestamp PST!";
//Connect to MySQL database
$conn = mysqli_connect("", "", "", "");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//Capture the latitude ($lat) and longitude ($lon) passed from the app
$lat=$_REQUEST['lat'];
$lon=$_REQUEST['lon'];
//Get the address from Google API
$address= getaddress($lat,$lon);
if(!$address){
$address= "Not found";
}
//Insert record into database
$sql = "INSERT INTO phone_location (lat, lon, time, address)
VALUES ('$lat', '$lon', '$timestamp', '$address')";
if (mysqli_query($conn, $sql)) {
echo json_encode($success_response);
} else {
echo json_encode("Error: Unable to create posting.");
}
mysqli_close($conn);
?>

Google API Integration for Address Data

As shown in the example above, you can easily get address information using the Google API and reverse geocoding.