本文整理汇总了C#中RedditSharp.Reddit.GetSubreddit方法的典型用法代码示例。如果您正苦于以下问题:C# Reddit.GetSubreddit方法的具体用法?C# Reddit.GetSubreddit怎么用?C# Reddit.GetSubreddit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedditSharp.Reddit
的用法示例。
在下文中一共展示了Reddit.GetSubreddit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var reddit = new Reddit();
while (reddit.User == null)
{
Console.Write("Username: ");
var username = Console.ReadLine();
Console.Write("Password: ");
var password = ReadPassword();
try
{
Console.WriteLine("Logging in...");
reddit.LogIn(username, password);
}
catch (AuthenticationException)
{
Console.WriteLine("Incorrect login.");
}
}
var subreddit = reddit.GetSubreddit("pokemon");
var posts = subreddit.GetNew();
foreach (var post in posts.Take(25))
Console.WriteLine("/u/{0}: (+{1}-{2}:{3}) {4}", post.AuthorName, post.Upvotes, post.Downvotes, post.Score, post.Title);
Console.ReadKey(true);
}
示例2: Main
static void Main(string[] args)
{
var reddit = new Reddit();
int backDays;
try
{
reddit.User = reddit.LogIn(ModUserName, ModPassword);
_sub = reddit.GetSubreddit(SubReddit);
int.TryParse(ReadBackDays, out backDays);
if(backDays<1)
{
Console.WriteLine("Invalid value for readBackDays in config file. Please enter an integer greater than 0.");
throw new Exception();
}
}
catch
{
Console.WriteLine("Configuration Error. Please confirm values in config file.");
Console.WriteLine("Press Enter to exit.");
Console.Read();
return;
}
while (true)
{
try
{
AssignFlairs(TriggerText, DateTime.Today.AddDays(backDays));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
示例3: Launch
public void Launch()
{
var reddit = new Reddit();
var user = reddit.LogIn("bot_wallpaper", "qwerty");
var subreddit = reddit.GetSubreddit("/r/botwallpaper");
DateTime today = DateTime.Today;
if (today.DayOfWeek == DayOfWeek.Sunday && !sentMessages)
{
using (StreamReader sr = new StreamReader("subreddits.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
SubredditProcessor wallpaper = new SubredditProcessor(
line);
wallpaper.Launch();
}
Console.WriteLine("ServerListener: Created subreddits");
}
sentMessages = true;
}
else if (today.DayOfWeek == DayOfWeek.Monday)
{
sentMessages = false;
}
}
示例4: Launch
public void Launch()
{
List<String> title = new List<string>();
List<String> urls = new List<string>();
string body = "";
var reddit = new Reddit();
var user = reddit.LogIn("bot_wallpaper", "qwerty");
var subreddit = reddit.GetSubreddit("/r/" + _wallpaperType);
foreach (var post in subreddit.GetTop(FromTime.Week).Take(25))
{
if (_resolution == "null")
{
title.Add(post.Title);
urls.Add(post.Url.ToString());
}
else if (post.Title.Contains(_resolution))
{
title.Add(post.Title);
urls.Add(post.Url.ToString());
}
}
for (int i = 0; i < title.Count; i++)
{
body += "[" + title[i] + "](" + urls[i] + ") \n\n";
}
reddit.ComposePrivateMessage("Wallpapers!", "#Here is the top wallpapers of this week in **/r/" + _wallpaperType + "** \n\n" + body + "\n\n I am a bot!", _username, "", "");
Console.WriteLine("UserProcessor: Message sent to " + _username);
}
示例5: Form2
public Form2(Reddit reddit)
{
InitializeComponent();
radioButton1.Checked = true;
this.reddit = reddit;
default_subredit = reddit.FrontPage;
createMainList(listView1, default_subredit, default_subreddit_posts);
bottom_left_subreddit = reddit.GetSubreddit("/r/programming");
createSideList(listView2, bottom_left_subreddit, bottom_left_posts, label1);
bottom_right_subreddit = reddit.GetSubreddit("/r/linux");
createSideList(listView3, bottom_right_subreddit, bottom_right_posts, label2);
updateStatusBarLabels();
}
示例6: 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;
}
示例7: RAOATools
public RAOATools(string modMailSub)
{
try
{
_reddit = new Reddit();
Sub = _reddit.GetSubreddit(modMailSub);
}
catch (Exception)
{
}
}
示例8: Launch
public void Launch()
{
List<String> title = new List<string>();
List<String> urls = new List<string>();
string body = "";
var reddit = new Reddit();
var user = reddit.LogIn("bot_wallpaper", "qwerty");
var wallpaperSubreddit = reddit.GetSubreddit("/r/" + _wallpaperType);
var homeSubreddit = reddit.GetSubreddit("/r/botwallpaper");
foreach (var post in wallpaperSubreddit.GetTop(FromTime.Week).Take(25))
{
title.Add(post.Title);
urls.Add(post.Url.ToString());
}
for (int i = 0; i < title.Count; i++)
{
body += "[" + title[i] + "](" + urls[i] + ") \n\n";
}
DateTime thisDay = DateTime.Today;
homeSubreddit.SubmitTextPost("[" + thisDay.ToString("D") + "] Top /r/" + _wallpaperType, "#Here is the top wallpapers of this week in **/r/" + _wallpaperType + "** \n\n" + body + "\n\n I am a bot!", "", "");
Console.WriteLine("SubredditProcessor: Post submitted to " + homeSubreddit.Name + "with posts of " + wallpaperSubreddit.Name);
}
示例9: Main
static void Main(string[] args)
{
Reddit reddit = null;
var authenticated = false;
try
{
#if DEBUG
reddit = new Reddit("", "", true);
#else
reddit = new Reddit(args[0], args[1], true);
#endif
authenticated = reddit.User != null;
}
catch (AuthenticationException)
{
Console.WriteLine("Incorrect login.");
authenticated = false;
}
if (authenticated)
{
Subreddit dailyProgrammer = reddit.GetSubreddit("dailyprogrammer");
List<PostMetaData> PostDataList = new List<PostMetaData>();
foreach(Post post in dailyProgrammer.Posts)
PostDataList.Add(new PostMetaData(post.Title));
using (StreamWriter writer = new StreamWriter("OutputMarkup.txt"))
{
writer.WriteLine("<table>");
for (int i = PostDataList.Max(a => a.ChallengeNumber); i >= -1; i--)
{
writer.WriteLine(" <tr>");
writer.WriteLine(" <td>Challenge #{0}</td>", i.ToString());
foreach (PostMetaData data in PostDataList.Where(a => a.ChallengeNumber == i).OrderBy(b => b.Difficulty))
{
writer.WriteLine(string.Format(" <td>{0}</td>", data.Title));
}
writer.WriteLine(" </tr>");
}
writer.WriteLine("</table>");
}
}
Console.WriteLine("Processing complete.");
Console.ReadKey();
}
示例10: Index
public ActionResult Index()
{
var reddit = new Reddit();
//var user = reddit.LogIn("EddieValiantsRabbit", "camaro");
var all = reddit.GetSubreddit("/r/news");
var listOfPosts = all.Hot.Take(25);
ViewBag.Posts = new List<RedditSharp.Things.Post>();
ViewBag.Posts = listOfPosts;
ViewBag.Greeting = "Good " + SpareParts.DeterminePartOfDay();
WebRequest weatherRequest = WebRequest.Create(@"http://api.openweathermap.org/data/2.5/weather?zip=94040,us&appid=8b3de9d1132f5c7199d2650d858cef68");
weatherRequest.ContentType = "application/json; charset=utf-8";
WeatherResponse jsonResponse = new WeatherResponse();
using (HttpWebResponse weatherResponse = weatherRequest.GetResponse() as HttpWebResponse)
{
if (weatherResponse.StatusCode != HttpStatusCode.OK)
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).",
weatherResponse.StatusCode,
weatherResponse.StatusDescription));
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(WeatherResponse));
object objResponse = jsonSerializer.ReadObject(weatherResponse.GetResponseStream());
jsonResponse
= objResponse as WeatherResponse;
}
ViewBag.CurrentMonth = SpareParts.GetCurrentMonth(DateTime.Now.Month);
ViewBag.CurrentDayOfMonth = DateTime.Now.Day;
ViewBag.CurrentDayOfWeek = DateTime.Now.DayOfWeek;
ViewBag.CurrentHour = DateTime.Now.Hour;
ViewBag.CurrentMinute = DateTime.Now.Minute;
ViewBag.CurrentSecond = DateTime.Now.Second;
ViewBag.CurrentTemp = (jsonResponse.main.Temp - 273.15) * 1.8 + 32;
ViewBag.WeatherDescription = jsonResponse.weather[0].Description;
return View();
}
示例11: Submit
public static void Submit(string title, string url)
{
try
{
string youtubeTitle = HypeBotYoutube.YoutubeTitle(url);
if (youtubeTitle != null)
{
title = Regex.Replace(title, @"(https?://)?(www.)?(youtu.\S*)", '"' + youtubeTitle + '"');
}
var reddit = new Reddit();
var user = reddit.LogIn(username, password, false);
var sub = reddit.GetSubreddit(subreddit);
sub.SubmitPost(title, url);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
示例12: Main
static void Main(string[] args)
{
/// <summary>
/// Simple reddit bot that replies to comments.
/// </summary>
var reddit = new Reddit();
var user = reddit.LogIn("BotKazy", "thisisapassword");
var subreddit = reddit.GetSubreddit("/r/test");
foreach (var post in subreddit.New.Take(25))
{
Console.WriteLine("THREAD : {0}", post.Title);
if (post.Title == "Test")
{
try
{
foreach (var comment in post.Comments)
{
if (comment.Body.Contains("Kazy") || comment.Body.Contains("kazy"))
if (comment.Author != "BotKazy")
{
using (WebClient client = new WebClient())
{
comment.Reply("[Kazy is a bot](https://play.esea.net/users/727731)");
Thread.Sleep(5000);
//penis
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e.Message);
}
}
}
}
示例13: Main
static void Main(string[] args)
{
var reddit = new Reddit();
while (reddit.User == null)
{
Console.Write("Username: ");
var username = Console.ReadLine();
Console.Write("Password: ");
var password = ReadPassword();
try
{
Console.WriteLine("Logging in...");
reddit.LogIn(username, password);
}
catch (AuthenticationException)
{
Console.WriteLine("Incorrect login.");
}
}
Console.Write("Create post? (y/n) [n]: ");
var choice = Console.ReadLine();
if (!string.IsNullOrEmpty(choice) && choice.ToLower()[0] == 'y')
{
Console.Write("Type a subreddit name: ");
var subname = Console.ReadLine();
var sub = reddit.GetSubreddit(subname);
Console.WriteLine("Making test post");
var post = sub.SubmitTextPost("RedditSharp test", "This is a test post sent from RedditSharp");
Console.WriteLine("Submitted: {0}", post.Url);
}
else
{
var subreddit = Subreddit.GetRSlashAll(reddit);
foreach (var post in subreddit.Posts.Take(10))
Console.WriteLine("\"{0}\" by {1}", post.Title, post.Author);
}
Console.ReadKey(true);
}
示例14: Main
static void Main(string[] args)
{
var auth = new AuthProvider(_clientId, _clientSecret, _redirectUrl);
var _authToken = auth.GetOAuthToken("curiosity_auto", "reddit18");
var reddit = new Reddit(_authToken);
var limit = reddit.RateLimit;
var subreddit = reddit.GetSubreddit("/r/gaming");
foreach (var post in subreddit.New.Take(250))
{
if (post.Title.ToLower().Contains("halo"))
{
if (post.Liked.HasValue && post.Liked.Value)
continue;
post.Upvote();
post.Comment("hell yes");
}
}
}
示例15: Init
static void Init()
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("ScreenshotBot is bootstrapping...");
try
{
reddit = new Reddit();
Reddit.UserAgent = "ScreenshotBot";
ini = new IniFile("sst.ini");
reddit.LogIn(ini.IniReadValue("ACCOUNT", "Username"), ini.IniReadValue("ACCOUNT", "Password"));
var inisub = ini.IniReadValue("BOT", "Subreddit");
if (inisub == "all") sub = Subreddit.GetRSlashAll(reddit);
else sub = reddit.GetSubreddit(inisub);
popular = new BlackList("popular", ini);
www = ini.IniReadValue("BOT", "www");
template = ini.IniReadValue("BOT", "Template");
Work1 = new List<Post>();
Work2 = new List<Post>();
ProcessedURLs = new List<string>();
ThreadPool.QueueUserWorkItem(new WaitCallback(ScreenshotWorker), 1);
ThreadPool.QueueUserWorkItem(new WaitCallback(ScreenshotWorker), 2);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Initialization failure! Error details: \r\n" + ex.ToString());
Console.ReadLine();
return;
}
Console.WriteLine("ScreenshotBot was successfully initialized!\n----------------------------------------------------------\r\n\r\n");
}