def check_dota2(): dota2 = MatchScraper() match_history = [] while True: live_matches = dota2.find_live_matches() for game in live_matches: if game.match_id not in match_history: print('\a', 'Live game found!') print( '{} ({}) vs {} ({})\n\t-Tournament: {}\n\t-Url: {}'.format( game.team1, game.team1_bet, game.team2, game.team2_bet, game.tournament, game.url)) match_history.extend([game.match_id for game in live_matches]) [ print('\t-Stream', index, ':', stream) for index, stream in enumerate(game.get_streams()) ] sleep(5)
import json from gosu_gamers.gg_match import MatchScraper ''' This is example on how to create a matchticker that outputs json file with current match data as a json file. Comment heavy ''' #1. we create scraper, in this case we use general scraper that scrapes all games, if you want to scrape specific game # see <game_name>MatchScraper() objects,i.e. Dota2MatchScraper match_scraper = MatchScraper() # find live matches live_matches = match_scraper.find_live_matches() # Now live matches have no proper label in matches page, let set it to 'live' for live_match in live_matches: live_match.live_in = 'Live' # find upcoming matches upcoming_matches = match_scraper.find_upcoming_matches() # now we can do whatever we want with that data, in this example lets save all that in json format which can be # read by our website to display the results games_dict = {'games': []} for match in live_matches + upcoming_matches: games_dict['games'].append(match.__dict__( )) # here we go through every object and save it's __dict__ value with open('matchticker.json', 'w') as json_file: json_file.write(json.dumps(games_dict))