// 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); }
} // 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
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