コード例 #1
0
 public static string GetXmlAttributeValue(XParseElement node, string attName)
 {
     if (node != null)
     {
         XParseAttribute att = node.Attribute(XParseName.Get(attName));
         if (att != null)
         {
             return(att.Value);
         }
     }
     return(string.Empty);
 }
コード例 #2
0
ファイル: SecEdgarDownloader.cs プロジェクト: adamshe/wget
        protected override PositionChangeDataPointAggregate ConvertResult(string contentStr, string ticker = "")
        {
            string         startPattern     = "<table class=\"tableFile\" summary=\"Document Format Files\">";
            string         endPattern       = "</table>";
            int            startIndex       = contentStr.IndexOfOccurence(startPattern, 1);
            int            endIndex         = contentStr.IndexOf(endPattern, startIndex);
            string         normalizeContent = contentStr.Substring(startIndex, endIndex - startIndex + endPattern.Length);
            XParseDocument doc = MyHelper.ParseXmlDocument(normalizeContent);

            XParseElement resultNode = XPath.GetElement("//table/tr[3]/td[3]/a", doc);

            var xmlLink   = resultNode.Attribute("href").Value;
            var xmlResult = ParseForm4(GetSecPath(xmlLink));
            var aggregate = new PositionChangeDataPointAggregate(xmlResult);

            aggregate.PopulatePoints();
            Console.WriteLine(xmlResult);
            ////*[@id="formDiv"]/div/table/tbody/tr[3]/td[3]/a
            return(aggregate);
        }
コード例 #3
0
        internal PortfolioInfoResult ConvertHtml(XParseDocument doc)
        {
            XParseElement        resultsNode = XPath.GetElement("//div[@id=\"yfi-main\"]/div/div[2]/form/div/table/tbody", doc);
            List <PortfolioInfo> lst         = new List <PortfolioInfo>();

            if (resultsNode != null)
            {
                foreach (XParseElement trNode in resultsNode.Elements())
                {
                    XParseElement a = XPath.GetElement("/td[2]/a", trNode);
                    if (a != null)
                    {
                        string          name = a.Value;
                        XParseAttribute att  = a.Attribute(XParseName.Get("href"));
                        if (att != null)
                        {
                            string id = att.Value.Split(';')[0].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[1];
                            lst.Add(new PortfolioInfo(name, id));
                        }
                    }
                }
            }
            return(new PortfolioInfoResult(lst.ToArray()));
        }
コード例 #4
0
        protected override BondScreenerResult ConvertResult(ConnectionInfo connInfo, System.IO.Stream stream, SettingsBase settings)
        {
            List <BondScreenerData> results = new List <BondScreenerData>();

            System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");
            XParseDocument doc = MyHelper.ParseXmlDocument(stream);

            XParseElement[] resultsNodes = XPath.GetElements("//results", doc);
            if (resultsNodes.Length == 1)
            {
                XParseElement resultsNode = resultsNodes[0];
                foreach (XParseElement trNode in resultsNode.Elements())
                {
                    XParseAttribute classAtt = trNode.Attribute(XParseName.Get("class"));
                    if (classAtt != null)
                    {
                        if (classAtt.Value == "yfnc_tabledata1")
                        {
                            BondScreenerData res = new BondScreenerData();
                            int index            = 0;
                            foreach (XParseElement tdNode in trNode.Elements())
                            {
                                switch (index)
                                {
                                case 0:
                                    XParseElement fontNode = null;    //tdNode.FirstNode;
                                    switch (fontNode.Value)
                                    {
                                    case "Treas":
                                        res.Type = BondType.Treasury;
                                        break;

                                    case "Zero":
                                        res.Type = BondType.TreasuryZeroCoupon;
                                        break;

                                    case "Corp":
                                        res.Type = BondType.Corporate;
                                        break;

                                    case "Muni":
                                        res.Type = BondType.Municipal;
                                        break;
                                    }
                                    break;

                                case 1:
                                    XParseElement aNode = null;     // tdNode.FirstNode.FirstNode;
                                    fontNode = null;
                                    //fontNode = tdNode.LastNode.FirstNode;
                                    res.Issue = new Link(fontNode.Value.Replace("\n", ""), new Uri("http://reports.finance.yahoo.com" + aNode.Attribute(XParseName.Get("href")).Value));
                                    break;

                                case 2:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    double t;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.Price = t;
                                    }
                                    break;

                                case 3:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.CouponInPercent = t;
                                    }
                                    break;

                                case 4:
                                    XParseElement nobrNode = null;    // tdNode.FirstNode.FirstNode.FirstNode;
                                    DateTime      d;
                                    if (System.DateTime.TryParseExact(nobrNode.Value, "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d))
                                    {
                                        res.Maturity = d;
                                    }
                                    break;

                                case 5:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.YieldToMaturityInPercent = t;
                                    }
                                    break;

                                case 6:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.CurrentYieldInPercent = t;
                                    }
                                    break;

                                case 7:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode;
                                    foreach (Rating r in Enum.GetValues(typeof(Rating)))
                                    {
                                        if (r.ToString() == fontNode.Value)
                                        {
                                            res.FitchRating = r;
                                            break;     // TODO: might not be correct. Was : Exit For
                                        }
                                    }

                                    break;

                                case 8:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode;
                                    res.Callable = Convert.ToBoolean((fontNode.Value == "Yes" ? true : false));
                                    break;
                                }
                                index += 1;
                            }
                            results.Add(res);
                        }
                    }
                }
            }
            return(new BondScreenerResult(results.ToArray()));
        }
