public User GetUser(string userName) { string str = string.Concat("https://m.twitter.com/", userName); string source = WebUtil.GetSource(str); string source1 = WebUtil.GetSource(string.Concat(str, "/favorites")); User user = new User() { IsProtected = source.Contains("<div class='protected'>"), FullName = Regex.Match(source, "(?<=<div class=\"fullname\">).*(?=\\s*<\\/div>)").Value, UserName = Regex.Match(source, "(?<=<span class=\"screen-name\">).*(?=\\s*<\\/span>)").Value, Location = Regex.Match(source, "(?<=<div class=\"location\">).*(?=\\s*<\\/div>)").Value, Bio = StripTags(Regex.Match(source, "(?<=<div class=\"bio\">\\s*<div class=\"dir-ltr\" dir=\"ltr\">\\s*).*(?=\\s*<\\/div>)").Value.Trim()), AvatarUrl = string.Concat(Regex.Match(source, "(?<=<td class=\"avatar\">\\s*<img alt=\".*?\" src=\")[\\s\\S]*?(?=_normal)").Value, ".jpg"), TweetCount = Regex.Match(source, "(?<=<div class=\"statnum\">)[0-9,KM]*(?=<\\/div>\\s*<div class=\"statlabel\"> Tweets <\\/div>)").Value, FollowingCount = Regex.Match(source, "(?<=<div class=\"statnum\">)[0-9,KM]*(?=<\\/div>\\s*<div class=\"statlabel\"> Following <\\/div>)").Value, FollowerCount = Regex.Match(source, "(?<=<div class=\"statnum\">)[0-9,KM]*(?=<\\/div>\\s*<div class=\"statlabel\"> Followers <\\/div>)").Value }; if (!user.IsProtected) { user.TweetList = GetTweetList(userName, 0, source); user.FollowingList = GetFollowList(userName, "following"); user.FollowerList = GetFollowList(userName, "followers"); user.FavoriteList = GetFavoriteList(userName, 0, source1); user.FavoriteCount = Regex.Match(source1, "(?<=<span class=\"count\">)[0-9,KM]*(?=<\\/span>)").Value; } return user; }
private void ArchiveUser(User user) { string path = Path.Combine(paths["archives"], user.UserName); IOUtil.CreateDirectory(path); Console.WriteLine("Writing to {0}", path); string json = JsonConvert.SerializeObject(user, Formatting.Indented); string fileName = String.Format("\\{0}_{1}.json", user.UserName, GetTimestamp()); IOUtil.WriteToFile(path + fileName, json); }
private void PrintUserStats(User user) { PrintName(user); Console.WriteLine(user.AvatarUrl); Console.WriteLine("Location: {0}", user.Location); Console.WriteLine("Bio: {0}", user.Bio); Console.WriteLine("{0} Following", user.FollowingCount); Console.WriteLine("{0} Followers", user.FollowerCount); Console.WriteLine("{0} Favorites", user.FavoriteCount); Console.WriteLine("Protected account: {0}", user.IsProtected); }
private void PrintName(User user) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("@{0}", user.UserName); Console.ResetColor(); Console.WriteLine(user.FullName); }
private List<User> ParseListOfUsers(string source) { List<User> users = new List<User>(); foreach (Match match in Regex.Matches(source, "<td class=\"info fifty screenname\">[\\s\\S]*?<\\/td>")) { User user = new User() { UserName = Regex.Match(match.Value, "(?<=<a name=\").*(?=\"\\/)").Value, FullName = Regex.Match(match.Value, "(?<=<strong class=\"fullname\">).*(?=<\\/strong>)").Value }; users.Add(user); } return users; }