// Used to only receive ID however it now received ID's // as well as html Text public static double GetDateOfBirthForWinner(string htmlPage) { // check whether we passed in a html page as a parameter no a nameToken if (htmlPage.Length < 20) { OscarData oscarData = new OscarData(); string url = "http://www.imdb.com/name/" + htmlPage; htmlPage = oscarData.RequestFile(url); } string startElement = "<div id=\"name-born-info\""; string endElement = "</div>"; // Get DateOfBirth Section int startIndex = 0; int endIndex = 0; int length = 0; startIndex = htmlPage.IndexOf(startElement); endIndex = htmlPage.IndexOf(endElement, startIndex); length = endIndex - startIndex; string refinedDOB = htmlPage.Substring(startIndex, length); startElement = "<time datetime=\""; endElement = "itemprop"; startIndex = refinedDOB.IndexOf(startElement); endIndex = refinedDOB.IndexOf(endElement, startIndex); startIndex += startElement.Length; length = endIndex - startIndex; string resultDOB = refinedDOB.Substring(startIndex, length); resultDOB = OscarsAwardHelper.cleanUpString(resultDOB); string year = resultDOB.Substring(0, 4); string month = resultDOB.Substring(5, 1); string day; try { day = resultDOB.Substring(7, 2); } catch { day = resultDOB.Substring(7, 1); } var dateTime = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day), 0, 0, 0, DateTimeKind.Local); var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var unixDateTime = (dateTime.ToUniversalTime() - epoch).TotalSeconds; return(unixDateTime); }
public static string GetActorsPage(string nameTokenID) { OscarData oscarData = new OscarData(); string url = "http://www.imdb.com/name/" + nameTokenID; string htmlPage = oscarData.RequestFile(url); Debug.WriteLine(htmlPage.Length); if (htmlPage.Length < 100000) { Debug.WriteLine("If statement"); } return(htmlPage); }
/* * This creates a Person then creates the films * It also then makes a request for the user's image * and stores it in the cache * */ public void CreatePersonAndFilm(List <Film> refinedFilms, List <Person> actorNameID, int categorySectionID) { foreach (var actor in actorNameID) { foreach (var film in refinedFilms) { actor.awards.Add(new Award() { categoryID = categorySectionID, filmID = film.FID, filmWebToken = film.webIDToken }); if (DataRepository.allFilms.Find(q => q.webIDToken.Equals(film.webIDToken)) == null) { DataRepository.AddFilm(film); } else { Debug.WriteLine("The film exists"); } } ; actor.DOB = GetDateOfBirthForWinner(actor.nameToken); List <Person> checkIfUserExists = DataRepository.GetAllPersons(); if (checkIfUserExists.Contains(actor) == true) { Debug.WriteLine("The actor exists"); } else { DataRepository.AddPerson(actor); } //Recently Added OscarData od = new OscarData(actor.ID); string htmlPage = OscarsAwardHelper.GetActorsPage(actor.nameToken); string[] profileImageUrl = ImageHelper.GetProfileImageUrl(htmlPage, actor); if (profileImageUrl != null) { od.RequestImage(profileImageUrl); } } }
} // End function public void GetLinksForWinner(Person person) { OscarData oscarData = new OscarData(); List <Person> listOfPerson = new List <Person>(); foreach (var award in person.awards) { string url = "http://www.imdb.com/title/" + award.filmWebToken + "/fullcredits?ref_=tt_cl_sm#cast"; string htmlPage = oscarData.RequestFile(url); List <Person> castMembers = OscarsAwardHelper.ReturnCastForThatFilm(htmlPage); List <Person> oscarWinnerList = DataRepository.GetAllPersons(); int castcounter = 0; int counter = 0; Random rand = new Random(); foreach (var oscarWinner in oscarWinnerList) { foreach (var cast in castMembers) { if (oscarWinner.nameToken.Equals(cast.nameToken) && oscarWinner.name.Equals(cast.name) && oscarWinner.name != person.name) { Person personTemp = DataRepository.FindByPersonByName(oscarWinner.name); // Could do find actor by nameID and and also webTokenID for (int i = 0; i < personTemp.awards.Count; i++) { person.links.Add(new Link() { PersonID = personTemp.ID, filmID = personTemp.awards[i].filmID }); } } else { //Debug.WriteLine("There is no match" + rand.Next()); } } // End of ForEach Loop 3 } // End of ForEach Loop 2 }// End of ForEach loop 1 }// End Method
// One single function called grab winners public void GetWinners(string htmlSection, int categorySectionID, int year) { string startPoint = "<h3>WINNER</h3>"; string endPoint = "<h3>NOMINEES</h3>"; int secondSection; int startIndex = htmlSection.IndexOf(startPoint); if (startIndex == -1) { startIndex = htmlSection.IndexOf("<h3>WINNERS</h3>"); } int endIndex = htmlSection.IndexOf(endPoint, startIndex); if (endIndex == -1) { endIndex = htmlSection.IndexOf("<h3>NOMINEE</h3>", startIndex); } int length = endIndex - startIndex; // This variable contains winners actor name and film name string winnerSection = htmlSection.Substring(startIndex, length); int firstSection = winnerSection.IndexOf("<strong>"); secondSection = winnerSection.IndexOf("</strong>"); int innerLength = secondSection - firstSection; string filmName = winnerSection.Substring(firstSection, innerLength); // There could be more than one film so we need to check List <string> films = ReturnNumberOfFilms(filmName); // FILM array List <Film> refinedFilms = RefineFilmsArray(films, year); if (refinedFilms == null) { Debug.WriteLine("refinedFilms"); } // After we get the name of the Film we also get the Actor name as well int whereToCut = winnerSection.IndexOf("<a", secondSection); int whereToStopCut = winnerSection.IndexOf("</a>", secondSection); int whereToStop = whereToStopCut - whereToCut; string actorName = winnerSection.Substring(whereToCut, whereToStop); // ACTOR array use a simple model first. //Then later on add the model when it has more information to the actorNameID array actorNameID = returnActorNameID(actorName); foreach (var actor in actorNameID) { foreach (var film in refinedFilms) { actor.awards.Add(new Award() { categoryID = categorySectionID, filmID = film.FID, filmWebToken = film.webIDToken }); if (DataRepository.allFilms.Find(q => q.webIDToken.Equals(film.webIDToken)) == null) { DataRepository.AddFilm(film); } else { Debug.WriteLine("The film exists"); } } ; string htmlPage = OscarsAwardHelper.GetActorsPage(actor.nameToken); if (htmlPage.Contains("\"title=\"No photo available.\"") == true) { Debug.WriteLine("Problem"); } actor.DOB = GetDateOfBirthForWinner(htmlPage); // Create a function that gets the Actor's profile image once you have the Image // This array contains the url to the Page [0] // It also contains whether it is a profile or media image [1] // Contains Actor's id as well [2] string[] profileImageUrl = ImageHelper.GetProfileImageUrl(htmlPage, actor); if (profileImageUrl[0].Length < 20 || profileImageUrl[0].Length < 100) { Debug.WriteLine("PROBLEM"); } OscarData od = new OscarData(actor.ID); // If statement is a DEBUG test if (profileImageUrl[1].Equals("media") == true || profileImageUrl == null) { Debug.WriteLine("media items"); } if (profileImageUrl != null) { od.RequestImage(profileImageUrl); } List <Person> checkIfUserExists = DataRepository.GetAllPersons(); if (checkIfUserExists.Contains(actor) == true) { Debug.WriteLine("The actor exists"); } else { DataRepository.AddPerson(actor); } } }
public void GetLinksForWinnersTwo(Person person) { OscarData oscarData = new OscarData(); List <Film> films = DataRepository.GetAllFilms(); foreach (var film in films) // Loop through all of the films { string url = "http://www.imdb.com/title/" + film.webIDToken + "/fullcredits?ref_=tt_cl_sm#cast"; string htmlPage = oscarData.RequestFile(url); List <Person> castMembers = OscarsAwardHelper.ReturnCastForThatFilm(htmlPage); List <Person> oscarWinnerList = DataRepository.GetAllPersons(); // The CastMember list needs to contain the Person even though they might not have won an award // Check that the person is on the film's cast bool containsPerson = false; foreach (var cast in castMembers) // we check the Cast to make sure that the person is on it { if (cast.nameToken.Equals(person.nameToken) && cast.name.Equals(person.name)) { containsPerson = true; } } if (containsPerson == true) { //Check whether any of the cast are oscar winners foreach (var cast in castMembers) { foreach (var oscarWinner in oscarWinnerList) { // Looking for a match between the cast and the oscar winner by name and nameToken // The person who you have passed in; their name should not be matched if (cast.name.Equals(oscarWinner.name) && cast.nameToken.Equals(oscarWinner.nameToken) && person.name != cast.name) { Person personTemp = DataRepository.FindByPersonByName(oscarWinner.name); person.links.Add(new Link() { filmID = film.FID, PersonID = oscarWinner.ID }); /*foreach (var award in personTemp.awards) // iterate over links not awards * { * * person.links.Add(new Link() * { * filmID = film.FID, * PersonID = oscarWinner.ID * * }); * }*/ } } } // End foreach } // End if } // End foreach } // End function