Skip to content

Instantly share code, notes, and snippets.

@rossengeorgiev
Last active November 27, 2016 22:55
Show Gist options
  • Save rossengeorgiev/02ad8cb8cea2f5a2f23799dff3f78eeb to your computer and use it in GitHub Desktop.
Save rossengeorgiev/02ad8cb8cea2f5a2f23799dff3f78eeb to your computer and use it in GitHub Desktop.
change filename
#!/usr/bin/env python
#
# pip install steam, dota2
#
import logging
import gevent
from steam import SteamClient
from dota2 import Dota2Client
from dota2.enums import EDOTAGCMsg
logging.basicConfig(format='[%(asctime)s] %(levelname)s %(name)s: %(message)s', level=logging.INFO)
LOG = logging.getLogger("Bot")
client = SteamClient()
dota = Dota2Client(client)
@dota.on(EDOTAGCMsg.EMsgGCTopCustomGamesList)
def print_top_custom_list(message):
r = client.unified_messages.send_and_wait('PublishedFile.GetDetails#1', {
'publishedfileids': [message.game_of_the_day] + list(message.top_custom_games),
'includetags': False,
'includeadditionalpreviews': False,
'includechildren': False,
'includekvtags': False,
'includevotes': True,
'short_description': False,
'includeforsaledata': False,
'includemetadata': False,
'language': 0
}, timeout=7)
if r:
gotd = r.publishedfiledetails[0]
print "\nGame of the day: %d %.2f - %s\n" % (gotd.publishedfileid,
gotd.vote_data.score,
gotd.title,
)
for rank, pub in enumerate(r.publishedfiledetails[1:]):
print "% 2d: %d %.2f - %s" % (rank + 1,
pub.publishedfileid,
pub.vote_data.score,
pub.title,
)
print ""
@dota.on('connection_status')
def print_status(status):
LOG.info("GC Status: %s" % status)
@client.on('disconnected')
def just_reconnect():
if client.relogin_available:
client.reconnect()
@client.on('connected')
def just_login():
if client.relogin_available:
client.relogin()
client.cli_login()
try:
while True:
if not client.logged_on:
client.wait_event('logged_on')
LOG.info("Launching Dota 2")
dota.launch()
dota.wait_event(EDOTAGCMsg.EMsgGCTopCustomGamesList)
dota.exit()
LOG.info("Waiting 30 seconds")
gevent.sleep(30)
except KeyboardInterrupt:
if client.connected:
client.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment