本文整理汇总了C#中RedditSharp.Reddit.Search方法的典型用法代码示例。如果您正苦于以下问题:C# Reddit.Search方法的具体用法?C# Reddit.Search怎么用?C# Reddit.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedditSharp.Reddit
的用法示例。
在下文中一共展示了Reddit.Search方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImgurLinksFromSubReddit
public async Task<List<ImageLink>> GetImgurLinksFromSubReddit(Reddit reddit, string sub, SearchRange searchRange, Sorting sortOrder, string outputPath, CancellationToken token)
{
token.ThrowIfCancellationRequested();
Subreddit subreddit = null;
var links = new List<ImageLink>();
if (!string.IsNullOrWhiteSpace(sub))
{
try
{
subreddit = reddit.GetSubreddit(sub);
OutputLine($"{subreddit.Name}: Begining Search...");
}
catch (Exception e)
{
OutputLine($"Error connecting to reddit: {e.Message}");
return links;
}
}
if (_filter == null) _filter = string.Empty;
var searchTo = DateTime.Now;
var searchFrom = DateTime.Now;
switch (searchRange)
{
case SearchRange.Today:
searchFrom = searchFrom.AddDays(-1);
break;
case SearchRange.Week:
searchFrom = searchFrom.AddDays(-7);
break;
case SearchRange.Fortnight:
searchFrom = searchFrom.AddDays(-14);
break;
case SearchRange.Month:
searchFrom = searchFrom.AddMonths(-1);
break;
case SearchRange.ThreeMonths:
searchFrom = searchFrom.AddMonths(-3);
break;
case SearchRange.SixMonths:
searchFrom = searchFrom.AddMonths(-6);
break;
}
var search = !string.IsNullOrWhiteSpace(sub)
? searchRange == SearchRange.AllTime ? subreddit?.Search(_filter) : subreddit?.Search(searchFrom, searchTo, sortOrder)
: reddit.Search<Post>(_filter);
token.ThrowIfCancellationRequested();
var listings = search?.GetEnumerator();
links = CombineLinkLists(await GetImagesFromListing(reddit, listings, outputPath, token), links);
return links;
}
示例2: Main
public static void Main(string[] args)
{
string[] contentIds;
var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(File.ReadAllText("config.json"));
using (var cli = new BungieClient(config.BungieApiKey))
{
contentIds = cli.GetAllNews("Destiny", "en").Result
.Where(x => x.properties.Title.StartsWith("Bungie Weekly Update"))
.Select(x => x.contentId)
.ToArray();
}
var reddit = new Reddit();
var me = reddit.LogIn(config.RedditUser, config.RedditPassword);
using (var outStream = File.OpenWrite("results.csv"))
{
using (var writer = new StreamWriter(outStream))
{
foreach (var aid in contentIds)
{
var misses = 0;
foreach (var post in reddit.Search<Post>($"selftext:aid={aid} self:yes subreddit:DestinyTheGame", sortE: Sorting.Top))
{
Console.Write(".");
if (++misses == 10)
return;
try
{
if (!post.IsSelfPost || (post.Title.IndexOf("Bungie Weekly Update", StringComparison.OrdinalIgnoreCase) == -1 && post.Title.IndexOf("Destiny Update", StringComparison.OrdinalIgnoreCase) == -1))
continue;
}
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
{
continue;
}
var scores = new List<double>();
foreach (var comment in post.GetCommentsRecursive())
{
if (string.IsNullOrEmpty(comment.Body))
continue;
scores.Add(i4Ds.LanguageToolkit.SentimentAnalyzer.GetSentiment("en", comment.Body));
}
var line = string.Format("{0:yyyy/MM/dd},{1}", post.CreatedUTC, scores.Average());
writer.WriteLine(line);
Console.WriteLine();
Console.WriteLine(line);
break;
}
}
}
}
}