コード例 #5
0
        internal Portfolio ConvertHtmlDoc(XParseDocument doc)
        {
            if (doc != null)
            {
                List <IID>              lstIDs     = new List <IID>();
                PortfolioInfo           ownPf      = null;
                List <PortfolioInfo>    portfolios = new List <PortfolioInfo>();
                List <PortfolioDataRow> dt         = new List <PortfolioDataRow>();
                string selectedView = string.Empty;
                List <PortfolioColumnType> lstColumns     = new List <PortfolioColumnType>();
                List <PortfolioColumnType> lstViewColumns = new List <PortfolioColumnType>();
                List <string> views    = new List <string>();
                XParseElement mainNode = XPath.GetElement("//div[@id=\"yfi-main\"]", doc);
                if (mainNode != null)
                {
                    XParseElement portfoliosNode = XPath.GetElement("/div[@class=\"yfi_dropdown_select\"]/div[@class=\"bd\"]/form/div/select", mainNode);
                    if (portfoliosNode != null)
                    {
                        foreach (XParseElement childNode in portfoliosNode.Elements())
                        {
                            if (childNode.Name.LocalName == "option" && childNode.HasElements)
                            {
                                string id   = childNode.Attribute(XParseName.Get("value")).Value;
                                string name = childNode.Value;
                                portfolios.Add(new PortfolioInfo(name, id));
                                if (childNode.Attribute(XParseName.Get("selected")) != null && childNode.Attribute(XParseName.Get("selected")).Value == "selected")
                                {
                                    ownPf = portfolios[portfolios.Count - 1];
                                }
                            }
                        }
                    }

                    XParseElement[] viewNodes = XPath.GetElements("/div[@class=\"yfi_tablist\"]/div/ul/li", mainNode);
                    if (viewNodes.Length > 0)
                    {
                        foreach (XParseElement viewNode in viewNodes)
                        {
                            if (!viewNode.Value.Contains("Detailed") && !viewNode.Value.Contains("Add Custom View"))
                            {
                                views.Add(viewNode.Value);
                                if (XPath.GetElement("/strong", viewNode) != null)
                                {
                                    selectedView = viewNode.Value;
                                }
                            }
                        }
                    }

                    XParseElement tableNode = XPath.GetElement("/div[@class=\"yfi_module yfi-quotes-table\"]/div[2]/table", mainNode);
                    if (tableNode != null)
                    {
                        XParseElement[] columnCells = XPath.GetElements("/thead/tr/th", tableNode);

                        foreach (XParseElement thNode in columnCells)
                        {
                            XParseAttribute colNameAtt = thNode.Attribute(XParseName.Get("class"));
                            if (colNameAtt != null && colNameAtt.Value.StartsWith("col-"))
                            {
                                string colName = colNameAtt.Value.Split(' ')[0].Replace("col-", "");
                                Nullable <PortfolioColumnType> colType = this.GetColumnType(colName);

                                if (colType != null)
                                {
                                    int subColumnCount = Convert.ToInt32(thNode.Attribute(XParseName.Get("colspan")).Value);
                                    if (subColumnCount == 1)
                                    {
                                        lstColumns.Add(colType.Value);
                                        lstViewColumns.Add(colType.Value);
                                    }
                                    else
                                    {
                                        Nullable <PortfolioColumnType>[] addCT = new Nullable <PortfolioColumnType> [subColumnCount];
                                        switch (colType)
                                        {
                                        case PortfolioColumnType.change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.change; addCT[1] = PortfolioColumnType.percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.change_and_percent);
                                            break;

                                        case PortfolioColumnType.time:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.time; addCT[1] = PortfolioColumnType.price;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.price_and_time);
                                            break;

                                        case PortfolioColumnType.day_low:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.day_low; addCT[1] = PortfolioColumnType.day_high;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.day_range);
                                            break;

                                        case PortfolioColumnType.day_value_change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.day_value_change; addCT[1] = PortfolioColumnType.day_value_percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.day_value_change_and_percent);
                                            break;

                                        case PortfolioColumnType.fiftytwo_week_low:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.fiftytwo_week_low; addCT[1] = PortfolioColumnType.fiftytwo_week_high;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.fiftytwo_week_range);
                                            break;

                                        case PortfolioColumnType.pre_mkt_time:
                                            PortfolioColumnType t = PortfolioColumnType.pre_mkt_price_and_time;
                                            if (subColumnCount >= 2)
                                            {
                                                addCT[0] = PortfolioColumnType.pre_mkt_time; addCT[1] = PortfolioColumnType.pre_mkt_price;
                                            }
                                            if (subColumnCount == 4)
                                            {
                                                addCT[2] = PortfolioColumnType.after_mkt_time; addCT[3] = PortfolioColumnType.after_mkt_price; t = PortfolioColumnType.pre_after_mkt_price_and_time;
                                            }
                                            lstViewColumns.Add(t);
                                            break;

                                        case PortfolioColumnType.after_mkt_time:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.after_mkt_time; addCT[1] = PortfolioColumnType.after_mkt_price;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.pre_after_mkt_price_and_time);
                                            break;

                                        case PortfolioColumnType.pre_mkt_change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.pre_mkt_change; addCT[1] = PortfolioColumnType.pre_mkt_percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.pre_mkt_change_and_percent);
                                            break;

                                        case PortfolioColumnType.after_mkt_change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.after_mkt_change; addCT[1] = PortfolioColumnType.after_mkt_percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.after_mkt_change_and_percent);
                                            break;

                                        case PortfolioColumnType.holdings_gain:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.holdings_gain; addCT[1] = PortfolioColumnType.holdings_percent_gain;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.holdings_gain_and_percent);
                                            break;
                                        }

                                        for (int i = 0; i < addCT.Length; i++)
                                        {
                                            if (addCT[i] != null)
                                            {
                                                lstColumns.Add(addCT[i].Value);
                                            }
                                            else
                                            {
                                                System.Diagnostics.Debug.WriteLine(colName);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        XParseElement[] tableCells = XPath.GetElements("/tbody/tr", tableNode);
                        foreach (XParseElement trNode in tableCells)
                        {
                            XParseElement[] enm = MyHelper.EnumToArray(trNode.Elements());
                            if (enm.Length > 0)
                            {
                                PortfolioDataRow r = new PortfolioDataRow();
                                for (int i = 0; i < enm.Length; i++)
                                {
                                    XParseElement   tdNode     = enm[i];
                                    XParseAttribute colNameAtt = tdNode.Attribute(XParseName.Get("class"));
                                    if (colNameAtt != null && colNameAtt.Value.StartsWith("col-"))
                                    {
                                        XParseElement[] tdEnm   = MyHelper.EnumToArray(tdNode.Elements());
                                        string          colName = colNameAtt.Value.Split(' ')[0].Replace("col-", "");
                                        if (i < lstColumns.Count && lstColumns[i].ToString() == colName &&
                                            colName != "delete" &&
                                            (tdNode.Attribute(XParseName.Get("class")) != null && !tdNode.Attribute(XParseName.Get("class")).Value.StartsWith("col-delete")) &&
                                            tdEnm.Length > 0 && tdEnm[0].Name.LocalName == "span" && tdEnm[0].Attribute(XParseName.Get("class")) != null && tdEnm[0].Attribute(XParseName.Get("class")).Value == "wrapper")
                                        {
                                            string cellTxt = tdNode.Value;
                                            r[lstColumns[i]] = cellTxt;
                                            if (lstColumns[i] == PortfolioColumnType.symbol)
                                            {
                                                lstIDs.Add(new SimpleID(cellTxt));
                                            }
                                        }
                                    }
                                }
                                dt.Add(r);
                            }
                        }
                    }
                }

                return(new Portfolio(ownPf, lstIDs.ToArray(), dt.ToArray(), selectedView, views.ToArray(), lstColumns.ToArray(), lstViewColumns.ToArray(), portfolios.ToArray()));
            }
            else
            {
                return(null);
            }
        }