当前位置: 首页>>代码示例>>C#>>正文


C# Reddit.GetUser方法代码示例

本文整理汇总了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();
//.........这里部分代码省略.........
开发者ID:W1R3D-Code,项目名称:RedditRip,代码行数:101,代码来源:RedditRip.cs


注:本文中的RedditSharp.Reddit.GetUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。