private static EdgarFiling Deserialize(string xml) { XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlNodeList nodeList = document.GetElementsByTagName("acession-number"); EdgarFiling efi = null; try { using (var reader = XmlReader.Create(new StringReader(xml))) { XmlSerializer serializer = new XmlSerializer(typeof(EdgarFiling)); efi = (EdgarFiling)serializer.Deserialize(reader); } } catch (Exception ex) { log.Error("Unable to deserialze content.", ex); } return(efi); }
public void Download() { var factory = EdgarFiling.EdgarDownloadFactory(); using (IDbConnection db = factory.OpenDbConnection()) { db.CreateTableIfNotExists <EdgarFiling>(); db.Delete <EdgarFiling>(f => f.Ticker == this._ticker); var filings = this.Filings; if (null != filings) { foreach (SyndicationItem item in filings) { ParseFiling(db, item); } } } }
public EdgarParser(EdgarFiling filing) { _filing = filing; _statementCache = new Dictionary<string, FinancialStatement>(); }
private void ParseFiling(IDbConnection db, SyndicationItem item) { try { // get filing data EdgarFiling filing = EdgarFiling.Deserialize(item.Content); filing.Ticker = this._ticker; // if it's a quarterly or annual report, save info if (null != filing && filing.FilingType == "10-K" || filing.FilingType == "10-Q") { //if (!string.IsNullOrEmpty(filing.FilingDirectory)) if (!string.IsNullOrEmpty(filing.FilingHref)) { // find root directory of each filing //RestClient client = new RestClient(filing.FilingDirectory); RestClient client = new RestClient(filing.FilingHref); var request = new RestRequest(); request.Method = Method.GET; var response = client.Execute(request); string content = response.Content; foreach (LinkItem i in LinkFinder.Find(content)) { //TODO not a beauty if (i.Href.Substring(i.Href.Length - 4, 4) == ".xml") { filing.FileName = i.Text; filing.FilingUrl = "https://www.sec.gov" + i.Href; filing.PathOnDisk = DownloadXml(filing.FilingUrl, DownloadPath(_basePath, _ticker, filing.FileName)); if (!string.IsNullOrEmpty(filing.PathOnDisk)) { db.Insert(filing); } else { ErrorLog.HandleError(this._ticker, "EdgarDownloader", string.Format("Unable to download xml for filing: {0} on ticker {1}", filing.FilingDate, this._ticker)); } //one item is enough break; } } //old //Match match = Regex.Match(content, @"<a href=""([\w]+-[\d]+\.xml)"">[\w]+-[\d]+\.xml</a>", RegexOptions.IgnoreCase); //if (match.Success) //{ // filing.FileName = match.Groups[1].Value; // filing.PathOnDisk = DownloadXml(filing.FilingUrl, DownloadPath(_basePath, _ticker, filing.FileName)); // if (!string.IsNullOrEmpty(filing.PathOnDisk)) // { // db.Insert(filing); // } // else // { // ErrorLog.HandleError(this._ticker, "EdgarDownloader", string.Format("Unable to download xml for filing: {0} on ticker {1}", filing.FilingDate, this._ticker)); // } //} //else //{ // ErrorLog.HandleError(this._ticker, "EdgarDownloader", string.Format("Unable to find xml for filing: {0} on ticker {1}", filing.FilingDate, this._ticker)); //} } else { ErrorLog.HandleError(this._ticker, "EdgarDownloader", string.Format("Unable to find base directory for filing: {0} on ticker {1}", filing.FilingDate, this._ticker)); } } } catch (Exception ex) { log.Error(ex); } }
public EdgarParser(EdgarFiling filing) { _filing = filing; _statementCache = new Dictionary <string, FinancialStatement>(); }