private static bool UpdateData() { WeiboData myData = new WeiboData(); Console.WriteLine("please input Data ID:"); long checkdata; if (long.TryParse(Console.ReadLine(), out checkdata)) { myData = GetInputData(); myData.weiboID = checkdata; if (dataService.UpdateData(myData)) { Console.WriteLine("Update success"); return(true); } else { Console.WriteLine("Update failed"); return(false); } } else { Console.WriteLine("please input Data ID here, such as 10008"); return(false); } }
public IList <WeiboData> GetData() { List <WeiboData> weiboDataList = new List <WeiboData>(); if (ConnectServer()) { SqlCommand command = new SqlCommand(QueryProcedureName, Connection); command.CommandType = CommandType.StoredProcedure; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { WeiboData currentData = new WeiboData(); currentData.weiboID = int.Parse(reader[0].ToString()); currentData.WeiboDescription = reader[1].ToString(); currentData.ImageUrl = reader[2].ToString(); currentData.CreatedBy = reader[3].ToString(); currentData.CreatedOn = Convert.ToDateTime(reader[4]); currentData.LikeRate = int.Parse(reader[5].ToString()); weiboDataList.Add(currentData); } reader.Close(); } Connection.Close(); Connection.Dispose(); return(weiboDataList); }
private void CommandAddParameter(SqlCommand command, WeiboData data, params SqlParameter[] additionalParams) { foreach (var sqlParam in ConstructParams(data)) { command.Parameters.Add(sqlParam); } foreach (var sqlParam in additionalParams) { command.Parameters.Add(sqlParam); } }
private IEnumerable <SqlParameter> ConstructParams(WeiboData data) { var sqlParams = new List <SqlParameter> () { ConstructSqlParameter("@weiboDescription", SqlDbType.NVarChar, data.WeiboDescription, 140), ConstructSqlParameter("@imageUrl", SqlDbType.NVarChar, data.ImageUrl, 380), ConstructSqlParameter("@createdBy", SqlDbType.NVarChar, data.CreatedBy, 40), ConstructSqlParameter("@createdOn", SqlDbType.DateTime, data.CreatedOn), ConstructSqlParameter("@likerate", SqlDbType.Int, data.LikeRate) }; return(sqlParams); }
/// <summary> /// 开始 /// </summary> public void Start() { WeiboData data = new WeiboData(); Weibo weibo = data.GetUserWeiboData(this.Nick); string content = string.Empty; string index = string.Empty; //获取订单编号 string tradeId = utils.GetValueByPropertyNum(this.Msg, "tid"); switch (this.Status) { case "ItemUpshelf": content = weibo.ContentUp; index = "1"; break; case "TradeCreate": content = weibo.ContentSell; ItemInfo.ID = GetItemId(tradeId); index = "2"; break; case "TradeRated": content = weibo.ContentReview; ItemInfo.ID = GetItemId(tradeId); index = "3"; break; case "ItemRecommendAdd": content = weibo.ContentRecommend; index = "4"; break; } string imgUrl = string.Empty; //如果卖家没有设置则退出 if (content.Length == 0) { Console.Write(Nick + "-还没有设置微博自动发送的信息...\r\n"); return; } content = ChangeTag(content, this.ItemInfo, ref imgUrl); SendWeiboMsg(Nick, content, imgUrl, index); }
public bool UpdateData(WeiboData updateData) { if (ConnectServer()) { var command = new SqlCommand(UpdateProcedureName, Connection) { CommandType = CommandType.StoredProcedure }; CommandAddParameter(command, updateData, ConstructSqlParameter("@weiboID", SqlDbType.BigInt, updateData.weiboID)); return(ExecuteQuery(command)); } return(false); }
public bool InsertData(WeiboData addData) { if (ConnectServer()) { var command = new SqlCommand(InsertProcedureName, Connection) { CommandType = CommandType.StoredProcedure }; CommandAddParameter(command, addData, ConstructSqlParameter("@weiboID", SqlDbType.BigInt, null, -1, ParameterDirection.Output)); return(ExecuteQuery(command)); } return(false); }
private static WeiboData GetInputData() { WeiboData myData = new WeiboData(); Console.WriteLine("please input description:"); myData.WeiboDescription = Console.ReadLine(); Console.WriteLine("Please input the imageUrl"); myData.ImageUrl = Console.ReadLine(); Console.WriteLine("Please input the Author"); myData.CreatedBy = Console.ReadLine(); myData.CreatedOn = DateTime.Now; return(myData); }
/* /api/data/id */ public WeiboData GetWeiboById(int id) { var weiboData = new WeiboData(); foreach (var currentdata in weiboDataList) { if (currentdata.weiboID == id) { weiboData = currentdata; break; } } if (weiboData == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(weiboData); }
/// <summary> /// 发送微博消息 /// </summary> /// <param name="Nick"></param> /// <param name="content"></param> private void SendWeiboMsg(string nick, string content, string imgUrl, string index) { WeiboData data = new WeiboData(); List <WeiboID> weiboids = data.GetUserWeiboIDS(nick); for (int i = 0; i < weiboids.Count; i++) { if (data.IsCanSendMsg(nick, weiboids[i], index)) { Console.Write("sending...\r\n"); utils uti = new utils(); uti.SendMicroBlog(nick, content, imgUrl, weiboids[i].Key, weiboids[i].Secret); //记录发送数量 data.UpdateWeiboNum(nick, index); //记录发送日志 data.InsertWeiboSendLog(nick, weiboids[i], content, index); } } }
// 获取指定目标中的所有微博评论,如果指定了目标ID,则只获取指定目标ID的评论 public WeiboData getTotalComments( string url, string selfId, string friendId) { cc = cc0; WeiboData weiboData = new WeiboData(); List<string> commentEntities = getTotalCommentEntities(cc, url, startPage, endPage); // 得到微博评论入口 // 遍历入口得到所有评论 foreach (var entity in commentEntities) { Console.Write("[" + threadName + "]评论入口:" + entity + " "); int n = 0; int maxCommentPage = 0; for (int i = 1; i <= (maxCommentPage == 0 ? 2 : maxCommentPage); i++) { string content = ""; try { content = SpiderHelper.RequestHttpGetWithCookie(entity + "&page=" + i, cc); } catch (Exception e) { Console.Write(e.Message); continue; } // 查找评论的最大页码 if (maxCommentPage == 0) { Match regMaxCommentPage = Regex.Match(content, "/([0-9]+)页</div>"); if (regMaxCommentPage.Length > 0) { maxCommentPage = int.Parse(regMaxCommentPage.Groups[1].Value); } maxCommentPage = maxCommentPage > 10 ? 10 : maxCommentPage; // 评论超过 10 页,应该也是大V没错,惹不起 } // // 评论示例:<a href="/u/1990224584?st=9771">目标用户</a>:<span class="ctt">哈哈,眼熟吧</span> // .*? 这种写法是因为c#的正则表达式匹配默认是贪婪模式,默认匹配最多字符,用这个可以禁止贪婪模式 string regstr = "<a href=\"/u/([0-9]+).*?\">(.*?)</a>.*?<span class=\"ctt\">.*?</span>"; MatchCollection mc = Regex.Matches(content, regstr, RegexOptions.Compiled | RegexOptions.IgnoreCase); if (mc.Count == 0) { cc = (cc == cc0) ? cc1 : cc0; // COOKIE已经被检测到异常,换一个COOKIE继续 } foreach (Match m in mc) { WeiboComment comment = new WeiboComment(); comment.userid = m.Groups[1].Value; string s = m.Value.Replace("</span>", ""); int k = s.LastIndexOf('>'); comment.comment = s.Substring(k + 1, s.Length - k - 1); comment.username = m.Groups[2].Value; n++; if (friendId == null) { // 此时是获取博主自身的 weiboData.comments.Add(comment); if (!comment.userid.Equals(selfId)) { // 有新的好友 WeiboUser friend; weiboData.friends.TryGetValue(comment.userid, out friend); if (friend == null) { friend = new WeiboUser(); friend.userid = comment.userid; friend.url = "http://weibo.cn/u/" + friend.userid + "?page="; friend.username = comment.username; weiboData.friends.Add(friend.userid, friend); } friend.count++; } continue; } else { // 此时是获取博主好友的,就只保存博主和好友说过的 if (comment.userid.Equals(selfId)) // || comment.userid.Equals(friendId)) { weiboData.comments.Add(comment); } } } } Console.WriteLine(n + " 条评论"); } return weiboData; }