forked from proverbialsunrise/hockeyScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetStreamURL.py
More file actions
executable file
·155 lines (120 loc) · 4.09 KB
/
getStreamURL.py
File metadata and controls
executable file
·155 lines (120 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/local/bin/python2.7
import urllib2
import pdb
import pyperclip
import json
import datetime
import time
class Game:
""" holds data about a game
Attributes
date:
gameID:
homeTeamID:
awayTeamID:
homeTeamStream:
awayTeamStream:
"""
def __init__(self, homeTeamID, awayTeamID):
self.homeTeamID = homeTeamID
self.awayTeamID = awayTeamID
def printOut(self):
print self.homeTeamID + " vs. " + self.awayTeamID
print self.homeTeamID + ": " + self.homeTeamStream
print self.awayTeamID + ": " + self.awayTeamStream
def description(self):
return time.strftime("%d/%m/%Y %H:%M:%S", self.date) + ": " + self.homeTeamID + " vs. " + self.awayTeamID + " " + str(self.gameID)
def printStreams(self):
print "(1) " + self.homeTeamID + ": " + self.homeTeamStream
print "(2) " + self.awayTeamID + ": " + self.awayTeamStream
def addStreamsToGame(game):
ID1 = str(game.gameID)[4:6]
ID2 = str(game.gameID)[6:11]
jsonURL = "http://smb.cdnak.neulion.com/fs/nhl/mobile/feed_new/data/streams/2013/ipad/" + ID1 + "_" + ID2 + ".json"
req = urllib2.Request(jsonURL)
f = urllib2.urlopen(req)
streamObj = json.loads(f.read())
game.homeTeamStream = streamObj["gameStreams"]["ipad"]["home"]["live"]["bitrate0"]
game.awayTeamStream = streamObj["gameStreams"]["ipad"]["away"]["live"]["bitrate0"]
def gameFromJSON(gameJSON):
game = Game(gameJSON['h'], gameJSON['a'])
game.date = time.strptime(gameJSON['est'], "%Y%m%d %H:%M:%S")
game.gameID = gameJSON['id']
return game
def getAllGames(scheduleURL):
req = urllib2.Request(scheduleURL)
f = urllib2.urlopen(req)
jsonSchedule = f.read()
gameList = json.loads(jsonSchedule)
games = []
for gameJSON in gameList:
games.append(gameFromJSON(gameJSON))
return games
def getGames(scheduleURL, checkTime):
allGames=getAllGames(scheduleURL)
margin = datetime.timedelta(hours = 12)
todayGames = []
for game in allGames:
gameDT = datetime.datetime.fromtimestamp(time.mktime(game.date))
if checkTime - margin <= gameDT <= checkTime + margin:
try:
addStreamsToGame(game)
todayGames.append(game)
except KeyError:
continue
return todayGames
'''all_names = {
BOS : "Boston Bruins",
BUF : "Buffalo Sabres",
CGY : "Calgary Flames",
CHI : "Chicago Blackhawks",
DET : "Detroit Red Wings",
EDM : "Edmonton Oilers",
CAR : "Carolina Hurricanes",
LAK : "Los Angeles Kings",
MTL : "Montreal Canadiens",
DAL : "Dallas Stars",
NJD : "New Jersey Devils",
NYI : "New York Islanders",
NYR : "New York Rangers",
PHI : "Philadelphia Flyers",
PIT : "Pittsburgh Penguins",
COL : "Colorado Avalanche",
STL : "St. Louis Blues",
TOR : "Toronto Maple Leafs",
VAN : "Vancouver Canucks",
WSH : "Washington Capitals",
PHX : "Phoenix Coyotes",
SJS : "San Jose Sharks",
OTT : "Ottawa Senators",
TBL : "Tampa Bay Lightning",
ANA : "Anaheim Ducks",
FLA : "Florida Panthers",
CBJ : "Columbus Blue Jackets",
MIN : "Minnesota Wild",
NSH : "Nashville Predators",
WPG : "Winnipeg Jets"
}
'''
scheduleURL = "http://live.nhl.com/GameData/SeasonSchedule-20132014.json"
checkTime = datetime.datetime.now()
games = getGames(scheduleURL, checkTime)
#pdb.set_trace()
print ""
i = 1
for game in games:
print "Game " + str(i) + " --- " + game.description()
print ""
i += 1
gameNum = int(raw_input("Select a game number... ")) - 1
game = games[gameNum]
print "Selected " + game.description()
print "Available Streams:"
game.printStreams()
streamNum = int(raw_input("Select a stream number... "))
if streamNum == 1:
selectedStream = game.homeTeamStream
else:
selectedStream = game.awayTeamStream
pyperclip.copy(selectedStream)
print "Copied " + selectedStream + " to clipboard."