• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

将棋ウォーズ棋譜を検索条件を指定して一括でダウンロードする。


コミットメタ情報

リビジョン4 (tree)
日時2015-01-26 20:56:35
作者bellyoshi

ログメッセージ

変更サマリ

差分

--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.Designer.vb (revision 3)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.Designer.vb (revision 4)
@@ -34,7 +34,6 @@
3434 Me.txtSaveDirectory = New System.Windows.Forms.TextBox()
3535 Me.btnSelectDirectory = New System.Windows.Forms.Button()
3636 Me.btnDownload = New System.Windows.Forms.Button()
37- Me.txtDebug = New System.Windows.Forms.TextBox()
3837 Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog()
3938 Me.GroupBox1.SuspendLayout()
4039 Me.SuspendLayout()
@@ -153,20 +152,11 @@
153152 Me.btnDownload.Text = "ダウンロード"
154153 Me.btnDownload.UseVisualStyleBackColor = True
155154 '
156- 'txtDebug
157- '
158- Me.txtDebug.Location = New System.Drawing.Point(8, 208)
159- Me.txtDebug.Multiline = True
160- Me.txtDebug.Name = "txtDebug"
161- Me.txtDebug.Size = New System.Drawing.Size(382, 300)
162- Me.txtDebug.TabIndex = 6
163- '
164155 'frmCondtion
165156 '
166157 Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
167158 Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
168- Me.ClientSize = New System.Drawing.Size(402, 520)
169- Me.Controls.Add(Me.txtDebug)
159+ Me.ClientSize = New System.Drawing.Size(402, 179)
170160 Me.Controls.Add(Me.btnDownload)
171161 Me.Controls.Add(Me.btnSelectDirectory)
172162 Me.Controls.Add(Me.txtSaveDirectory)
@@ -195,7 +185,6 @@
195185 Friend WithEvents txtSaveDirectory As System.Windows.Forms.TextBox
196186 Friend WithEvents btnSelectDirectory As System.Windows.Forms.Button
197187 Friend WithEvents btnDownload As System.Windows.Forms.Button
198- Friend WithEvents txtDebug As System.Windows.Forms.TextBox
199188 Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
200189
201190 End Class
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.vb (revision 3)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.vb (revision 4)
@@ -1,9 +1,5 @@
11 Public Class frmCondtion
22
3- Private baseUrl As String = "http://swks.sakura.ne.jp/wars/kifusearch/"
4- Private csrfmiddlewaretoken As String
5- Private downloadLists As IList(Of aLink)
6- Dim cc As System.Net.CookieContainer
73
84 Private Sub btnDownload_Click(sender As System.Object, e As System.EventArgs) Handles btnDownload.Click
95 If txtSaveDirectory.Text = String.Empty Then
@@ -20,115 +16,21 @@
2016 Not rbAnimal.Checked Then
2117 MessageBox.Show("対局モードを選択してください。")
2218 End If
23- LoginReq()
24- ListPageReadReq()
25- DownloadsReq()
2619
27- End Sub
20+ Dim frm As New frmProgress
21+ Dim downloder As New downloder(
22+ frm.BackgroundWorker1,
23+ txtSaveDirectory.Text,
24+ txtName1.Text,
25+ txtName2.Text,
26+ GetGTypeValue())
27+ frm.downLoder = downloder
28+ frm.ShowDialog()
2829
29- Private Sub LoginReq()
30-
31- cc = New System.Net.CookieContainer()
32-
33- Dim webreq As System.Net.HttpWebRequest = _
34- System.Net.WebRequest.Create(baseUrl)
35- webreq.CookieContainer = cc
36- Dim webres As System.Net.WebResponse = webreq.GetResponse()
37- Dim st As System.IO.Stream = webres.GetResponseStream()
38-
39- Dim sr As New System.IO.StreamReader(st, System.Text.Encoding.UTF8)
40-
41- Dim htmlSource As String = sr.ReadToEnd()
42-
43- sr.Close()
44- st.Close()
45- webres.Close()
46-
47- csrfmiddlewaretoken = GetCsrmiddlewaretoken(htmlSource)
48- csrfmiddlewaretoken = csrfmiddlewaretoken.Substring(1, csrfmiddlewaretoken.Length - 2)
49- txtDebug.Text = csrfmiddlewaretoken
50-
5130 End Sub
5231
53- Private Sub DownLoadsReq()
5432
55- Dim wc As New System.Net.WebClient()
56- ' _backGroudWoker.ReportProgress(100, String.Format("{0}をダウンロード中", l.Text))
57- Dim dirfullpath As String = txtSaveDirectory.Text
58- If Not IOUtil.CreateDirectoryIfNotExist(dirfullpath) Then
59- ' _backGroudWoker.ReportProgress(100, String.Format("{0}のダウンロード失敗", l.Text))
60- Exit Sub
61- End If
6233
63- For Each link As aLink In downloadLists
64- DownLoadOneLink(wc, link, dirfullpath)
65- Next
66-
67- wc.Dispose()
68- End Sub
69-
70- Private Sub DownLoadOneLink(wc As System.Net.WebClient, link As aLink, dirfullpath As String)
71- Dim url As String = link.Url
72- Dim filename As String = System.IO.Path.GetFileName(url)
73- Dim fullpath As String = dirfullpath & "/" & filename
74- Try
75- wc.DownloadFile(url, fullpath)
76- Catch ex As Exception
77- ' Log.Err(url & ex.ToString)
78- End Try
79- End Sub
80-
81- Private Function GetCsrmiddlewaretoken(ByVal text As String) As String
82- Dim m As System.Text.RegularExpressions.Match =
83- System.Text.RegularExpressions.Regex.Match(
84- text,
85- "\<input\s+[^>]*name\s*=\s*'csrfmiddlewaretoken'\s*value=(?<value>'.*') /\>",
86- System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
87- System.Text.RegularExpressions.RegexOptions.Singleline)
88-
89- Return m.Groups("value").Value.Trim()
90- End Function
91-
92-
93-
94- Private Sub ListPageReadReq()
95-
96- Dim ps As New Hashtable
97- ps.Add("csrfmiddlewaretoken", csrfmiddlewaretoken)
98- ps.Add("name1", txtName1.Text)
99- ps.Add("name2", txtName2.Text)
100- ps.Add("gtype", GetGTypeValue())
101-
102- Dim encoder As System.Text.Encoding = System.Text.Encoding.UTF8
103-
104- Dim resText As String = HttpPostUtl.HttpPost(baseUrl, ps, cc, encoder)
105-
106- downloadLists = GetLinks(resText)
107-
108-
109-
110- End Sub
111-
112- Private Function GetLinks(ByVal text As String) As IList(Of aLink)
113-
114- Dim mc As System.Text.RegularExpressions.MatchCollection =
115- System.Text.RegularExpressions.Regex.Matches(
116- text, _
117- "<a\s+class=""btn1""\s+href=""(?<url>[^""]+\.kif)"">保存</a>",
118- System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
119- System.Text.RegularExpressions.RegexOptions.Singleline)
120-
121- Dim links As New List(Of aLink)
122- For Each m As System.Text.RegularExpressions.Match In mc
123- Dim link As New aLink
124- link.Url = baseUrl + m.Groups("url").Value
125- link.Text = System.IO.Path.GetFileName(link.Url)
126- links.Add(link)
127- Next
128- Return links
129- End Function
130-
131-
13234 Private Function GetGTypeValue() As Integer
13335 If rb10min.Checked Then
13436 Return 0
@@ -154,4 +56,8 @@
15456 txtSaveDirectory.Text = FolderBrowserDialog1.SelectedPath
15557 End If
15658 End Sub
59+
60+
61+
62+
15763 End Class
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmProgress.Designer.vb (revision 3)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmProgress.Designer.vb (revision 4)
@@ -23,8 +23,9 @@
2323 <System.Diagnostics.DebuggerStepThrough()> _
2424 Private Sub InitializeComponent()
2525 Me.btnCancel = New System.Windows.Forms.Button()
26- Me.ProgressBar1 = New System.Windows.Forms.ProgressBar()
26+ Me.pbProgress = New System.Windows.Forms.ProgressBar()
2727 Me.lblKifuFileName = New System.Windows.Forms.Label()
28+ Me.BackgroundWorker1 = New System.ComponentModel.BackgroundWorker()
2829 Me.SuspendLayout()
2930 '
3031 'btnCancel
@@ -36,12 +37,12 @@
3637 Me.btnCancel.Text = "キャンセル"
3738 Me.btnCancel.UseVisualStyleBackColor = True
3839 '
39- 'ProgressBar1
40+ 'pbProgress
4041 '
41- Me.ProgressBar1.Location = New System.Drawing.Point(0, 12)
42- Me.ProgressBar1.Name = "ProgressBar1"
43- Me.ProgressBar1.Size = New System.Drawing.Size(339, 23)
44- Me.ProgressBar1.TabIndex = 1
42+ Me.pbProgress.Location = New System.Drawing.Point(0, 12)
43+ Me.pbProgress.Name = "pbProgress"
44+ Me.pbProgress.Size = New System.Drawing.Size(339, 23)
45+ Me.pbProgress.TabIndex = 1
4546 '
4647 'lblKifuFileName
4748 '
@@ -50,8 +51,11 @@
5051 Me.lblKifuFileName.Name = "lblKifuFileName"
5152 Me.lblKifuFileName.Size = New System.Drawing.Size(339, 23)
5253 Me.lblKifuFileName.TabIndex = 2
53- Me.lblKifuFileName.Text = "XXXX.kif"
5454 '
55+ 'BackgroundWorker1
56+ '
57+ Me.BackgroundWorker1.WorkerReportsProgress = True
58+ '
5559 'frmProgress
5660 '
5761 Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
@@ -58,7 +62,7 @@
5862 Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
5963 Me.ClientSize = New System.Drawing.Size(340, 101)
6064 Me.Controls.Add(Me.lblKifuFileName)
61- Me.Controls.Add(Me.ProgressBar1)
65+ Me.Controls.Add(Me.pbProgress)
6266 Me.Controls.Add(Me.btnCancel)
6367 Me.Name = "frmProgress"
6468 Me.Text = "棋譜ダウンロード中(XXX/XXX)"
@@ -66,6 +70,7 @@
6670
6771 End Sub
6872 Friend WithEvents btnCancel As System.Windows.Forms.Button
69- Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
73+ Friend WithEvents pbProgress As System.Windows.Forms.ProgressBar
7074 Friend WithEvents lblKifuFileName As System.Windows.Forms.Label
75+ Friend WithEvents BackgroundWorker1 As System.ComponentModel.BackgroundWorker
7176 End Class
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmProgress.vb (revision 3)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmProgress.vb (revision 4)
@@ -1,3 +1,18 @@
11 Public Class frmProgress
22
3+ Friend Property downloder As downloder
4+
5+ Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
6+ downloder.Start()
7+ End Sub
8+
9+ Private Sub frmProgress_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
10+ BackgroundWorker1.RunWorkerAsync()
11+ End Sub
12+
13+ Private Sub BackgroundWorker1_ProgressChanged(sender As System.Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
14+ lblKifuFileName.Text = e.UserState
15+
16+ End Sub
17+
318 End Class
\ No newline at end of file
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/downloder.vb (nonexistent)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/downloder.vb (revision 4)
@@ -0,0 +1,138 @@
1+Public Class downloder
2+
3+ Public Property backGroudWoker As System.ComponentModel.BackgroundWorker
4+ Private baseUrl As String = "http://swks.sakura.ne.jp/wars/kifusearch/"
5+ Private csrfmiddlewaretoken As String
6+ Private downloadLists As IList(Of aLink)
7+ Dim cc As System.Net.CookieContainer
8+
9+ Public Property saveDirectory As String
10+ Public Property name1 As String
11+ Public Property name2 As String
12+ Public Property gType As Integer
13+
14+
15+ Private Sub New()
16+ End Sub
17+ Public Sub New(ByVal bg As System.ComponentModel.BackgroundWorker,
18+ ByVal saveDirectory As String, ByVal name1 As String, ByVal name2 As String, ByVal gType As Integer)
19+ _backGroudWoker = bg
20+ _saveDirectory = saveDirectory
21+ _name1 = name1
22+ _name2 = name2
23+ _gType = gType
24+ End Sub
25+
26+ Public Sub Start()
27+ _backGroudWoker.ReportProgress(0, "ログイン開始")
28+ LoginReq()
29+ _backGroudWoker.ReportProgress(0, "一覧取得中")
30+ ListPageReadReq()
31+ _backGroudWoker.ReportProgress(0, "ダウンロード開始")
32+ DownLoadsReq()
33+ _backGroudWoker.ReportProgress(0, "ダウンロード終了")
34+ End Sub
35+ Private Sub LoginReq()
36+
37+ cc = New System.Net.CookieContainer()
38+
39+ Dim webreq As System.Net.HttpWebRequest = _
40+ System.Net.WebRequest.Create(baseUrl)
41+ webreq.CookieContainer = cc
42+ Dim webres As System.Net.WebResponse = webreq.GetResponse()
43+ Dim st As System.IO.Stream = webres.GetResponseStream()
44+
45+ Dim sr As New System.IO.StreamReader(st, System.Text.Encoding.UTF8)
46+
47+ Dim htmlSource As String = sr.ReadToEnd()
48+
49+ sr.Close()
50+ st.Close()
51+ webres.Close()
52+
53+ csrfmiddlewaretoken = GetCsrmiddlewaretoken(htmlSource)
54+ csrfmiddlewaretoken = csrfmiddlewaretoken.Substring(1, csrfmiddlewaretoken.Length - 2)
55+
56+ End Sub
57+
58+ Private Sub DownLoadsReq()
59+
60+ Dim wc As New System.Net.WebClient()
61+
62+ Dim dirfullpath As String = _saveDirectory
63+ If Not IOUtil.CreateDirectoryIfNotExist(dirfullpath) Then
64+ _backGroudWoker.ReportProgress(100, String.Format("ディレクトリ""{0}""が作成できません", dirfullpath))
65+ Exit Sub
66+ End If
67+
68+ For Each link As aLink In downloadLists
69+ _backGroudWoker.ReportProgress(100, String.Format("{0}", link.Text))
70+ DownLoadOneLink(wc, link, dirfullpath)
71+ Next
72+
73+ wc.Dispose()
74+ End Sub
75+
76+ Private Sub DownLoadOneLink(wc As System.Net.WebClient, link As aLink, dirfullpath As String)
77+ Dim url As String = link.Url
78+ Dim filename As String = System.IO.Path.GetFileName(url)
79+ Dim fullpath As String = dirfullpath & "/" & filename
80+ Try
81+ wc.DownloadFile(url, fullpath)
82+ Catch ex As Exception
83+ ' Log.Err(url & ex.ToString)
84+ End Try
85+ End Sub
86+
87+ Private Function GetCsrmiddlewaretoken(ByVal text As String) As String
88+ Dim m As System.Text.RegularExpressions.Match =
89+ System.Text.RegularExpressions.Regex.Match(
90+ text,
91+ "\<input\s+[^>]*name\s*=\s*'csrfmiddlewaretoken'\s*value=(?<value>'.*') /\>",
92+ System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
93+ System.Text.RegularExpressions.RegexOptions.Singleline)
94+
95+ Return m.Groups("value").Value.Trim()
96+ End Function
97+
98+
99+
100+ Private Sub ListPageReadReq()
101+
102+ Dim ps As New Hashtable
103+ ps.Add("csrfmiddlewaretoken", csrfmiddlewaretoken)
104+ ps.Add("name1", _name1)
105+ ps.Add("name2", _name2)
106+ ps.Add("gtype", _gType)
107+
108+ Dim encoder As System.Text.Encoding = System.Text.Encoding.UTF8
109+
110+ Dim resText As String = HttpPostUtl.HttpPost(baseUrl, ps, cc, encoder)
111+
112+ downloadLists = GetLinks(resText)
113+
114+
115+
116+ End Sub
117+
118+ Private Function GetLinks(ByVal text As String) As IList(Of aLink)
119+
120+ Dim mc As System.Text.RegularExpressions.MatchCollection =
121+ System.Text.RegularExpressions.Regex.Matches(
122+ text, _
123+ "<a\s+class=""btn1""\s+href=""(?<url>[^""]+\.kif)"">保存</a>",
124+ System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
125+ System.Text.RegularExpressions.RegexOptions.Singleline)
126+
127+ Dim links As New List(Of aLink)
128+ For Each m As System.Text.RegularExpressions.Match In mc
129+ Dim link As New aLink
130+ link.Url = baseUrl + m.Groups("url").Value
131+ link.Text = System.IO.Path.GetFileName(link.Url)
132+ links.Add(link)
133+ Next
134+ Return links
135+ End Function
136+
137+
138+End Class