Esempio n. 1
0
        public static string AddNewLocation(Tuple <float, float> coordinate)
        {
            Location loc = new Location();

            loc.PoIDSource            = WeiboUtilities.GetPoIDSource(null);
            loc.CheckInCount          = 0;
            loc.Url                   = null;
            loc.IntervalMins          = 15;
            loc.LocationSampleMethode = Enums.SampleMethod.All;
            loc.PoID                  = Guid.NewGuid().ToString("N");
            loc.Radius                = 600;
            loc.RefreshStatus         = Enums.CrawlStatus.Stop;
            loc.Lon                   = coordinate.Item1;
            loc.Lat                   = coordinate.Item2;
            loc.CategoryID            = "unknown";
            LocationDBManager.AddNewLocation(loc);
            return(loc.PoID);
        }
Esempio n. 2
0
        public static Tuple <string, float, float> AddNewLocation(dynamic place, string url)
        {
            Location loc = new Location();

            loc.PoIDSource            = WeiboUtilities.GetPoIDSource(url);
            loc.Url                   = url;
            loc.IntervalMins          = 15;
            loc.LocationSampleMethode = Enums.SampleMethod.All;
            loc.PoID                  = Guid.NewGuid().ToString("N");
            loc.Radius                = 600;
            loc.RefreshStatus         = Enums.CrawlStatus.Stop;
            try
            {
                loc.Lat = float.Parse(place.lat);
                loc.Lon = float.Parse(place.lon);
            }
            catch (Exception)
            {
                try
                {
                    loc.Lat = (float)place.lat;
                    loc.Lon = (float)place.lon;
                }
                catch (Exception) { }
            }
            loc.Title    = place.title;
            loc.ClientID = place.poiid;
            try
            {
                if (loc.ClientID != null)
                {
                    WeiboAPI.SetPOIInfo(loc, loc.ClientID);
                }
            }
            catch (Exception) { }
            LocationDBManager.AddNewLocation(loc);
            return(new Tuple <string, float, float>(loc.PoID, loc.Lon, loc.Lat));
        }
Esempio n. 3
0
        /// <summary>
        /// 将新浪返回的动态微博类型转换为本地微博类型(Item)
        /// </summary>
        /// <param name="status">动态类型微博</param>
        /// <param name="source">微博来源</param>
        /// <returns></returns>
        public static Item ConvertToItem(Enums.AuthorSource source, string CrawlID, dynamic status, dynamic user = null, Author author = null)
        {
            Item item = new Item();

            item.CrawlID = CrawlID;
            item.Crawler = ConfigurationManager.AppSettings["ServerLocation"] + CrawlID;

            //设置媒体信息
            WeiboUtilities.SetItemMediaInfo(item);

            try
            {
                #region 抓取任务数据

                item.FetchTime          = DateTime.Now;
                item.UpdateTime         = null;
                item.ContentDetailLevel = Enums.ContentDetailLevel.Weibo;

                #endregion 抓取任务数据

                #region 基础数据
                if (user == null)
                {
                    if (author != null)
                    {
                        item.Url = Utilities.GetItemUrl(author.AuthorID, status.mid);
                    }
                    else
                    {
                        item.Url = Utilities.GetItemUrl(status.user.id, status.mid);
                    }
                }
                else
                {
                    item.Url = Utilities.GetItemUrl(user.id, status.mid);
                }
                if (item.Url == null)
                {
                    item.ItemID = null;
                }
                else
                {
                    item.ItemID = Palas.Common.Utility.MD5Helper.getMd5Hash(item.Url);
                }
                item.ClientItemID = status.id;
                item.CleanTitle   = status.text;
                item.PubDate      = Utilities.ParseToDateTime(status.created_at);
                item.Location     = null;
                string checkinUrl = null;
                try
                {
                    checkinUrl = Utilities.GetCheckInUrl(status.text);
                }
                catch (Exception) { }

                LocationDBManager.SetPoIDAndCoordinate(item, status, checkinUrl);

                if (user == null)
                {
                    if (author != null)
                    {
                        item.AuthorName         = author.AuthorName;
                        item.AuthorID           = author.AuthorID;
                        item.AuthorCertificated = author.Certification;
                        item.Source             = status.source;
                        item.AuthorImg          = author.AuthorImg;
                    }
                    else
                    {
                        item.AuthorName         = status.user.name;
                        item.AuthorID           = status.user.id;
                        item.AuthorCertificated = Utilities.GetCertificationType(status.user.verified_type, status.user.verified);
                        item.Source             = status.source;
                        item.AuthorImg          = status.user.profile_image_url;
                    }
                }
                else
                {
                    item.AuthorName         = user.name;
                    item.AuthorID           = user.id;
                    item.AuthorCertificated = Utilities.GetCertificationType(user.verified_type, user.verified);
                    item.Source             = status.source;
                    item.AuthorImg          = user.profile_image_url;
                }
                try
                {
                    item.AttachImg = status.original_pic;
                }
                catch (Exception) { }
                #endregion

                #region Item跟踪
                item.CurrentCount = new ItemCountData(DateTime.Now);
                try
                {
                    item.CurrentCount.ForwardCount = int.Parse(status.reposts_count);
                    item.CurrentCount.ReplyCount   = int.Parse(status.comments_count);
                }
                catch (Exception) { }
                item.CountHistory    = new ItemCountData[1];
                item.CountHistory[0] = item.CurrentCount;
                WeiboUtilities.SetItemTrackingRule(item, source);
                #endregion Item跟踪
                try
                {
                    if (status.retweeted_status != null)
                    {
                        Item tmp = ConvertToItem(status.retweeted_status, source, CrawlID);
                        if (tmp.ItemID != null)
                        {
                            InsertOrUpdateItem(tmp);
                        }
                        item.ParentItemID = tmp.ItemID;
                    }
                }
                catch (Exception) { }
            }
            catch (Exception) {  }
            return(item);
        }
