public static IReadOnlyList <IAFile> GetItemThumbnailFiles( this IAItem @this) { return(IAFileInterpreter.ScrapeArchiveThumbnailFiles(@this) .Where(t => t.FilePathUrl.EndsWith(".jpg")) .ToArray()); }
public static string GetItemDownloadPageUrl( this IAItem @this) { return($"https://www.archive.org/" + $"download/" + $"{@this.Identifier}/"); }
public void TestGetItem() { IAItem item = userMethods.GetItem(1); var expected = 1; var actual = item.PartNo; Assert.True(expected.Equals(actual)); }
public void CreateItemTest() { IFactory factory = new Factory(); List <string> mockData = new List <string>() { "7", "testpart", "I AM A TEST PART", "7.77", "7.77", "../" }; IAItem expected = new AItem(mockData, new ConsoleLogger()); IAItem actual = factory.CreateItem(mockData, new ConsoleLogger()); Assert.True(expected.PartDescription.Equals(actual.PartDescription)); }
public virtual void DeepCopyIn( IAItem item, IAItemGetter rhs, ErrorMaskBuilder?errorMask, TranslationCrystal?copyMask, bool deepCopy) { base.DeepCopyIn( (IOblivionMajorRecord)item, (IOblivionMajorRecordGetter)rhs, errorMask, copyMask, deepCopy: deepCopy); }
public static IEnumerable <IAFile> ScrapeArchiveFiles( IAItem internetArchiveItem) { var context = BrowsingContext.New( Configuration.Default.WithDefaultLoader()); var downloadPageUrl = internetArchiveItem.GetItemDownloadPageUrl(); using (var document = context .OpenAsync(downloadPageUrl) .GetAwaiter() .GetResult()) { var maincontent = document .GetElementById("maincontent"); var container = maincontent .GetElementsByClassName("container-ia") .First(); var directoryListing = container .GetElementsByClassName("download-directory-listing") .First(); var tbody = directoryListing .GetElementsByTagName("tbody") .First(); var fileNodeList = tbody .GetElementsByTagName("tr") .Skip(1); var itemIndex = 0; foreach (var fileNode in fileNodeList) { var fileLinkElement = fileNode .GetElementsByTagName("td") .First() .GetElementsByTagName("a") .First(); var fileLinkPath = fileLinkElement .GetAttribute("href"); var fileTitle = fileLinkElement .TextContent; var fileDate = fileNode .GetElementsByTagName("td") .Skip(1) .First() .TextContent; var fileSize = fileNode .GetElementsByTagName("td") .Skip(2) .First() .TextContent; var fileKind = DetermineIAFileKind(fileTitle); //var airDate = DetermineArchiveFileAirDate( // postShowStr) // .GetValueOrDefault(); var approximateBytes = DetermineArchiveFileSizeBytes(fileSize); if (!DateTime.TryParseExact( fileDate, "dd-MMM-yyyy ss:mm", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out var lastModifiedDate)) { throw new FormatException( $"Cannot parse dateTime from string {fileDate.Quote()}."); } yield return(new IAFile( internetArchiveItem, fileLinkPath, fileKind, fileTitle, lastModifiedDate, approximateBytes, itemIndex)); itemIndex++; } } }
public static IReadOnlyList <IAFile> GetItemFiles( this IAItem @this) { return(IAFileInterpreter.ScrapeArchiveFiles(@this) .ToArray()); }
private IARoot GetInstantArticleCount(int maxDays, int maxEntries) { EntryCollection entries = null; //We only build the entries if blogcore doesn't exist and we'll need them later... if (dataService.GetLastEntryUpdate() == DateTime.MinValue) { entries = BuildEntries(null, maxDays, maxEntries); } //Try to get out as soon as possible with as little CPU as possible if (inASMX) { DateTime lastModified = SiteUtilities.GetLatestModifedEntryDateTime(dataService, entries); if (SiteUtilities.GetStatusNotModified(lastModified)) { return(null); } } if (inASMX) { string referrer = Context.Request.UrlReferrer != null ? Context.Request.UrlReferrer.AbsoluteUri : ""; if (ReferralBlackList.IsBlockedReferrer(referrer)) { if (siteConfig.EnableReferralUrlBlackList404s) { return(null); } } else { loggingService.AddReferral( new LogDataItem( Context.Request.RawUrl, referrer, Context.Request.UserAgent, Context.Request.UserHostName)); } } //not-modified didn't work, do we have this in cache? string CacheKey = string.Format("InstantArticle:{0}:{1}", maxDays, maxEntries); IARoot documentRoot = cache[CacheKey] as IARoot; if (documentRoot == null) //we'll have to build it... { //However, if we made it this far, the not-modified check didn't work, and we may not have entries... if (entries == null) { entries = BuildEntries(null, maxDays, maxEntries); } documentRoot = new IARoot(); documentRoot.Namespaces.Add("content", "http://purl.org/rss/1.0/modules/content/"); IAChannel ch = new IAChannel(); ch.Title = siteConfig.Title; ch.Link = SiteUtilities.GetBaseUrl(siteConfig); if (siteConfig.Description == null || siteConfig.Description.Trim().Length == 0) { ch.Description = siteConfig.Subtitle; } else { ch.Description = siteConfig.Description; } ch.PubDate = DateTime.UtcNow.ToString(); ch.LastBuildDate = DateTime.UtcNow.ToString(); if (siteConfig.RssLanguage != null && siteConfig.RssLanguage.Length > 0) { ch.Language = siteConfig.RssLanguage; } //generator ch.Docs = string.Empty; documentRoot.Channels.Add(ch); foreach (Entry entry in entries) { if (entry.IsPublic == false || entry.Syndicated == false) { continue; } IAItem item = new IAItem(); List <XmlElement> anyElements = new List <XmlElement>(); XmlDocument xmlDoc = new XmlDocument(); item.Title = entry.Title; item.PubDate = entry.CreatedUtc.ToString("R"); if (ch.LastBuildDate == null || ch.LastBuildDate.Length == 0) { ch.LastBuildDate = item.PubDate; } item.Link = SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)entry); item.Guid = entry.EntryId; if (!siteConfig.AlwaysIncludeContentInRSS && entry.Description != null && entry.Description.Trim().Length > 0) { item.Description = PreprocessItemContent(entry.EntryId, entry.Description); } else { item.Description = ContentFormatter.FormatContentAsHTML(PreprocessItemContent(entry.EntryId, entry.Content)); } XmlElement contentEncoded = xmlDoc.CreateElement("content", "encoded", "http://purl.org/rss/1.0/modules/content/"); string encData = string.Format("<!doctype html>" + "<html lang=\"en\" prefix=\"op: http://media.facebook.com/op#\">" + "<head>" + "<meta charset=\"utf-8\">" + "<link rel=\"canonical\" href=\"{3}\">" + "<meta property=\"op:markup_version\" content=\"v1.0\">" + "</head>" + "<body><article>" + "<header>{0}</header>" + "{1}" + "<footer>{2}</footer>" + "</article></body></html>", entry.Title, ContentFormatter.FormatContentAsHTML(PreprocessItemContent(entry.EntryId, entry.Content)), string.Empty, item.Link); XmlCDataSection cdata = xmlDoc.CreateCDataSection(encData); contentEncoded.AppendChild(cdata); anyElements.Add(contentEncoded); item.anyElements = anyElements.ToArray(); ch.Items.Add(item); } cache.Insert(CacheKey, documentRoot, DateTime.Now.AddMinutes(5)); } return(documentRoot); }
public void RemapLinks(IAItem obj, IReadOnlyDictionary <FormKey, FormKey> mapping) { base.RemapLinks(obj, mapping); }