Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdThunder11 committed Mar 22, 2020
1 parent dd1c3d2 commit 1d10de2
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 14 deletions.
17 changes: 9 additions & 8 deletions AdnmbBackup-gui/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 89 additions & 6 deletions AdnmbBackup-gui/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void button1_Click(object sender, EventArgs e)
var fpjson = JsonConvert.DeserializeObject<JObject>(str);
var replyCount = int.Parse(fpjson["replyCount"].ToString());
int pageCount = replyCount / 19;
if (replyCount / pageCount != 0) pageCount++;
if (replyCount % pageCount != 0) pageCount++;
JArray contentJA = fpjson["replys"].ToObject<JArray>();
for (var page = 2; page <= pageCount; page++)
{
Expand Down Expand Up @@ -91,6 +91,7 @@ private void button1_Click(object sender, EventArgs e)
index--;
}
}
label4.Text = "完成";
fpjson["replys"].Replace(contentJA);
var fjsonstr = JsonConvert.SerializeObject(fpjson, Formatting.Indented);
File.WriteAllText(path, fjsonstr);
Expand Down Expand Up @@ -122,17 +123,17 @@ static void ConvertToText(string path)
var ja = jo["replys"].ToObject<JArray>();
for (int i = 0; i < ja.Count; i++)
{
sb.Append("------------------------------"); sb.Append(Environment.NewLine);
sb.Append("----------------------------------------"); sb.Append(Environment.NewLine);
sb.Append(ja[i]["userid"].ToString()); sb.Append(" "); sb.Append(ja[i]["now"].ToString());
sb.Append(" No."); sb.Append(ja[i]["id"].ToString()); sb.Append(Environment.NewLine);
sb.Append(ContentProcess(ja[i]["content"].ToString())); sb.Append(Environment.NewLine);
}
File.WriteAllText(path.Replace("json", "txt"), sb.ToString());
var lines = File.ReadAllLines(path.Replace("json", "txt"));
for (var i = 0; i < lines.Length; i++)
{
lines[i] = lines[i].Trim();
}
//for (var i = 0; i < lines.Length; i++)
//{
// lines[i] = lines[i].Trim();
//}
File.WriteAllLines(path.Replace("json", "txt"), lines);
}
static string ContentProcess(string content)
Expand All @@ -156,5 +157,87 @@ static string ReadGzip(byte[] bytes)
}
return result;
}

private void Form1_Shown(object sender, EventArgs e)
{
if (File.Exists("AtuobBackupList.txt"))
{
if (!File.Exists("cookie.txt"))
{
MessageBox.Show("请先放好小饼干");
return;
}
int errCount = 0;
if (!Directory.Exists(DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString()))
Directory.CreateDirectory(DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString());
var cookie = File.ReadAllText("cookie.txt");
var ids = File.ReadAllLines("AtuobBackupList.txt");
foreach (var id in ids)
{
try
{
string path = Path.Combine(DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString(), id + ".json");
if (File.Exists(path)) continue;
string url = "https://nmb.fastmirror.org/Api/thread";
CookieContainer cookieContainer = new CookieContainer();
cookieContainer.Add(new Cookie("userhash", cookie, "/", "nmb.fastmirror.org"));
HttpClientHandler handler = new HttpClientHandler() { UseCookies = true };
handler.CookieContainer = cookieContainer;
HttpClient http = new HttpClient(handler);
http.DefaultRequestHeaders.Add("Host", "nmb.fastmirror.org");
http.DefaultRequestHeaders.Add("Accept", "application/json");
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36 HavfunClient-AdnmbBackup");
label4.Text = ">>" + id + " 正在获取第1页";
var t = http.GetAsync(url + "?id=" + id + "&page=1");
t.Wait();
var result = t.Result;
var t2 = result.Content.ReadAsByteArrayAsync();
t2.Wait();
var bytes = t2.Result;
var str = ReadGzip(bytes);
var fpjson = JsonConvert.DeserializeObject<JObject>(str);
var replyCount = int.Parse(fpjson["replyCount"].ToString());
int pageCount = replyCount / 19;
if (replyCount % pageCount != 0) pageCount++;
JArray contentJA = fpjson["replys"].ToObject<JArray>();
for (var page = 2; page <= pageCount; page++)
{
label4.Text = ">>" + id + " 正在获取第" + page + "";
t = http.GetAsync(url + "?id=" + id + "&page=" + page);
t.Wait();
result = t.Result;
t2 = result.Content.ReadAsByteArrayAsync();
t2.Wait();
bytes = t2.Result;
str = ReadGzip(bytes);
var jo = JsonConvert.DeserializeObject<JObject>(str);
JArray ja = jo["replys"].ToObject<JArray>();
var rpcount = ja.Count;
for (int j = 0; j < rpcount; j++)
{
contentJA.Add(ja[j]);
}
}
for (var index = 0; index < contentJA.Count; index++)
{
if (contentJA[index]["title"].ToString() == "广告")
{
contentJA.RemoveAt(index);
index--;
}
}
fpjson["replys"].Replace(contentJA);
var fjsonstr = JsonConvert.SerializeObject(fpjson, Formatting.Indented);
File.WriteAllText(path, fjsonstr);
ConvertToText(path);
}
catch
{
errCount++;
}
}
label4.Text = "已完成自动备份,有" + errCount + "个串的备份存在错误";
}
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# AdnmbBackup-gui
一个让你本地备份A岛串的小程序
[饼干获取教程](https://www.coldthunder11.com/artical/%e6%95%99%e7%a8%8b/%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96a%e5%b2%9b%e7%9a%84%e9%a5%bc%e5%b9%b2/)
支持批量自动备份,在程序目录下新建AtuobBackupList.txt将需要自动备份的串号填入(一行一个),每天第一次打开会自动备份
需要.net framework4.8

0 comments on commit 1d10de2

Please sign in to comment.