Esempio n. 4
0
        public static void SetPoIDAndCoordinate(Item item, dynamic status, string checkinUrl)
        {
            item.PoIDSource = WeiboUtilities.GetPoIDSource(checkinUrl);
            if (!WeiboUtilities.IsPOISourceInWhiteList(item.PoIDSource))
            {
                item.PoID = item.PoIDSource = null;
                return;
            }
            //情形一,有POID
            try
            {
                foreach (var anno in status.annotations)
                {
                    Tuple <string, float, float> tupe = LocationDBManager.GetPoIDAndCoordinateViaClientID(anno.place.poiid);
                    if (tupe == null)
                    {
                        tupe = AddNewLocation(anno.place, checkinUrl);
                    }
                    if (tupe != null)
                    {
                        item.PoID = tupe.Item1;
                        item.Lon  = tupe.Item2;
                        item.Lat  = tupe.Item3;
                        return;
                    }
                }
            }
            catch (Exception) { }

            #region 尝试获取坐标
            Tuple <float, float> coordinate = null;
            try
            {
                foreach (var anno in status.annotations)
                {
                    //从wpinfo获取坐标
                    coordinate = Utilities.GetCoordinateViaWPInfo(anno.wpinfo);
                }
            }
            catch (Exception) { }
            if (coordinate == null)
            {
                try
                {
                    //从GEO获取坐标
                    coordinate = Utilities.GetCoordinateViaGEO(status.geo);
                }
                catch (Exception) { }
            }
            if (coordinate == null)
            {
                try
                {
                    //尝试解析签到链接获取url
                    coordinate = Utilities.GetCoordinateViaUrl(checkinUrl);
                }
                catch (Exception) { }
            }
            #endregion

            if (coordinate != null)
            {
                item.Lon = coordinate.Item1;
                item.Lat = coordinate.Item2;
            }

            //有checkinUrl
            if (checkinUrl != null)
            {
                var tupe = GetPoIDAndCoordinateViaUrl(checkinUrl);
                if (tupe == null)
                {
                    tupe = AddNewLocation(coordinate, checkinUrl);
                }
                if (tupe != null)
                {
                    item.PoID = tupe.Item1;
                    item.Lon  = tupe.Item2;
                    item.Lat  = tupe.Item3;
                }
                return;
            }

            //只有坐标
            if (coordinate != null)
            {
                item.PoID = GetPoIDViaCoordinate(coordinate.Item1, coordinate.Item2);
                if (item.PoID == null)
                {
                    item.PoID = AddNewLocation(coordinate);
                }
                return;
            }

            //什么都没有
            item.PoID = item.PoIDSource = null;
        }