Skip to content

Instantly share code, notes, and snippets.

@kelby
Last active November 5, 2023 09:53
Show Gist options
  • Save kelby/7a979fc5f940fa86f3a055a905c172e5 to your computer and use it in GitHub Desktop.
Save kelby/7a979fc5f940fa86f3a055a905c172e5 to your computer and use it in GitHub Desktop.
Python 实现:连接 Steam 客户端,登录账号,启动 Dota2 客户端,抓取实时比赛数据。
from steam import SteamClient
from dota2 import Dota2Client
client = SteamClient()
dota = Dota2Client(client)
LOGON_DETAILS = {
'username': "your-steam-username",
'password': "your-steam-password",
}
@client.on('logged_on')
def start_dota():
dota.launch()
@dota.on('ready')
def do_dota_stuff1():
print('11111')
jobid = dota.request_profile_card(70388657)
profile_card = dota.wait_msg(jobid, timeout=20)
if profile_card:
print(profile_card)
games = dota.request_top_source_tv_games()
if games:
print('55555555555')
print(games)
@dota.on('top_source_tv_games')
def do_top_source_tv_games(response):
print('44444444')
print(response)
@dota.on('notready')
def do_dota_stuff2():
print('222222')
@dota.on('connection_status')
def do_dota_stuff3():
print('33333')
# client.cli_login()
client.login(**LOGON_DETAILS)
client.run_forever()
search_key: ""
league_id: 0
hero_id: 0
start_game: 0
num_games: 100
game_list_index: 2106
game_list {
activate_time: 1543478656
deactivate_time: 0
server_steam_id: 90121279764703243
lobby_id: 25894769524407257
league_id: 10482
lobby_type: 1
game_time: 994
delay: 300
spectators: 1716
game_mode: 2
average_mmr: 0
team_name_radiant: "Team Root"
team_name_dire: "KEEN GAMING"
sort_score: 10716
last_update_time: 1543480192.0
radiant_lead: -2188
radiant_score: 11
dire_score: 6
players {
account_id: 135878232
hero_id: 89
}
players {
account_id: 139876032
hero_id: 86
}
players {
account_id: 397462905
hero_id: 3
}
players {
account_id: 255219872
hero_id: 45
}
players {
account_id: 134276083
hero_id: 96
}
players {
account_id: 139280377
hero_id: 54
}
players {
account_id: 90882159
hero_id: 43
}
players {
account_id: 107081378
hero_id: 121
}
players {
account_id: 114239371
hero_id: 50
}
players {
account_id: 98878010
hero_id: 2
}
building_state: 5374161
team_logo_radiant: 946215998644843978
team_logo_dire: 941685450590444307
}
game_list {
activate_time: 1543478912
deactivate_time: 0
server_steam_id: 90121279962203136
lobby_id: 25894769524388282
league_id: 10482
lobby_type: 1
game_time: 668
delay: 300
spectators: 437
game_mode: 2
average_mmr: 0
team_name_radiant: "Royal Never Give Up"
team_name_dire: "ForTheDream"
sort_score: 9437
last_update_time: 1543480192.0
radiant_lead: 1864
radiant_score: 10
dire_score: 5
players {
account_id: 163587550
hero_id: 27
}
players {
account_id: 114787051
hero_id: 15
}
players {
account_id: 137925613
hero_id: 33
}
players {
account_id: 142139318
hero_id: 41
}
players {
account_id: 136421659
hero_id: 75
}
players {
account_id: 148215639
hero_id: 89
}
players {
account_id: 139822354
hero_id: 23
}
players {
account_id: 89598554
hero_id: 64
}
players {
account_id: 156662698
hero_id: 53
}
players {
account_id: 119576842
hero_id: 107
}
building_state: 5374089
team_logo_radiant: 972104754092650543
team_logo_dire: 963103354433927743
}
game_list {
activate_time: 1543479808
deactivate_time: 0
server_steam_id: 90121276992082946
lobby_id: 25894769523900909
league_id: 10482
lobby_type: 1
game_time: 524
delay: 300
spectators: 377
game_mode: 2
average_mmr: 0
team_name_radiant: "Vici Gaming"
team_name_dire: "INVICTUS GAMING"
sort_score: 9377
last_update_time: 1543480192.0
radiant_lead: 0
radiant_score: 0
dire_score: 0
players {
account_id: 107803494
hero_id: 0
}
players {
account_id: 143693439
hero_id: 0
}
players {
account_id: 139937922
hero_id: 0
}
players {
account_id: 182331313
hero_id: 0
}
players {
account_id: 101259972
hero_id: 0
}
players {
account_id: 137193239
hero_id: 0
}
players {
account_id: 110837826
hero_id: 0
}
players {
account_id: 140680642
hero_id: 0
}
players {
account_id: 103940975
hero_id: 0
}
players {
account_id: 202217968
hero_id: 0
}
building_state: 19138340
team_logo_radiant: 845963870798027729
team_logo_dire: 975479762873971573
}
game_list {
activate_time: 1543477888
deactivate_time: 0
server_steam_id: 90121276987195395
lobby_id: 25894769524973063
league_id: 0
lobby_type: 7
game_time: 2029
delay: 120
spectators: 839
game_mode: 22
average_mmr: 7164
sort_score: 8503
last_update_time: 1543480192.0
radiant_lead: 1372
radiant_score: 28
dire_score: 35
players {
account_id: 314355206
hero_id: 44
}
players {
account_id: 48542571
hero_id: 78
}
players {
account_id: 35950371
hero_id: 50
}
players {
account_id: 113710995
hero_id: 26
}
players {
account_id: 116585378
hero_id: 89
}
players {
account_id: 50580004
hero_id: 8
}
players {
account_id: 237610210
hero_id: 43
}
players {
account_id: 293904640
hero_id: 97
}
players {
account_id: 837312001
hero_id: 86
}
players {
account_id: 112594983
hero_id: 75
}
building_state: 16384228
}
game_list {
activate_time: 1543480064
deactivate_time: 0
server_steam_id: 90121280070087686
lobby_id: 25894769537267625
league_id: 0
lobby_type: 7
game_time: -79
delay: 120
spectators: 0
game_mode: 22
average_mmr: 7295
sort_score: 7795
last_update_time: 1543480192.0
radiant_lead: 228
radiant_score: 0
dire_score: 0
players {
account_id: 401653350
hero_id: 10
}
players {
account_id: 119535307
hero_id: 40
}
players {
account_id: 330191088
hero_id: 77
}
players {
account_id: 102481068
hero_id: 85
}
players {
account_id: 94762375
hero_id: 86
}
players {
account_id: 101897410
hero_id: 44
}
players {
account_id: 104504914
hero_id: 50
}
players {
account_id: 186888336
hero_id: 52
}
players {
account_id: 164532005
hero_id: 114
}
players {
account_id: 122258583
hero_id: 97
}
building_state: 4784201
}
game_list {
activate_time: 1543478784
deactivate_time: 0
server_steam_id: 90121280462953474
lobby_id: 25894769529983892
league_id: 0
lobby_type: 7
game_time: 1100
delay: 120
spectators: 80
game_mode: 22
average_mmr: 7126
sort_score: 7706
last_update_time: 1543480192.0
radiant_lead: -1291
radiant_score: 20
dire_score: 16
players {
account_id: 173422507
hero_id: 14
}
players {
account_id: 89438610
hero_id: 97
}
players {
account_id: 100594231
hero_id: 44
}
players {
account_id: 364318819
hero_id: 121
}
players {
account_id: 206144913
hero_id: 120
}
players {
account_id: 117672038
hero_id: 69
}
players {
account_id: 196931374
hero_id: 76
}
players {
account_id: 100311765
hero_id: 93
}
players {
account_id: 361518412
hero_id: 85
}
players {
account_id: 111392103
hero_id: 27
}
building_state: 5308618
}
game_list {
activate_time: 1543478400
deactivate_time: 0
server_steam_id: 90121280052236290
lobby_id: 25894769527855401
league_id: 0
lobby_type: 7
game_time: 1560
delay: 120
spectators: 39
game_mode: 22
average_mmr: 7072
sort_score: 7611
last_update_time: 1543480192.0
radiant_lead: -9129
radiant_score: 18
dire_score: 29
players {
account_id: 101240880
hero_id: 67
}
players {
account_id: 121404228
hero_id: 46
}
players {
account_id: 228517469
hero_id: 21
}
players {
account_id: 186946175
hero_id: 5
}
players {
account_id: 104206045
hero_id: 22
}
players {
account_id: 120852812
hero_id: 107
}
players {
account_id: 442056188
hero_id: 78
}
players {
account_id: 169756712
hero_id: 10
}
players {
account_id: 173476224
hero_id: 23
}
players {
account_id: 113874152
hero_id: 9
}
building_state: 5374234
}
game_list {
activate_time: 1543478272
deactivate_time: 0
server_steam_id: 90121277662774282
lobby_id: 25894769526631854
league_id: 0
lobby_type: 7
game_time: 1662
delay: 120
spectators: 26
game_mode: 22
average_mmr: 7038
sort_score: 7564
last_update_time: 1543480192.0
radiant_lead: -12626
radiant_score: 14
dire_score: 27
players {
account_id: 193851835
hero_id: 31
}
players {
account_id: 174821179
hero_id: 51
}
players {
account_id: 126417273
hero_id: 11
}
players {
account_id: 90547237
hero_id: 80
}
players {
account_id: 6922000
hero_id: 102
}
players {
account_id: 152545459
hero_id: 25
}
players {
account_id: 107088064
hero_id: 10
}
players {
account_id: 116782914
hero_id: 78
}
players {
account_id: 134741940
hero_id: 86
}
players {
account_id: 115613584
hero_id: 50
}
building_state: 9634019
}
game_list {
activate_time: 1543478784
deactivate_time: 0
server_steam_id: 90121279853697031
lobby_id: 25894769529573496
league_id: 0
lobby_type: 7
game_time: 1274
delay: 120
spectators: 17
game_mode: 22
average_mmr: 6980
sort_score: 7497
last_update_time: 1543480192.0
radiant_lead: -5916
radiant_score: 15
dire_score: 20
players {
account_id: 196228187
hero_id: 17
}
players {
account_id: 119939006
hero_id: 44
}
players {
account_id: 54811179
hero_id: 101
}
players {
account_id: 148603884
hero_id: 96
}
players {
account_id: 86772934
hero_id: 121
}
players {
account_id: 384872547
hero_id: 120
}
players {
account_id: 149068953
hero_id: 97
}
players {
account_id: 130271765
hero_id: 22
}
players {
account_id: 146711951
hero_id: 8
}
players {
account_id: 397742415
hero_id: 31
}
building_state: 8978587
}
game_list {
activate_time: 1543479680
deactivate_time: 0
server_steam_id: 90121280644043779
lobby_id: 25894769534932200
league_id: 0
lobby_type: 7
game_time: 219
delay: 120
spectators: 10
game_mode: 22
average_mmr: 6890
sort_score: 7400
last_update_time: 1543480192.0
radiant_lead: -444
radiant_score: 3
dire_score: 3
players {
account_id: 152569610
hero_id: 14
}
players {
account_id: 879229651
hero_id: 8
}
players {
account_id: 385295772
hero_id: 13
}
players {
account_id: 149792869
hero_id: 97
}
players {
account_id: 345803031
hero_id: 86
}
players {
account_id: 370177319
hero_id: 121
}
players {
account_id: 89871557
hero_id: 49
}
players {
account_id: 180011187
hero_id: 71
}
players {
account_id: 877696078
hero_id: 93
}
players {
account_id: 161539806
hero_id: 102
}
building_state: 4784201
}
specific_games: false
bot_game {
activate_time: 1543480192
deactivate_time: 0
server_steam_id: 90121277027880967
lobby_id: 25894769529568622
league_id: 5683
lobby_type: 1
game_time: 1426
delay: 10
spectators: 1
game_mode: 1
average_mmr: 0
team_name_radiant: "BotExperiment"
team_name_dire: "PubSimulator"
sort_score: 5001
last_update_time: 1543480192.0
radiant_lead: 10578
radiant_score: 25
dire_score: 8
building_state: 10616970
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment