You have no items in your shopping cart.

Profile: fabio.parigi

Avatar
Statistics

    Where i can found the url of main image?
    I have only a thumb of 200px
    I try to modify the config thumb image.... but nothing work
    Please help

    Fabio

    9 years ago

    Support wrote:

    you will have the problem with images.
    I tested imports and ...
    First image in RSS message is a left conner of the css frame...


    The GetFirstImageUrl method I post checks if the image is bigger than 50x50, is that left corner so big??
    You can increase size limit if you think it's too low.
    9 years ago

    The message has been truncated without any warning... Here is the end of the class:


    public static string GetFirstImageUrl(string htmlContent)
            {
                if (string.IsNullOrEmpty(htmlContent)) return null;

                HTMLDocument doc = new HTMLDocument();
                IHTMLDocument2 doc2 = (doc as IHTMLDocument2);
                doc2.write(htmlContent as object);

                IHTMLElementCollection imgs = doc.getElementsByTagName("img");
                int i = 0;
                while (true)
                {
                    IHTMLElement img = imgs.item(i);
                    if (img != null)
                    {
                        string ImageUrl = img.getAttribute("src") as string;
                        Stream str = null;
                        HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(ImageUrl);
                        HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
                        str = wRes.GetResponseStream();

                        var imageOrig = System.Drawing.Image.FromStream(str);
                        int height = imageOrig.Height;
                        int width = imageOrig.Width;
                        if (height > 50 && width > 50)
                        {
                            return ImageUrl;
                        }
                        else
                        {
                            i++;
                            continue;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                return null;
            }

            public static bool IsRilevant(SyndicationItem item)
            {
                return IsRilevant(item.Title) || IsRilevant(item.Summary) || IsRilevant(item.Content as TextSyndicationContent);
            }
            public static bool IsRilevant(TextSyndicationContent textContent)
            {
                if (textContent == null) return false;
                else return IsRilevant(textContent.Text);
            }
            public static bool IsRilevant(string text)
            {
                if (text == null) return false;
                return text.ToLower().Contains("keyword");
            }
        }
    }
    9 years ago

    This is my class. The method you need to retrieve the image is GetFirstImageUrl(string)


    [code]
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using RSSImporter.Model;
    using System.ServiceModel.Syndication;
    using System.Xml;
    using mshtml;
    using System.Net;
    using System.Drawing;
    using System.IO;

    namespace RSSImporter
    {
        public class Importer
        {
            private SharedLibrary.ILogger Logger
            {
                get { return SharedLibrary.LoggerManager.GetLogger(RSSImporter); }
            }

            public void ReadAll()
            {
                int siteCounter = 0;
                int totalArticleCounter = 0;
                foreach (RSSProvider site in DBContext.RSSProviders)
                {
                    try
                    {
                        XmlReader reader = XmlReader.Create(site.RssUrl);
                        SyndicationFeed feed = SyndicationFeed.Load(reader);

                        Logger.Info(string.Format("Start reading feed {0}.", site.Name));

                        int articleCounter = 0;
                        foreach (SyndicationItem item in feed.Items)
                        {
                            if (!site.Hidden && (site.DontFilter || IsRilevant(item)))
                            {
                                string url = item.Links.First().Uri.AbsoluteUri;
                  
                  // Look if I've already downloaded it before...
                                FeedArticle news = site.FeedArticles.SingleOrDefault(no => no.Url.Equals(url));
                  
                  // ... If Not
                                if (news == null)
                                {
                                    articleCounter++;
                                    totalArticleCounter++;

                                    news = new FeedArticle();
                                    news.Site = site;
                                    news.Title = item.Title.Text;
                                    news.DateTime = item.PublishDate.DateTime;
                                    news.Text = item.Summary.Text;
                                    news.Url = url;
                                    var textContent = (item.Content as TextSyndicationContent);
                                    if (textContent != null)
                                    {
                                        news.ImageUrl = GetFirstImageUrl(textContent.Text);
                                    }

                                    site.FeedArticles.Add(news);
                                }
                            }
                        }

                        Logger.Info(string.Format("End reading feed {0}. Imported {1} new articles", site.Name, articleCounter));

                        siteCounter++;
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorException(string.Format("Error reading feed {0}.", site.Name), ex);
                    }

                }

                DBContext.SaveChanges();
                Logger.Info(string.Format("End feed reading process. Read {0} articles from {1} feeds.", totalArticleCounter, siteCounter));
            }

            public static string GetFirstImageUrl(string htmlContent)
            {
                if (string.IsNullOrEmpty(htmlContent)) return null;

                HTMLDocument doc = new HTMLDocument();
                IHTMLDocument2 doc2 = (doc as IHTMLDocument2);
                doc2.write(htmlContent as object);

                IHTMLElementCollection imgs = doc.getElementsByTagName("img");
                int i = 0;
                while (true)
                {
                    IHTMLElement img = imgs.item(i);
                    if (img != null)
                    {
                        string ImageUrl = img.getAttribute("src") as string;
                        Stream str = null;
                        HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(ImageUrl);
                        HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
                        str

    9 years ago

    P.S. Yes I want to automatically search for new articles from a pre-filled list of rss feed.

    9 years ago

    Don't you know there are already classes for parsing rss built in .NET framework? You have just to reference System.ServiceModel assembly.

    Some time ago I developed an analog procedure for another application, but I'm not able to do it for NopCommerce.

    For images I made a method that inspect the html of the article body and finds the first img tag that contains a useful image.

    If you wish I can post the class responsible for reading rss feeds.

    9 years ago

    Hi I don't understand what do you mean.
    What I need to do is find a way for read external rss and automatic create new Noparticle and put its in a particular category

    tell me if you can make it in nop article or like you tell me a month ago create a new module that make this

    thanks a lot for your support
    Fabio

    9 years ago

    Hi Any news about the rss support?
    thanks
    Fabio

    9 years ago

    Hi .... how can I know when ll be ready?

    9 years ago

    thanks for your support
    when do you think to make it?
    thanks
    Fabio

    9 years ago

    Powered by nopCommerce

    Copyright © 2023 FoxNetSoft. All rights reserved