Skip to content

Instantly share code, notes, and snippets.

@SnowyYANG
Created October 21, 2023 11:54
Show Gist options
  • Save SnowyYANG/ce9ca29bb225557ff20cf5befa71d83a to your computer and use it in GitHub Desktop.
Save SnowyYANG/ce9ca29bb225557ff20cf5befa71d83a to your computer and use it in GitHub Desktop.
检查符文工房4中文百科留言板是否有新留言
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Forms;
namespace CheckClient
{
class Program
{
static string lastId;
static void Main(string[] args)
{
try
{
using (var sr = new StreamReader("lastId.txt"))
lastId = sr.ReadLine();
}
catch
{
lastId = "";
}
var timer = new System.Threading.Timer(onTick, null, TimeSpan.Zero, TimeSpan.FromHours(1));
while (true) Console.ReadKey();
}
private static void onTick(Object o)
{
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://snowyyang.com/rfwiki/QandA?a=check");
// access req.Headers to get/set header values before calling GetResponse.
// req.CookieContainer allows you access cookies.
var response = req.GetResponse();
string webcontent;
using (var strm = new StreamReader(response.GetResponseStream()))
{
webcontent = strm.ReadToEnd();
}
req.Abort();
if (!int.TryParse(webcontent, out _)) MessageBox.Show("Error");
else if (lastId != webcontent)
{
lastId = webcontent;
using (var sw = new StreamWriter("lastId.txt")) sw.WriteLine(lastId);
MessageBox.Show("New");
}
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment