Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
加钱居士.
foot
提交
21bd8c8f
F
foot
项目概览
加钱居士.
/
foot
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
foot
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
21bd8c8f
编写于
3月 13, 2020
作者:
M
monomania
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.赛季信息获取完成
上级
65c926e2
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
326 addition
and
480 deletion
+326
-480
.gitignore
.gitignore
+2
-1
FS000.go
FS000.go
+12
-2
foot-api/module/elem/pojo/League.go
foot-api/module/elem/pojo/League.go
+2
-0
foot-api/module/elem/pojo/LeagueSeason.go
foot-api/module/elem/pojo/LeagueSeason.go
+5
-8
foot-api/module/elem/pojo/LeagueSub.go
foot-api/module/elem/pojo/LeagueSub.go
+24
-0
foot-core/common/base/service/mysql/DBOpsService.go
foot-core/common/base/service/mysql/DBOpsService.go
+1
-1
foot-core/module/elem/service/LeagueSeasonService.go
foot-core/module/elem/service/LeagueSeasonService.go
+39
-0
foot-core/module/elem/service/LeagueStubService.go
foot-core/module/elem/service/LeagueStubService.go
+0
-49
foot-core/module/elem/service/LeagueSubService.go
foot-core/module/elem/service/LeagueSubService.go
+39
-0
foot-spider/launch/FS200LeagueSeasonApplication.go
foot-spider/launch/FS200LeagueSeasonApplication.go
+11
-0
foot-spider/launch/FS200MatchHisApplication.go
foot-spider/launch/FS200MatchHisApplication.go
+5
-9
foot-spider/module/win007/Constant.go
foot-spider/module/win007/Constant.go
+5
-0
foot-spider/module/win007/proc/LeagueProcesser.go
foot-spider/module/win007/proc/LeagueProcesser.go
+7
-0
foot-spider/module/win007/proc/LeagueSeasonProcesser.go
foot-spider/module/win007/proc/LeagueSeasonProcesser.go
+174
-0
foot-spider/module/win007/proc/LeagueStubProcesser.go
foot-spider/module/win007/proc/LeagueStubProcesser.go
+0
-105
foot-spider/module/win007/proc/MatchHisProcesser.go
foot-spider/module/win007/proc/MatchHisProcesser.go
+0
-304
foot.err
foot.err
+0
-1
未找到文件。
.gitignore
浏览文件 @
21bd8c8f
...
...
@@ -14,4 +14,5 @@ bin
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea/
logs/
\ No newline at end of file
logs/
.err
\ No newline at end of file
FS000.go
浏览文件 @
21bd8c8f
package
main
import
(
"fmt"
"tesou.io/platform/foot-parent/foot-spider/launch"
"time"
)
func
main
()
{
launch
.
Spider_league
()
now
:=
time
.
Now
()
temp_year
,
_
:=
time
.
ParseDuration
(
"-8760h"
)
add
:=
now
.
Add
(
temp_year
)
parse
:=
now
.
Format
(
"2006"
)
parse2
:=
add
.
Format
(
"2006"
)
fmt
.
Println
(
parse
)
fmt
.
Println
(
parse2
)
//launch.Spider_league()
launch
.
Spider_leagueSeason
()
}
foot-api/module/elem/pojo/League.go
浏览文件 @
21bd8c8f
...
...
@@ -13,6 +13,8 @@ type League struct {
Name
string
`xorm:" comment('联赛名称') index"`
ShortName
string
`xorm:" comment('联赛名简称') index"`
ShortUrl
string
`xorm:" comment('联赛入口路径') index"`
Cup
bool
`xorm:" comment('是否是杯赛') index"`
SeasonCross
bool
`xorm:" comment('赛制是否跨年') index"`
//联赛级别
Level
int
`xorm:" comment('联赛级别') index"`
...
...
foot-api/module/elem/pojo/LeagueS
tub
.go
→
foot-api/module/elem/pojo/LeagueS
eason
.go
浏览文件 @
21bd8c8f
...
...
@@ -5,17 +5,14 @@ import (
)
/**
联赛
子表表
联赛
赛季表,,
*/
//不管是从哪个平台抓取的数据,都使用win007的联赛的ID数据
type
LeagueStub
struct
{
type
LeagueSeason
struct
{
//联赛id
LeagueId
string
`xorm:" comment('LeagueId') index"`
//年份,使用,间隔
Season
string
`xorm:" comment('Season')"`
//subs
SubIds
[]
string
`xorm:" comment('Subs')"`
//--
//赛季
Season
string
`xorm:" comment('Season') index"`
//最大的回合数
Round
int
`xorm:" comment('最大的回合数')"`
pojo
.
BasePojo
`xorm:"extends"`
...
...
foot-api/module/elem/pojo/LeagueSub.go
0 → 100644
浏览文件 @
21bd8c8f
package
pojo
import
(
"tesou.io/platform/foot-parent/foot-api/common/base/pojo"
)
/**
联赛赛季次级表,, 如联赛,升级附加赛,降级附加赛
*/
type
LeagueSub
struct
{
//联赛id
LeagueId
string
`xorm:" comment('LeagueId') index"`
//赛季
Season
string
`xorm:" comment('Season') index"`
SubId
string
`xorm:" comment('SubId') index"`
SubName
string
`xorm:" comment('SubName') index"`
//最大的回合数
Round
int
`xorm:" comment('最大的回合数')"`
pojo
.
BasePojo
`xorm:"extends"`
}
foot-core/common/base/service/mysql/DBOpsService.go
浏览文件 @
21bd8c8f
...
...
@@ -60,7 +60,7 @@ func (this *DBOpsService) SyncTableStruct() {
}
//波菜公司,联赛其他数据表
err
=
engine
.
Sync2
(
new
(
entity3
.
Comp
),
new
(
entity3
.
League
))
err
=
engine
.
Sync2
(
new
(
entity3
.
Comp
),
new
(
entity3
.
League
)
,
new
(
entity3
.
LeagueSeason
),
new
(
entity3
.
LeagueSub
)
)
if
nil
!=
err
{
base
.
Log
.
Error
(
err
.
Error
())
}
...
...
foot-core/module/elem/service/LeagueSeasonService.go
0 → 100644
浏览文件 @
21bd8c8f
package
service
import
(
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-core/common/base/service/mysql"
)
//联赛表
type
LeagueSeasonService
struct
{
mysql
.
BaseService
}
func
(
this
*
LeagueSeasonService
)
Exist
(
e
*
pojo
.
LeagueSeason
)
(
string
,
bool
)
{
sql_build
:=
strings
.
Builder
{}
sql_build
.
WriteString
(
" LeagueId = '"
+
e
.
LeagueId
+
"' AND Season = '"
+
e
.
Season
+
"'"
)
temp
:=
&
pojo
.
LeagueSeason
{}
var
id
string
exist
,
err
:=
mysql
.
GetEngine
()
.
Where
(
sql_build
.
String
())
.
Get
(
temp
)
if
err
!=
nil
{
base
.
Log
.
Error
(
"Exist:"
,
err
)
}
if
exist
{
id
=
temp
.
Id
}
return
id
,
exist
}
func
(
this
*
LeagueSeasonService
)
FindByLeagueId
(
id
string
)
[]
*
pojo
.
LeagueSeason
{
dataList
:=
make
([]
*
pojo
.
LeagueSeason
,
0
)
sql_build
:=
strings
.
Builder
{}
sql_build
.
WriteString
(
" LeagueId = '"
+
id
+
"'"
)
err
:=
mysql
.
GetEngine
()
.
Where
(
sql_build
.
String
())
.
Find
(
&
dataList
)
if
err
!=
nil
{
base
.
Log
.
Error
(
"FindByLeagueId:"
,
err
)
}
return
dataList
}
foot-core/module/elem/service/LeagueStubService.go
已删除
100644 → 0
浏览文件 @
65c926e2
package
service
import
(
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-core/common/base/service/mysql"
)
//联赛表
type
LeagueStubService
struct
{
mysql
.
BaseService
}
func
(
this
*
LeagueStubService
)
Exist
(
e
*
pojo
.
LeagueStub
)
(
string
,
bool
)
{
//sql_build := strings.Builder{}
//eventMatchDateStr := e.EventMatchDate.Format("2006-01-02 15:04:05")
//sql_build.WriteString(" MatchId = '" + e.MatchId + "' AND TeamId = '" + e.TeamId + "' AND EventMatchDate = '" + eventMatchDateStr + "'")
//temp := &pojo.BFFutureEvent{}
//var id string
//exist, err := mysql.GetEngine().Where(sql_build.String()).Get(temp)
//if err != nil {
// base.Log.Error("Exist:", err)
//}
//if exist {
// id = temp.Id
//}
//return id, exist
return
""
,
false
}
func
(
this
*
LeagueStubService
)
FindById
(
id
string
)
*
pojo
.
League
{
league
:=
new
(
pojo
.
League
)
league
.
Id
=
id
_
,
err
:=
mysql
.
GetEngine
()
.
Get
(
league
)
if
err
!=
nil
{
base
.
Log
.
Info
(
"FindById:"
,
err
)
}
return
league
}
func
(
this
*
LeagueStubService
)
FindByName
(
name
string
)
*
pojo
.
League
{
league
:=
new
(
pojo
.
League
)
league
.
Name
=
name
_
,
err
:=
mysql
.
GetEngine
()
.
Get
(
league
)
if
err
!=
nil
{
base
.
Log
.
Info
(
"FindByName:"
,
err
)
}
return
league
}
foot-core/module/elem/service/LeagueSubService.go
0 → 100644
浏览文件 @
21bd8c8f
package
service
import
(
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-core/common/base/service/mysql"
)
//联赛表
type
LeagueSubService
struct
{
mysql
.
BaseService
}
func
(
this
*
LeagueSubService
)
Exist
(
e
*
pojo
.
LeagueSub
)
(
string
,
bool
)
{
sql_build
:=
strings
.
Builder
{}
sql_build
.
WriteString
(
" LeagueId = '"
+
e
.
LeagueId
+
"' AND Season = '"
+
e
.
Season
+
"' AND SubId = '"
+
e
.
SubId
+
"'"
)
temp
:=
&
pojo
.
LeagueSub
{}
var
id
string
exist
,
err
:=
mysql
.
GetEngine
()
.
Where
(
sql_build
.
String
())
.
Get
(
temp
)
if
err
!=
nil
{
base
.
Log
.
Error
(
"Exist:"
,
err
)
}
if
exist
{
id
=
temp
.
Id
}
return
id
,
exist
}
func
(
this
*
LeagueSubService
)
FindByLeagueId
(
id
string
)
[]
*
pojo
.
LeagueSub
{
dataList
:=
make
([]
*
pojo
.
LeagueSub
,
0
)
sql_build
:=
strings
.
Builder
{}
sql_build
.
WriteString
(
" LeagueId = '"
+
id
+
"'"
)
err
:=
mysql
.
GetEngine
()
.
Where
(
sql_build
.
String
())
.
Find
(
&
dataList
)
if
err
!=
nil
{
base
.
Log
.
Error
(
"FindByLeagueId:"
,
err
)
}
return
dataList
}
foot-spider/launch/FS200LeagueSeasonApplication.go
0 → 100644
浏览文件 @
21bd8c8f
package
launch
import
(
"tesou.io/platform/foot-parent/foot-spider/module/win007/proc"
)
func
Spider_leagueSeason
()
{
processer
:=
proc
.
GetLeagueSubProcesser
()
processer
.
Startup
()
}
foot-spider/launch/FS200MatchHisApplication.go
浏览文件 @
21bd8c8f
package
launch
import
(
"tesou.io/platform/foot-parent/foot-spider/module/win007/proc"
)
//抓取比赛数据
func
Spider_match_his
()
{
processer
:=
proc
.
GetMatchHisProcesser
()
// /联赛时间/联赛id_联赛子id_第几轮.htm
//http://m.win007.com/info/fixture/2019-2020/36_0_1.htm
processer
.
MatchlastUrl
=
"http://m.win007.com/info/fixture/2019-2020/36_0_1.htm"
processer
.
Startup
()
//
processer := proc.GetMatchHisProcesser()
//
//
/联赛时间/联赛id_联赛子id_第几轮.htm
//
//
http://m.win007.com/info/fixture/2019-2020/36_0_1.htm
//
processer.MatchlastUrl = "http://m.win007.com/info/fixture/2019-2020/36_0_1.htm"
//
processer.Startup()
}
foot-spider/module/win007/Constant.go
浏览文件 @
21bd8c8f
...
...
@@ -21,5 +21,10 @@ const WIN007_EUROODD_BET_URL_PATTERN = "http://m.win007.com/1x2Detail.aspx?schei
const
WIN007_ASIAODD_URL_PATTERN
=
"http://m.win007.com/asian/${matchId}.htm"
const
WIN007_ASIAODD_NEW_URL_PATTERN
=
"http://m.win007.com/HandicapDataInterface.ashx?scheid=${matchId}&type=1&oddskind=0&flesh=0.7215399647784261"
/**
资料库里的比赛赛程前缀
示例:http://m.win007.com/info/Fixture/2019-2020/34_0_0.htm
*/
const
WIN007_MATCH_HIS_PATTERN
=
"http://m.win007.com/info/Fixture/${season}/${leagueId}_${subId}_${round}.htm"
foot-spider/module/win007/proc/LeagueProcesser.go
浏览文件 @
21bd8c8f
...
...
@@ -80,6 +80,13 @@ func (this *LeagueProcesser) Process(p *page.Page) {
league
.
Sid
=
sId
league
.
SName
=
sName
league
.
ShortUrl
=
lUrl
if
strings
.
Contains
(
lUrl
,
"Cup"
){
league
.
Cup
=
true
}
if
strings
.
Contains
(
lUrl
,
"-"
){
league
.
SeasonCross
=
true
}
this
.
league_list
=
append
(
this
.
league_list
,
league
)
})
}
...
...
foot-spider/module/win007/proc/LeagueSeasonProcesser.go
0 → 100644
浏览文件 @
21bd8c8f
package
proc
import
(
"github.com/PuerkitoBio/goquery"
"github.com/hu17889/go_spider/core/common/page"
"github.com/hu17889/go_spider/core/pipeline"
"github.com/hu17889/go_spider/core/spider"
"strconv"
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
service2
"tesou.io/platform/foot-parent/foot-core/module/elem/service"
"tesou.io/platform/foot-parent/foot-spider/module/win007"
"tesou.io/platform/foot-parent/foot-spider/module/win007/down"
)
type
LeagueSeasonProcesser
struct
{
service2
.
LeagueService
service2
.
LeagueSeasonService
service2
.
LeagueSubService
//联赛次级数据
leagueSeason_list
[]
*
pojo
.
LeagueSeason
leagueSub_list
[]
*
pojo
.
LeagueSub
sUrl_leagueId
map
[
string
]
string
}
func
GetLeagueSubProcesser
()
*
LeagueSeasonProcesser
{
return
&
LeagueSeasonProcesser
{}
}
func
(
this
*
LeagueSeasonProcesser
)
Startup
()
{
//初始化参数值
this
.
leagueSeason_list
=
make
([]
*
pojo
.
LeagueSeason
,
0
)
this
.
leagueSub_list
=
make
([]
*
pojo
.
LeagueSub
,
0
)
this
.
sUrl_leagueId
=
make
(
map
[
string
]
string
)
//1.获取所有的联赛
leaguesList
:=
make
([]
*
pojo
.
League
,
0
)
this
.
LeagueService
.
FindAll
(
&
leaguesList
)
//2.配置要抓取的路径
newSpider
:=
spider
.
NewSpider
(
this
,
"LeagueSeasonProcesser"
)
//index := 0
for
_
,
v
:=
range
leaguesList
{
//先不处理杯赛....
if
v
.
Cup
{
continue
}
//index++
//if index > 10{
// break
//}
url
:=
win007
.
WIN007_MATCH_HIS_PATTERN
if
v
.
SeasonCross
{
url
=
strings
.
Replace
(
url
,
"${season}"
,
"2018-2019"
,
1
)
}
else
{
url
=
strings
.
Replace
(
url
,
"${season}"
,
"2019"
,
1
)
}
url
=
strings
.
Replace
(
url
,
"${leagueId}"
,
v
.
Id
,
1
)
url
=
strings
.
Replace
(
url
,
"${subId}"
,
"0"
,
1
)
url
=
strings
.
Replace
(
url
,
"${round}"
,
"1"
,
1
)
this
.
sUrl_leagueId
[
url
]
=
v
.
Id
newSpider
=
newSpider
.
AddUrl
(
url
,
"html"
)
}
newSpider
.
SetDownloader
(
down
.
NewMWin007Downloader
())
newSpider
=
newSpider
.
AddPipeline
(
pipeline
.
NewPipelineConsole
())
newSpider
.
SetSleepTime
(
"rand"
,
100
,
2000
)
newSpider
.
SetThreadnum
(
1
)
.
Run
()
}
func
(
this
*
LeagueSeasonProcesser
)
Process
(
p
*
page
.
Page
)
{
request
:=
p
.
GetRequest
()
if
!
p
.
IsSucc
()
{
base
.
Log
.
Error
(
"URL:,"
,
request
.
Url
,
p
.
Errormsg
())
return
}
rawText
:=
p
.
GetBodyStr
()
if
rawText
==
""
{
base
.
Log
.
Error
(
"rawText:为空.url:"
,
request
.
Url
)
return
}
leagueId
:=
this
.
sUrl_leagueId
[
request
.
Url
]
//1.处理season
htmlParser
:=
p
.
GetHtmlParser
()
htmlParser
.
Find
(
"select[id='selSeason'] option"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
temp_maxRound
:=
1
temp_season
:=
strings
.
TrimSpace
(
selection
.
Text
())
//2.处理sub
htmlParser
.
Find
(
"select[id='selSubSclass'] option"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
temp_subName
:=
strings
.
TrimSpace
(
selection
.
Text
())
if
len
(
temp_subName
)
<=
0
{
return
}
val
,
exist
:=
selection
.
Attr
(
"value"
)
if
!
exist
{
return
}
base
.
Log
.
Info
(
"联赛Id:"
,
leagueId
,
",赛季:"
,
temp_season
,
",次级名称:"
,
temp_subName
,
",次级Id:"
,
val
)
leagueSub
:=
new
(
pojo
.
LeagueSub
)
leagueSub
.
LeagueId
=
leagueId
leagueSub
.
Season
=
temp_season
leagueSub
.
Round
=
temp_maxRound
leagueSub
.
SubId
=
val
leagueSub
.
SubName
=
temp_subName
this
.
leagueSub_list
=
append
(
this
.
leagueSub_list
,
leagueSub
)
})
//3.处理round
htmlParser
.
Find
(
"select[id='selRound'] option"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
temp_round_str
:=
strings
.
TrimSpace
(
selection
.
Text
())
if
len
(
temp_round_str
)
<=
0
{
return
}
temp_round
,
_
:=
strconv
.
Atoi
(
temp_round_str
)
if
temp_round
>
temp_maxRound
{
temp_maxRound
=
temp_round
}
})
leagueSeason
:=
new
(
pojo
.
LeagueSeason
)
leagueSeason
.
LeagueId
=
leagueId
leagueSeason
.
Season
=
temp_season
leagueSeason
.
Round
=
temp_maxRound
this
.
leagueSeason_list
=
append
(
this
.
leagueSeason_list
,
leagueSeason
)
})
}
func
(
this
*
LeagueSeasonProcesser
)
Finish
()
{
base
.
Log
.
Info
(
"联赛次级抓取解析完成,执行入库
\r\n
"
)
leagueSeason_list_slice
:=
make
([]
interface
{},
0
)
leagueSeason_modify_list_slice
:=
make
([]
interface
{},
0
)
for
_
,
v
:=
range
this
.
leagueSeason_list
{
if
nil
==
v
{
continue
}
id
,
exist
:=
this
.
LeagueSeasonService
.
Exist
(
v
)
if
exist
{
v
.
Id
=
id
leagueSeason_modify_list_slice
=
append
(
leagueSeason_modify_list_slice
,
v
)
continue
}
leagueSeason_list_slice
=
append
(
leagueSeason_list_slice
,
v
)
}
this
.
LeagueSeasonService
.
SaveList
(
leagueSeason_list_slice
)
this
.
LeagueSeasonService
.
ModifyList
(
leagueSeason_modify_list_slice
)
leagueSub_list_slice
:=
make
([]
interface
{},
0
)
leagueSub_modify_list_slice
:=
make
([]
interface
{},
0
)
for
_
,
v
:=
range
this
.
leagueSub_list
{
if
nil
==
v
{
continue
}
id
,
exist
:=
this
.
LeagueSubService
.
Exist
(
v
)
if
exist
{
v
.
Id
=
id
leagueSub_modify_list_slice
=
append
(
leagueSub_modify_list_slice
,
v
)
continue
}
leagueSub_list_slice
=
append
(
leagueSub_list_slice
,
v
)
}
this
.
LeagueSubService
.
SaveList
(
leagueSub_list_slice
)
this
.
LeagueSubService
.
ModifyList
(
leagueSub_modify_list_slice
)
}
foot-spider/module/win007/proc/LeagueStubProcesser.go
已删除
100644 → 0
浏览文件 @
65c926e2
package
proc
import
(
"github.com/PuerkitoBio/goquery"
"github.com/hu17889/go_spider/core/common/page"
"github.com/hu17889/go_spider/core/pipeline"
"github.com/hu17889/go_spider/core/spider"
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
entity2
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
service2
"tesou.io/platform/foot-parent/foot-core/module/elem/service"
"tesou.io/platform/foot-parent/foot-spider/module/win007"
"tesou.io/platform/foot-parent/foot-spider/module/win007/down"
)
type
LeagueStubProcesser
struct
{
service2
.
LeagueService
service2
.
CompService
//联赛数据
league_list
[]
*
entity2
.
League
sUrl_Id
map
[
string
]
string
sUrl_Name
map
[
string
]
string
}
func
GetLeagueStubProcesser
()
*
LeagueStubProcesser
{
return
&
LeagueStubProcesser
{}
}
func
(
this
*
LeagueStubProcesser
)
Startup
()
{
//初始化参数值
this
.
league_list
=
make
([]
*
entity2
.
League
,
0
)
this
.
sUrl_Id
=
make
(
map
[
string
]
string
)
this
.
sUrl_Name
=
make
(
map
[
string
]
string
)
newSpider
:=
spider
.
NewSpider
(
this
,
"LeagueStubProcesser"
)
//sid 数据
sid_stat_url
:=
"http://m.win007.com/info.htm#section0"
;
document
,
_
:=
GetDocument
(
sid_stat_url
)
document
.
Find
(
"a[href*='sid']"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
sUrl
,
_
:=
selection
.
Attr
(
"href"
)
sId
:=
strings
.
Split
(
sUrl
,
"sid="
)[
1
]
sName
:=
strings
.
TrimSpace
(
selection
.
Text
())
base
.
Log
.
Info
(
"sId:"
,
sId
,
",sName:"
,
sName
,
",sUrl:"
+
sUrl
)
this
.
sUrl_Id
[
win007
.
WIN007_BASE_URL
+
sUrl
]
=
sId
this
.
sUrl_Name
[
win007
.
WIN007_BASE_URL
+
sUrl
]
=
sName
newSpider
=
newSpider
.
AddUrl
(
win007
.
WIN007_BASE_URL
+
sUrl
,
"html"
)
})
newSpider
.
SetDownloader
(
down
.
NewMWin007Downloader
())
newSpider
=
newSpider
.
AddPipeline
(
pipeline
.
NewPipelineConsole
())
newSpider
.
SetSleepTime
(
"rand"
,
100
,
2000
)
newSpider
.
SetThreadnum
(
1
)
.
Run
()
}
func
(
this
*
LeagueStubProcesser
)
Process
(
p
*
page
.
Page
)
{
request
:=
p
.
GetRequest
()
if
!
p
.
IsSucc
()
{
base
.
Log
.
Error
(
"URL:,"
,
request
.
Url
,
p
.
Errormsg
())
return
}
rawText
:=
p
.
GetBodyStr
()
if
rawText
==
""
{
base
.
Log
.
Error
(
"rawText:为空.url:"
,
request
.
Url
)
return
}
sUrl
:=
request
.
Url
sId
:=
this
.
sUrl_Id
[
sUrl
]
sName
:=
this
.
sUrl_Name
[
sUrl
]
p
.
GetHtmlParser
()
.
Find
(
"a.gameItem[href*='info'][href*='htm']"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
lUrl
,
_
:=
selection
.
Attr
(
"href"
)
l_arr
:=
strings
.
Split
(
lUrl
,
"/"
)
lId_suffix
:=
l_arr
[
len
(
l_arr
)
-
1
]
lId
:=
strings
.
ReplaceAll
(
lId_suffix
,
".htm"
,
""
)
lName
:=
strings
.
TrimSpace
(
selection
.
Text
())
base
.
Log
.
Info
(
"lId:"
,
lId
,
",lName:"
,
lName
,
",lUrl:"
+
lUrl
)
league
:=
new
(
entity2
.
League
)
league
.
Id
=
lId
league
.
Name
=
lName
league
.
Sid
=
sId
league
.
SName
=
sName
league
.
ShortUrl
=
lUrl
this
.
league_list
=
append
(
this
.
league_list
,
league
)
})
}
func
(
this
*
LeagueStubProcesser
)
Finish
()
{
base
.
Log
.
Info
(
"联赛解析完成,执行入库
\r\n
"
)
league_list_slice
:=
make
([]
interface
{},
0
)
league_modify_list_slice
:=
make
([]
interface
{},
0
)
for
_
,
v
:=
range
this
.
league_list
{
if
nil
==
v
{
continue
}
exists
:=
this
.
LeagueService
.
ExistById
(
v
.
Id
)
if
exists
{
league_modify_list_slice
=
append
(
league_modify_list_slice
,
v
)
continue
}
league_list_slice
=
append
(
league_list_slice
,
v
)
}
this
.
LeagueService
.
SaveList
(
league_list_slice
)
this
.
LeagueService
.
ModifyList
(
league_modify_list_slice
)
}
foot-spider/module/win007/proc/MatchHisProcesser.go
已删除
100644 → 0
浏览文件 @
65c926e2
package
proc
import
(
"github.com/hu17889/go_spider/core/common/page"
"github.com/hu17889/go_spider/core/pipeline"
"github.com/hu17889/go_spider/core/spider"
"math/rand"
"strconv"
"strings"
"tesou.io/platform/foot-parent/foot-api/common/base"
entity2
"tesou.io/platform/foot-parent/foot-api/module/elem/pojo"
"tesou.io/platform/foot-parent/foot-api/module/match/pojo"
service2
"tesou.io/platform/foot-parent/foot-core/module/elem/service"
"tesou.io/platform/foot-parent/foot-core/module/match/service"
"tesou.io/platform/foot-parent/foot-spider/module/win007"
"tesou.io/platform/foot-parent/foot-spider/module/win007/down"
"time"
)
type
MatchHisProcesser
struct
{
service
.
MatchLastService
service
.
MatchHisService
service2
.
LeagueService
service2
.
CompService
//抓取的url
MatchlastUrl
string
//联赛数据
league_list
[]
*
entity2
.
League
win007Id_leagueId_map
map
[
string
]
string
//比赛数据
matchLast_list
[]
*
pojo
.
MatchLast
//比赛级别
MatchLevel
int
}
func
GetMatchHisProcesser
()
*
MatchHisProcesser
{
return
&
MatchHisProcesser
{}
}
func
(
this
*
MatchHisProcesser
)
Startup
()
{
//联赛数据
this
.
league_list
=
make
([]
*
entity2
.
League
,
0
)
this
.
win007Id_leagueId_map
=
make
(
map
[
string
]
string
)
//比赛数据
this
.
matchLast_list
=
make
([]
*
pojo
.
MatchLast
,
0
)
if
this
.
MatchlastUrl
==
""
{
this
.
MatchlastUrl
=
"http://m.win007.com/phone/Schedule_0_0.txt"
}
this
.
MatchlastUrl
=
this
.
MatchlastUrl
+
"?flesh="
+
strconv
.
FormatFloat
(
rand
.
Float64
(),
'f'
,
-
1
,
64
)
newSpider
:=
spider
.
NewSpider
(
this
,
"MatchHisProcesser"
)
newSpider
=
newSpider
.
AddUrl
(
this
.
MatchlastUrl
,
"text"
)
newSpider
.
SetDownloader
(
down
.
NewMWin007Downloader
())
newSpider
=
newSpider
.
AddPipeline
(
pipeline
.
NewPipelineConsole
())
newSpider
.
SetSleepTime
(
"rand"
,
100
,
2000
)
newSpider
.
SetThreadnum
(
1
)
.
Run
()
}
func
(
this
*
MatchHisProcesser
)
Process
(
p
*
page
.
Page
)
{
request
:=
p
.
GetRequest
()
if
!
p
.
IsSucc
()
{
base
.
Log
.
Error
(
"URL:,"
,
request
.
Url
,
p
.
Errormsg
())
return
}
rawText
:=
p
.
GetBodyStr
()
if
rawText
==
""
{
base
.
Log
.
Error
(
"rawText:为空.url:"
,
request
.
Url
)
return
}
rawText_arr
:=
strings
.
Split
(
rawText
,
"$$"
)
if
len
(
rawText_arr
)
<
2
{
base
.
Log
.
Error
(
"rawText:解析失败,rawTextArr长度小于所必需要的长度2,url:"
,
request
.
Url
,
"内容:"
,
rawText_arr
)
return
}
flag
:=
this
.
findParamVal
(
request
.
Url
)
var
league_str
string
var
match_str
string
if
flag
==
"0"
{
league_str
=
rawText_arr
[
0
]
match_str
=
rawText_arr
[
1
]
}
else
{
league_str
=
rawText_arr
[
1
]
match_str
=
rawText_arr
[
2
]
}
base
.
Log
.
Info
(
"日期:TODAY"
,
"联赛信息:"
,
league_str
)
this
.
league_process
(
league_str
)
base
.
Log
.
Info
(
"日期:TODAY"
,
"比赛信息:"
,
match_str
)
this
.
match_process
(
match_str
)
now
:=
time
.
Now
()
//获取明天赛程
h24h
,
_
:=
time
.
ParseDuration
(
"24h"
)
t_1_date
:=
now
.
Add
(
h24h
)
.
Format
(
"2006-01-02"
)
this
.
futrueMatch
(
t_1_date
)
//获取后天赛程
//h24h, _ = time.ParseDuration("48h")
//t_1_date = now.Add(h24h).Format("2006-01-02")
//this.futrueMatch(t_1_date)
}
func
(
this
*
MatchHisProcesser
)
futrueMatch
(
date
string
)
{
url
:=
"http://m.win007.com/ChangeDate.ashx?date="
+
date
rawText
:=
GetText
(
url
)
//rawText := Post("http://m.win007.com/ChangeDate.ashx", &req)
if
rawText
==
""
{
base
.
Log
.
Error
(
"rawText:为空.url:"
,
url
)
return
}
rawText_arr
:=
strings
.
Split
(
rawText
,
"$"
)
if
len
(
rawText_arr
)
<
2
{
base
.
Log
.
Error
(
"rawText:解析失败,rawTextArr长度小于所必需要的长度2,url:"
,
url
,
"内容:"
,
rawText_arr
)
return
}
league_str
:=
rawText_arr
[
0
]
match_str
:=
rawText_arr
[
1
]
base
.
Log
.
Info
(
"日期:"
,
date
,
"联赛信息:"
,
league_str
)
this
.
league_process
(
league_str
)
base
.
Log
.
Info
(
"日期:"
,
date
,
"比赛信息:"
,
match_str
)
this
.
match_process
(
match_str
)
}
func
(
this
*
MatchHisProcesser
)
findParamVal
(
url
string
)
string
{
paramUrl
:=
strings
.
Split
(
url
,
"_"
)[
2
]
paramArr
:=
strings
.
Split
(
paramUrl
,
"."
)
return
paramArr
[
0
]
}
func
(
this
*
MatchHisProcesser
)
league_process
(
rawText
string
)
{
league_arr
:=
strings
.
Split
(
rawText
,
"!"
)
this
.
league_list
=
make
([]
*
entity2
.
League
,
len
(
league_arr
))
var
index
int
for
_
,
v
:=
range
league_arr
{
league_info_arr
:=
strings
.
Split
(
v
,
"^"
)
if
len
(
league_info_arr
)
<
3
{
continue
}
i
:=
0
//联赛名称
name
:=
league_info_arr
[
i
]
//联赛ID
i
++
win007Id
:=
league_info_arr
[
i
]
league
:=
new
(
entity2
.
League
)
league
.
Id
=
win007Id
league
.
ShortName
=
name
if
this
.
MatchLevel
>
0
{
//设置联赛级别
league
.
LevelAssist
=
10000
}
//league.Ext = make(map[string]interface{})
//league.Ext["win007Id"] = win007Id
this
.
win007Id_leagueId_map
[
win007Id
]
=
league
.
Id
//联赛级别
i
++
level_str
:=
league_info_arr
[
i
]
level
,
_
:=
strconv
.
Atoi
(
level_str
)
league
.
Level
=
level
//占位
i
++
//赛事类别ID
i
++
league
.
Sid
=
league_info_arr
[
i
]
//赛事类别名称
i
++
league
.
SName
=
league_info_arr
[
i
]
this
.
league_list
[
index
]
=
league
index
++
}
}
/**
处理比赛信息
*/
func
(
this
*
MatchHisProcesser
)
match_process
(
rawText
string
)
{
match_arr
:=
strings
.
Split
(
rawText
,
"!"
)
match_len
:=
len
(
match_arr
)
for
i
:=
0
;
i
<
match_len
;
i
++
{
matchLast
:=
new
(
pojo
.
MatchLast
)
//matchLast.Ext = make(map[string]interface{})
//matchLast.Id = bson.NewObjectId().Hex()
//match_arr[0] is
//1503881^284^0^20180909170000^^町田泽维亚^水户蜀葵^0^0^0^0^0^0^0^0^0.5^181^^0^2^12^^^0^0^0^0
match_info_arr
:=
strings
.
Split
(
match_arr
[
i
],
"^"
)
index
:=
0
win007Id
:=
match_info_arr
[
index
]
//matchLast.Ext["win007Id"] = win007Id
//比赛ID
matchLast
.
Id
=
win007Id
//联赛ID
index
++
matchLast
.
LeagueId
=
this
.
win007Id_leagueId_map
[
match_info_arr
[
index
]]
index
++
//比赛日期
index
++
match_date_str
:=
match_info_arr
[
index
]
matchLast
.
MatchDate
,
_
=
time
.
ParseInLocation
(
"20060102150405"
,
match_date_str
,
time
.
Local
)
index
++
//主队客队名称
index
++
matchLast
.
MainTeamId
=
match_info_arr
[
index
]
/* if regexp.MustCompile("^\\d*$").MatchString(dataDate_or_mainTeamName) {
data_date_timestamp, _ := strconv.ParseInt(dataDate_or_mainTeamName, 10, 64)
matchLast.DataDate = time.Unix(data_date_timestamp, 0).Format("2006-01-02 15:04:05")
} else {
matchLast.MainTeamId = dataDate_or_mainTeamName
}*/
index
++
matchLast
.
GuestTeamId
=
match_info_arr
[
index
]
//全场进球
index
++
mainTeamGoals_str
:=
match_info_arr
[
index
]
mainTeamGoals
,
_
:=
strconv
.
Atoi
(
mainTeamGoals_str
)
matchLast
.
MainTeamGoals
=
mainTeamGoals
index
++
guestTeamGoals_str
:=
match_info_arr
[
index
]
guestTeamGoals
,
_
:=
strconv
.
Atoi
(
guestTeamGoals_str
)
matchLast
.
GuestTeamGoals
=
guestTeamGoals
//半场进球
index
++
mainTeamHalfGoals_str
:=
match_info_arr
[
index
]
mainTeamHalfGoals
,
_
:=
strconv
.
Atoi
(
mainTeamHalfGoals_str
)
matchLast
.
MainTeamHalfGoals
=
mainTeamHalfGoals
index
++
guestTeamHalfGoals_str
:=
match_info_arr
[
index
]
guestTeamHalfGoals
,
_
:=
strconv
.
Atoi
(
guestTeamHalfGoals_str
)
matchLast
.
GuestTeamHalfGoals
=
guestTeamHalfGoals
//最后加入数据中
this
.
matchLast_list
=
append
(
this
.
matchLast_list
,
matchLast
)
}
}
func
(
this
*
MatchHisProcesser
)
Finish
()
{
base
.
Log
.
Info
(
"比赛抓取解析完成,执行入库
\r\n
"
)
league_list_slice
:=
make
([]
interface
{},
0
)
for
_
,
v
:=
range
this
.
league_list
{
if
nil
==
v
{
continue
}
/* bytes, _ := json.Marshal(v)
base.Log.Info(string(bytes))*/
exists
:=
this
.
LeagueService
.
ExistById
(
v
.
Id
)
if
exists
{
continue
}
league_list_slice
=
append
(
league_list_slice
,
v
)
}
this
.
LeagueService
.
SaveList
(
league_list_slice
)
matchLast_list_slice
:=
make
([]
interface
{},
0
)
matchLast_modify_list_slice
:=
make
([]
interface
{},
0
)
matchHis_list_slice
:=
make
([]
interface
{},
0
)
matchHis_modify_list_slice
:=
make
([]
interface
{},
0
)
for
_
,
v
:=
range
this
.
matchLast_list
{
if
nil
==
v
{
continue
}
//v.Id = v.Ext["win007Id"].(string);
//处理比赛配置信息
matchExt
:=
new
(
pojo
.
MatchExt
)
/* matchLast_elem := reflect.ValueOf(v).Elem()
matchExt.MatchId = matchLast_elem.FieldByName("Id").String()*/
//ext := matchLast_elem.FieldByName("Ext").Interface().(map[string]interface{})
//matchExt.Sid = ext["win007Id"].(string)
matchExt
.
Sid
=
v
.
Id
v
.
Ext
=
make
(
map
[
string
]
interface
{})
v
.
Ext
[
win007
.
MODULE_FLAG
]
=
matchExt
exists
:=
this
.
MatchLastService
.
Exist
(
v
)
if
exists
{
matchLast_modify_list_slice
=
append
(
matchLast_modify_list_slice
,
v
)
}
else
{
matchLast_list_slice
=
append
(
matchLast_list_slice
,
v
)
}
his
:=
new
(
pojo
.
MatchHis
)
his
.
MatchLast
=
*
v
his_exists
:=
this
.
MatchHisService
.
Exist
(
his
)
if
his_exists
{
matchHis_modify_list_slice
=
append
(
matchHis_modify_list_slice
,
his
)
}
else
{
matchHis_list_slice
=
append
(
matchHis_list_slice
,
his
)
}
}
this
.
MatchLastService
.
SaveList
(
matchLast_list_slice
)
this
.
MatchLastService
.
ModifyList
(
matchLast_modify_list_slice
)
this
.
MatchHisService
.
SaveList
(
matchHis_list_slice
)
this
.
MatchHisService
.
ModifyList
(
matchHis_modify_list_slice
)
}
foot.err
已删除
120000 → 0
浏览文件 @
65c926e2
./logs/foot.err.20200227
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录