Skip to content

Instantly share code, notes, and snippets.

@Beej126
Last active November 21, 2016 18:44
Show Gist options
  • Save Beej126/652ee84c902b6e1590912095ba88e097 to your computer and use it in GitHub Desktop.
Save Beej126/652ee84c902b6e1590912095ba88e097 to your computer and use it in GitHub Desktop.
Movie Mashup
{
"status": "ok",
"status_message": "Query was successful",
"data": {
"movie_count": 5839,
"limit": 20,
"page_number": 1,
"movies": [
{
"id": 6182,
"imdb_code": "tt4196776",
"title": "Jason Bourne",
"title_english": "Jason Bourne",
"title_long": "Jason Bourne (2016)",
"slug": "jason-bourne-2016",
"year": 2016,
"rating": 6.8,
"runtime": 123,
"genres": [
"Action",
"Thriller"
],
"summary": "Jason Bourne is again being hunted by the CIA. It begins when Nicky Parson a former CIA operative who helped Bourne who then went under and now works with a man who's a whistle blower and is out to expose the CIA's black ops. So Nicky hacks into the CIA and downloads everything on all their Black Ops including Treadstone which Bourne was a part of. And Heather Lee, a CIA agent discovers the hack and brings it to the attention of CIA Director Dewey, the man behind the Black Ops. He then orders Parsons be found and hopefully Bourne too.",
"description_full": "Jason Bourne is again being hunted by the CIA. It begins when Nicky Parson a former CIA operative who helped Bourne who then went under and now works with a man who's a whistle blower and is out to expose the CIA's black ops. So Nicky hacks into the CIA and downloads everything on all their Black Ops including Treadstone which Bourne was a part of. And Heather Lee, a CIA agent discovers the hack and brings it to the attention of CIA Director Dewey, the man behind the Black Ops. He then orders Parsons be found and hopefully Bourne too.",
"synopsis": "Jason Bourne is again being hunted by the CIA. It begins when Nicky Parson a former CIA operative who helped Bourne who then went under and now works with a man who's a whistle blower and is out to expose the CIA's black ops. So Nicky hacks into the CIA and downloads everything on all their Black Ops including Treadstone which Bourne was a part of. And Heather Lee, a CIA agent discovers the hack and brings it to the attention of CIA Director Dewey, the man behind the Black Ops. He then orders Parsons be found and hopefully Bourne too.",
"language": "English",
"mpa_rating": "PG-13",
"state": "ok",
},
{
"id": 6181,
"imdb_code": "tt1226766",
"title": "The Great Gilly Hopkins",
"title_english": "The Great Gilly Hopkins",
"title_long": "The Great Gilly Hopkins (2016)",
"slug": "the-great-gilly-hopkins-2016",
"year": 2016,
"rating": 6.5,
"runtime": 99,
"genres": [
"Comedy",
"Drama",
"Family"
],
"summary": "A feisty foster kid's outrageous scheme to be reunited with her birth mother has unintended consequences in The Great Gilly Hopkins, an entertaining film for the entire family. Gilly Hopkins (Sophie N\u00e9lisse) has seen more than her share of foster homes and has outwitted every family she has lived with. In an effort to escape her new foster mother Maime Trotter's (Kathy Bates) endless loving care, Gilly concocts a plan that she believes will bring her mother running to her rescue. But when the ploy blows up in Gilly's face it threatens to ruin the only chance she's ever had to be part of a real family. Based on the award-winning young-adult novel by Katherine Paterson (Bridge to Terabithia), The Great Gilly Hopkins stars Sophie N\u00e9lisse, Kathy Bates, Julia Stiles, Bill Cobbs, Billy Magnussen, with Octavia Spencer and Glenn Close.",
"description_full": "A feisty foster kid's outrageous scheme to be reunited with her birth mother has unintended consequences in The Great Gilly Hopkins, an entertaining film for the entire family. Gilly Hopkins (Sophie N\u00e9lisse) has seen more than her share of foster homes and has outwitted every family she has lived with. In an effort to escape her new foster mother Maime Trotter's (Kathy Bates) endless loving care, Gilly concocts a plan that she believes will bring her mother running to her rescue. But when the ploy blows up in Gilly's face it threatens to ruin the only chance she's ever had to be part of a real family. Based on the award-winning young-adult novel by Katherine Paterson (Bridge to Terabithia), The Great Gilly Hopkins stars Sophie N\u00e9lisse, Kathy Bates, Julia Stiles, Bill Cobbs, Billy Magnussen, with Octavia Spencer and Glenn Close.",
"synopsis": "A feisty foster kid's outrageous scheme to be reunited with her birth mother has unintended consequences in The Great Gilly Hopkins, an entertaining film for the entire family. Gilly Hopkins (Sophie N\u00e9lisse) has seen more than her share of foster homes and has outwitted every family she has lived with. In an effort to escape her new foster mother Maime Trotter's (Kathy Bates) endless loving care, Gilly concocts a plan that she believes will bring her mother running to her rescue. But when the ploy blows up in Gilly's face it threatens to ruin the only chance she's ever had to be part of a real family. Based on the award-winning young-adult novel by Katherine Paterson (Bridge to Terabithia), The Great Gilly Hopkins stars Sophie N\u00e9lisse, Kathy Bates, Julia Stiles, Bill Cobbs, Billy Magnussen, with Octavia Spencer and Glenn Close.",
"language": "English",
"mpa_rating": "PG",
"state": "ok",
}
]
}
}
#r "System.Runtime"
#r "System.Dynamic.Runtime"
#r "Newtonsoft.Json.dll"
#r "MarkdownSharp.dll"
#load "secrets.csx"
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Net.Mail;
using MarkdownSharp;
//pull the json feed
var client = new WebClient();
var moviesJsStr = client.DownloadString(jsonUrl); //see feed.json file for sample data here
var movies = JObject.Parse(moviesJsStr)["data"]["movies"];
//pull IMDB watchlist
var imdbXmlStr = client.DownloadString("http://rss.imdb.com/user/ur29693018/watchlist");
var imdbXml = new System.Xml.XmlDocument();
imdbXml.LoadXml(imdbXmlStr);
var imdbTitles = imdbXml.SelectNodes("//item").Cast<System.Xml.XmlNode>().Select(i=>i.SelectSingleNode("title").InnerText);
//mash them together looking for any hits
var newMovies = from movie in movies
join imdb in imdbTitles on movie["title_long"] equals imdb
select new {
Title=movie["title_long"]
};
//if we haz hits...
var newMovieCount = newMovies.Count();
Console.WriteLine($"new movie count: {newMovieCount}");
if (newMovieCount > 0) {
//format message via markdown
var md = new Markdown();
var html = md.Transform(string.Join("", newMovies.Select(r=>$"##{r.Title}<br/>\n")));
html += "<br/>\ndon't forget to clear these off your watchlist: http://www.imdb.com/user/ur29693018/watchlist";
//pop off the email
//from: http://stackoverflow.com/a/4677382/813599
//https://accounts.google.com/DisplayUnlockCaptcha
using(var smtp = new SmtpClient())
using(var message = new MailMessage())
{
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(emailFromAddress, emailFromPassword);
smtp.Host = "smtp.gmail.com";
message.From = new MailAddress(emailFromAddress);
message.To.Add(new MailAddress(emailToAddress));
message.Subject = "Movie update";
message.IsBodyHtml = true;
message.Body = html;
smtp.Send(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment