// Download comic, votey, etc static void SaveAssets(Comic one) { // Comic string comicFilename = ComicName.Replace("{name}", one.ComicFilename); web.DownloadFile(one.ComicURL, comicFilename); Log("Downloaded comic"); // Votey string voteyFilename = VoteyName.Replace("{name}", one.VoteyFilename); web.DownloadFile(one.VoteyURL, voteyFilename); Log("Downloaded votey"); // Info string jsonFilename = JsonName.Replace("{id}", one.ID.ToString()).Replace("{url}", one.ShortURL); File.WriteAllText(jsonFilename, one.ToJSON()); Log("Saved JSON info"); }
// Convert the page to a Comic object static Comic ParseComicPage(int id, string text, string url, DateTime lastDate, int forThisDate) { Comic one = new Comic(); Log("f: " + forThisDate.ToString(), 4); // Comic ID one.ID = id; Log("ID: " + id); // Fetch date one.fetch_date = DateTime.Now; // Page URL one.URL = url; Log("URL: " + url); // Published date MatchCollection matches = publishedDateRegex.Matches(text); Log("PublishedDate match count - " + matches.Count, 3); one.PublishedDate = VoidDate; if (matches.Count == 0) { Error("No PublishedDate"); } else { one.PublishedDate = DateTime.Parse(matches[0].Groups[1].Value + " " + matches[0].Groups[2].Value); Log("PublishedDate: " + one.PublishedDate.ToString("yyyy-MM-dd_HH-mm")); } // For This Date Log("a " + lastDate.ToString(), 4); Log("a " + one.PublishedDate.Date.ToString(), 4); Log("a " + (lastDate != one.PublishedDate.Date).ToString(), 4); Log("a " + forThisDate, 4); if (lastDate != one.PublishedDate.Date) { one.ForThisDate = 1; } else { // TODO: review, I don't track the logic but +1 is necessary one.ForThisDate = forThisDate + 1; } Log("ForThisDate: " + one.ForThisDate, 1); //Console.ReadKey(); // Next URL matches = nextURLRegex.Matches(text); Log("NextURL match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No NextURL"); } else { one.NextURL = matches[0].Groups[1].Value; Log("NextURL - " + one.NextURL, 2); } // Short URL matches = shortURLRegex.Matches(url); Log("ShortURL match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No ShortURL"); } else { one.ShortURL = matches[0].Groups[1].Value; Log("ShortURL - " + one.ShortURL, 2); } // Title matches = titleRegex.Matches(text); Log("Title match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No Title"); } else { one.Title = matches[0].Groups[1].Value; Log("Title - " + one.Title, 2); } // CLick URL, Title Text, and Comic URL matches = comicRegex.Matches(text); Log("Comic match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No Comic"); } else { // Click URL one.ClickURL = matches[0].Groups[1].Value; Log("ClickURL - " + one.ClickURL, 2); // Title Text one.TitleText = matches[0].Groups[2].Value; Log("TitleText - " + one.TitleText, 2); // Comic URL one.ComicURL = matches[0].Groups[3].Value; Log("ComicURL - " + one.ComicURL, 2); } // Comic Filename matches = comicNameRegex.Matches(one.ComicURL); Log("ComicFilename match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No ComicFilename"); } else { one.ComicFilename = matches[0].Groups[1].Value; Log("ComicFilename - " + one.ComicFilename, 2); } // Votey matches = voteyRegex.Matches(text); Log("Votey match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No Votey"); } else { one.VoteyURL = matches[0].Groups[1].Value; Log("VoteyURL - " + one.VoteyURL, 2); } // Votey Filename matches = comicNameRegex.Matches(one.VoteyURL); Log("VoteyFilename match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No VoteyFilename"); } else { one.VoteyFilename = matches[0].Groups[1].Value; Log("VoteyFilename - " + one.VoteyFilename, 2); } // Buy A Print URL matches = buyAPrintRegex.Matches(text); Log("BuyAPrintURL match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No BuyAPrintURL"); } else { one.BuyAPrintURL = matches[0].Groups[1].Value; Log("BuyAPrintURL - " + one.BuyAPrintURL, 2); } // Today's News Title matches = todaysNewsTitleRegex.Matches(text); Log("TodaysNewsTitle match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No TodaysNewsTitle"); } else { one.TodaysNewsTitle = matches[0].Groups[1].Value; Log("TodaysNewsTitle - " + one.TodaysNewsTitle, 2); } // Today's News Content matches = todaysNewsContentRegex.Matches(text); Log("TodaysNewsContent match count - " + matches.Count, 3); if (matches.Count == 0) { Error("No TodaysNewsContent"); } else { one.TodaysNewsContent = matches[0].Groups[1].Value; Log("TodaysNewsContent - " + one.TodaysNewsContent, 2); } return(one); }