public void AddDoubanConfig(string groupId, string cityName) { if (string.IsNullOrEmpty(groupId) || string.IsNullOrEmpty(cityName)) { throw new Exception("请输入豆瓣小组Group和城市名称。"); } var topics = DoubanService.GetHouseData(groupId, cityName, 1); if (topics == null) { throw new Exception("保存失败!请检查豆瓣小组ID(如:XMhouse)/城市名称(如:厦门)是否正确..."); } var cityInfo = $"{{ 'groupid':'{groupId}','cityname':'{cityName}','pagecount':5}}"; var doubanConfig = new CrawlerConfig(); if (doubanConfig != null) { return; } var config = new CrawlerConfig() { ConfigurationKey = 0, ConfigurationValue = cityInfo, ConfigurationName = ConstConfigName.Douban, DataCreateTime = DateTime.Now, IsEnabled = true, }; _dapper.Insert(config); return; }
public void AddDoubanConfig(string groupId, string cityName) { if (string.IsNullOrEmpty(groupId) || string.IsNullOrEmpty(cityName)) { throw new Exception("请输入豆瓣小组Group和城市名称。"); } var topics = DoubanService.GetHouseData(groupId, cityName, 1); if (topics == null) { throw new Exception("保存失败!请检查豆瓣小组ID(如:XMhouse)/城市名称(如:厦门)是否正确..."); } var json = $"{{ 'groupid':'{groupId}','cityname':'{cityName}','pagecount':5}}"; if (_dataContext.Configs.Any(c => c.City == cityName && c.Source == ConstConfigName.Douban && c.Json == json)) { return; } var config = new DBConfig() { Id = Tools.GetUUId(), Json = json, City = cityName, Source = ConstConfigName.Douban, CreateTime = DateTime.Now, PageCount = 10 }; _dataContext.Configs.Add(config); _dataContext.SaveChanges(); return; }