本文整理汇总了C#中RedditSharp.Reddit.GetUser方法的典型用法代码示例。如果您正苦于以下问题:C# Reddit.GetUser方法的具体用法?C# Reddit.GetUser怎么用?C# Reddit.GetUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedditSharp.Reddit
的用法示例。
在下文中一共展示了Reddit.GetUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImagesFromListing
private async Task<List<ImageLink>> GetImagesFromListing(Reddit reddit, IEnumerator<Post> listing, string outputPath, CancellationToken token)
{
var erroCount = 0;
var posts = new List<Post>();
var links = new List<ImageLink>();
var users = new HashSet<string>();
var processedUsers = new HashSet<string>();
try
{
while (listing.MoveNext())
{
token.ThrowIfCancellationRequested();
Console.WriteLine();
for (var i = 0; i < _perSubThreadLimit; i++)
{
if (_allAuthorsPosts)
{
if (!users.Contains(listing.Current.AuthorName) && !processedUsers.Contains(listing.Current.AuthorName))
{
OutputLine($"Adding user to batch: {listing.Current.AuthorName}", true);
users.Add(listing.Current.AuthorName);
i = users.Count - 1;
}
}
else
{
if (!listing.Current.Domain.Contains("imgur.com") || (!_nsfw && listing.Current.NSFW) || (_onlyNsfw && !listing.Current.NSFW))
{
var suffix = listing.Current.NSFW ? " NSFW" : listing.Current.Url.DnsSafeHost;
OutputLine($"Skipping non-imgur link: {listing.Current.Url} ({suffix})", true);
continue;
}
posts.Add(listing.Current);
}
if (!listing.MoveNext())
break;
}
foreach (var user in users)
{
token.ThrowIfCancellationRequested();
OutputLine($"Getting all posts for user: {user}", true);
var userPosts = reddit.GetUser(user).Posts.OrderByDescending(post => post.Score).Where(post => post.Url.DnsSafeHost.Contains("imgur.com"));
if (_onlyNsfw)
userPosts = userPosts.Where(x => x.NSFW);
if (!_nsfw)
userPosts = userPosts.Where(x => !x.NSFW);
foreach (var userPost in userPosts)
{
token.ThrowIfCancellationRequested();
if (posts.Exists(x => x.Url == userPost.Url) || links.Exists(x => x.Url == userPost.Url.ToString())) continue;
posts.Add(userPost);
}
processedUsers.Add(user);
}
users = new HashSet<string>();
OutputLine($"Batch returned: {posts.Count} posts.", true);
var subName = string.Empty;
for (var i = 0; i < posts.Count; i = i + _perSubThreadLimit)
{
var tasks = new List<Task>();
for (var j = 0; j < _perSubThreadLimit; j++)
{
if (posts.Count <= (i + j))
break;
var post = posts[i + j];
tasks.Add(GetImgurImageOrAlbumFromUrl(post, outputPath, token));
}
Task.WaitAll(tasks.ToArray());
links = tasks.Cast<Task<List<ImageLink>>>().Aggregate(links, (current, task) => CombineLinkLists(task.Result, current));
if (string.IsNullOrWhiteSpace(subName))
subName = links.First()?.Post.SubredditName;
OutputLine($"Total Links found in {subName}: {links.Count()}");
}
posts = new List<Post>();
}
}
catch (IndexOutOfRangeException e)
{
return links;
}
catch (Exception e)
{
if (e is OperationCanceledException || e is AggregateException)
{
throw new OperationCanceledException();
//.........这里部分代码省略.........