From c96f770306378a34b1e3fd970c4a6554b07d03cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F?= Date: Sat, 18 Jul 2020 19:16:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=81=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ Program.cs | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5401d92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/bin +/obj +/out +/.vs \ No newline at end of file diff --git a/Program.cs b/Program.cs index b743db7..1bc48a3 100644 --- a/Program.cs +++ b/Program.cs @@ -16,13 +16,19 @@ class Program { private static readonly HttpClient client = new HttpClient(); - private static int index = 1; - static async Task Main() { try - { //微博用户Id(此处放的是我个人的微博Id,已经注销,无法再导出,需要替换成你自己的) - string userId = "223417235"; + { + ; + Console.WriteLine($"{getGodString()}******************************苦海无边.回头是岸******************************\n********欢迎使用,请输入微博ID,如:223417235(非微博昵称),Enter键确认********"); + //微博用户Id + string userId = Console.ReadLine(); + while (String.IsNullOrWhiteSpace(userId)) + { + Console.WriteLine("*****************************不得为空,请重新输入*****************************"); + userId = Console.ReadLine(); + } List weiboList = await getWeiboList(userId); if (weiboList != null && weiboList.Count > 0) { @@ -59,15 +65,19 @@ static async Task Main() } string end = "## 终章·从前过往,皆为序章\n有一种落差,是你配不上上自己的野心,也辜负了所受的苦难。\n\n事情总会忽然发生,而理由则是后来才会察觉的。\n\n往日情怀酿做酒,换你余生长醉不复忧。\n\n如果你忘了来时的路,那你注定会迷路。"; await WriteToMarkdown(end); - Console.WriteLine("导出完毕........"); + Console.WriteLine("导出完毕........,请在文档目录下查看‘Weibo.md’文件,点击任意键结束程序"); + Console.ReadKey(); + } + else + { + Console.WriteLine("导出失败........,点击任意键结束程序"); + Console.ReadKey(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } - - } public async static Task writeContent(dynamic weibo, string userName, string publishAt) @@ -119,11 +129,8 @@ public async static Task writeContent(dynamic weibo, string userName, string pub { sb.Append($"\n\n![]({(string)weibo.page_info.page_pic.url})"); } - else - { - Console.WriteLine("无图"); - } sb.Append("\n\n\n\n\n\n"); + Console.WriteLine("写入一条数据......"); await WriteToMarkdown(sb.ToString()); } @@ -177,16 +184,12 @@ static async Task> getWeiboList(string userId) Weibo weibo = new Weibo(item.mblog); weiboList.Add(weibo); db.Weibos.Add(weibo); - if (db.SaveChanges() > 0) - { - Console.WriteLine("1条存库成功"); - } + db.SaveChanges(); } } containerId = (string)weiboListObj.data.cardlistInfo.containerid; sinceId = (string)weiboListObj.data.cardlistInfo.since_id; url += $"&since_id="; - index = 1; while (true) { responseBody = await getRequest(url + sinceId); @@ -208,10 +211,7 @@ static async Task> getWeiboList(string userId) Weibo weibo = new Weibo(item.mblog); weiboList.Add(weibo); db.Weibos.Add(weibo); - if (db.SaveChanges() > 0) - { - Console.WriteLine("1条存库成功"); - } + db.SaveChanges(); } } containerId = (string)weiboListObj.data.cardlistInfo.containerid; @@ -251,8 +251,7 @@ static async Task getRequest(string url) if (response.StatusCode.Equals(HttpStatusCode.OK)) { responseBody = await response.Content.ReadAsStringAsync(); - index++; - Console.WriteLine(index + "次抓取成功...."); + Console.WriteLine("本次抓取成功...."); return responseBody; } reTry++; @@ -263,5 +262,9 @@ static async Task getRequest(string url) } + static string getGodString() + { + return "||=========================================================================||\n|| _oo8oo_ ||\n|| o8888888o ||\n|| 88\" . \"88 ||\n|| (| -_- |) ||\n|| 0\\ = /0 ||\n|| ___/'==='\\___ ||\n|| .' \\\\| |// '. ||\n|| / \\\\||| : |||// \\ ||\n|| / _||||| -:- |||||_ \\ ||\n|| | | \\\\\\ - /// | | ||\n|| | \\_| ''\\---/'' |_/ | ||\n|| \\ .-\\__ '-' __/-. / ||\n|| ___'. .' /--.--\\ '. .'___ ||\n|| .\"\" '< '.___\\_<|>_/___.' >' \"\". ||\n|| | | : `- \\`.:`\\ _ /`:.`/ -` : | | ||\n|| \\ \\ `-. \\_ __\\ /__ _/ .-` / / ||\n|| =====`-.____`.___ \\_____/ ___.`____.-`===== ||\n|| `= ---=` ||\n||=========================================================================||\n"; + } } }