• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

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

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

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


コミットメタ情報

リビジョン3 (tree)
日時2015-01-26 20:22:18
作者bellyoshi

ログメッセージ

変更サマリ

差分

--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/IOUtil.vb (nonexistent)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/IOUtil.vb (revision 3)
@@ -0,0 +1,19 @@
1+Public Class IOUtil
2+ ''' <summary>
3+ ''' ディレクトリを作成する。
4+ ''' </summary>
5+ ''' <param name="path"></param>
6+ ''' <returns>作成に成功したらTure 失敗したらFlase</returns>
7+ ''' <remarks></remarks>
8+ Public Shared Function CreateDirectoryIfNotExist(ByVal path As String) As Boolean
9+ If Not System.IO.File.Exists(path) Then
10+ Try
11+ System.IO.Directory.CreateDirectory(path)
12+ Catch ex As Exception
13+ ' Log.Err("Can Not Create Directory:" & path)
14+ Return False
15+ End Try
16+ End If
17+ Return True
18+ End Function
19+End Class
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/aLink.vb (nonexistent)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/aLink.vb (revision 3)
@@ -0,0 +1,11 @@
1+Public Class aLink
2+ Public Property Text As String
3+ Public Property Url As String
4+ Public ReadOnly Property View As String
5+ Get
6+ Return _Text & ":" & _Url
7+ End Get
8+ End Property
9+
10+
11+End Class
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.Designer.vb (revision 2)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.Designer.vb (revision 3)
@@ -35,6 +35,7 @@
3535 Me.btnSelectDirectory = New System.Windows.Forms.Button()
3636 Me.btnDownload = New System.Windows.Forms.Button()
3737 Me.txtDebug = New System.Windows.Forms.TextBox()
38+ Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog()
3839 Me.GroupBox1.SuspendLayout()
3940 Me.SuspendLayout()
4041 '
@@ -195,5 +196,6 @@
195196 Friend WithEvents btnSelectDirectory As System.Windows.Forms.Button
196197 Friend WithEvents btnDownload As System.Windows.Forms.Button
197198 Friend WithEvents txtDebug As System.Windows.Forms.TextBox
199+ Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
198200
199201 End Class
--- ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.vb (revision 2)
+++ ShogiWarsKifuDownloader/ShogiWarsKifuDownloader/frmCondtion.vb (revision 3)
@@ -1,22 +1,37 @@
11 Public Class frmCondtion
22
3- Private url As String = "http://swks.sakura.ne.jp/wars/kifusearch/"
3+ Private baseUrl As String = "http://swks.sakura.ne.jp/wars/kifusearch/"
44 Private csrfmiddlewaretoken As String
5+ Private downloadLists As IList(Of aLink)
56 Dim cc As System.Net.CookieContainer
67
78 Private Sub btnDownload_Click(sender As System.Object, e As System.EventArgs) Handles btnDownload.Click
9+ If txtSaveDirectory.Text = String.Empty Then
10+ MessageBox.Show("保存先を選択してください。")
11+ Exit Sub
12+ End If
13+ If txtName1.Text = String.Empty AndAlso
14+ txtName2.Text = String.Empty Then
15+ MessageBox.Show("対局者をどちらか入力してください。")
16+ End If
17+ If Not rb10min.Checked AndAlso
18+ Not rb3min.Checked AndAlso
19+ Not rb10sec.Checked AndAlso
20+ Not rbAnimal.Checked Then
21+ MessageBox.Show("対局モードを選択してください。")
22+ End If
23+ LoginReq()
24+ ListPageReadReq()
25+ DownloadsReq()
826
9- FirstReq()
10- SecondReq()
11-
1227 End Sub
1328
14- Private Sub FirstReq()
29+ Private Sub LoginReq()
1530
1631 cc = New System.Net.CookieContainer()
1732
1833 Dim webreq As System.Net.HttpWebRequest = _
19- System.Net.WebRequest.Create(url)
34+ System.Net.WebRequest.Create(baseUrl)
2035 webreq.CookieContainer = cc
2136 Dim webres As System.Net.WebResponse = webreq.GetResponse()
2237 Dim st As System.IO.Stream = webres.GetResponseStream()
@@ -29,8 +44,6 @@
2944 st.Close()
3045 webres.Close()
3146
32-
33-
3447 csrfmiddlewaretoken = GetCsrmiddlewaretoken(htmlSource)
3548 csrfmiddlewaretoken = csrfmiddlewaretoken.Substring(1, csrfmiddlewaretoken.Length - 2)
3649 txtDebug.Text = csrfmiddlewaretoken
@@ -37,10 +50,38 @@
3750
3851 End Sub
3952
53+ Private Sub DownLoadsReq()
54+
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
62+
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+
4081 Private Function GetCsrmiddlewaretoken(ByVal text As String) As String
41- Dim m As System.Text.RegularExpressions.Match = _
42- System.Text.RegularExpressions.Regex.Match( _
43- text, _
82+ Dim m As System.Text.RegularExpressions.Match =
83+ System.Text.RegularExpressions.Regex.Match(
84+ text,
4485 "\<input\s+[^>]*name\s*=\s*'csrfmiddlewaretoken'\s*value=(?<value>'.*') /\>",
4586 System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
4687 System.Text.RegularExpressions.RegexOptions.Singleline)
@@ -48,27 +89,46 @@
4889 Return m.Groups("value").Value.Trim()
4990 End Function
5091
51-
5292
53- Private Sub SecondReq()
5493
94+ Private Sub ListPageReadReq()
95+
5596 Dim ps As New Hashtable
5697 ps.Add("csrfmiddlewaretoken", csrfmiddlewaretoken)
5798 ps.Add("name1", txtName1.Text)
5899 ps.Add("name2", txtName2.Text)
59100 ps.Add("gtype", GetGTypeValue())
60- ps.Add("x", 15)
61- ps.Add("y", 13)
62101
102+ Dim encoder As System.Text.Encoding = System.Text.Encoding.UTF8
63103
104+ Dim resText As String = HttpPostUtl.HttpPost(baseUrl, ps, cc, encoder)
64105
65- Dim encoder As System.Text.Encoding = System.Text.Encoding.UTF8
106+ downloadLists = GetLinks(resText)
66107
67- Dim resText As String = HttpPostUtl.HttpPost(url, ps, cc, encoder)
68- txtDebug.Text = resText
108+
109+
69110 End Sub
70111
112+ Private Function GetLinks(ByVal text As String) As IList(Of aLink)
71113
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+
72132 Private Function GetGTypeValue() As Integer
73133 If rb10min.Checked Then
74134 Return 0
@@ -88,4 +148,10 @@
88148 Private Sub frmCondtion_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
89149 rb3min.Checked = True
90150 End Sub
151+
152+ Private Sub btnSelectDirectory_Click(sender As System.Object, e As System.EventArgs) Handles btnSelectDirectory.Click
153+ If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
154+ txtSaveDirectory.Text = FolderBrowserDialog1.SelectedPath
155+ End If
156+ End Sub
91157 End Class