class TVBroadCast(object): def __init__(self): self._tmp = 'tmp.html' self._date = '' self._time = '' self._webApi = WebApi() def saveTmp(self, str): fp = file(self._tmp, 'w') fp.write(str) fp.close() def getDate(self, line): pat = '<td class="link04"><strong>(.+?)</strong>' ret = search(pat, line) if None != ret: date = ret.group(1) # TODO why group(0) matches full pat? # cut weekday suffix. date = date.split(' ')[0] pat = '([0-9]+).*?([0-9]+).*' ret = search(pat, date) #print ret.group(1) + " " + ret.group(2) self._date = ret.group(1) + "-" + ret.group(2) return True def getGame(self, line): # 先把时间和比赛分开 pat = '<td class="link04">([0-9:]+) *(.+?)</td>' ret = search(pat, line) if None != ret: time = ret.group(1) desc = ret.group(2) self._time = time self.getDetail(desc) def getDetail(self, desc): desc = replace(desc, '<strong><font color="#ED1C24">CCTV-5</font></strong>', 'CCTV5') pat = '.+?VS +(.+?) +(.*)' ret = search(pat, desc) if None != ret: guestTeam=ret.group(1) tvb=ret.group(2) self._webApi.addTvB(guestTeam, self._date, self._time, tvb) def start(self): fp = open(self._tmp) line = fp.readline() while line: if True != self.getDate(line): self.getGame(line) line = fp.readline() def get(self, url): #html = getHtml(url) #self.saveTmp(html) self.start()
def getGamesOfThisWeek(self): api = WebApi() ret=api.getGamesOfWeek(self._weekBegin, self._weekEnd) data = json.loads(ret)['data'] data = json.loads(data) for i in range(len(data)): #print data[i]['round'] + " " + data[i]['tournamentId'] self.storeData(data[i]['tournamentId'], data[i]['round']) print self._thisRound;
def getGamesOfThisWeek(self): api = WebApi() ret = api.getGamesOfWeek(self._weekBegin, self._weekEnd) data = json.loads(ret)["data"] data = json.loads(data) for i in range(len(data)): # print data[i]['round'] + " " + data[i]['tournamentId'] self.storeData(data[i]["tournamentId"], data[i]["round"]) print self._thisRound
#print data[i]['round'] + " " + data[i]['tournamentId'] self.storeData(data[i]['tournamentId'], data[i]['round']) print self._thisRound; def updateGames(self): sina = GamesFromSina() self.getGamesOfThisWeek() # After query, self._thisRound's value would like this: # {17: [17], 18: [16], 19: [18], 20: [16, 17], 21: [16]} keys = self._thisRound.keys() for i in range(len(keys)): tourId = keys[i] rounds = self._thisRound[keys[i]] for j in range(len(rounds)): leagueId = self._tourId2UrlId.get(tourId) if None != leagueId: print leagueId, rounds[j] sina.getRoundGames(leagueId, rounds[j]) sina.uploadRoundGames() if __name__ == "__main__": updater = UpdateSoccerGameTime() updater.updateGames() webApi = WebApi() webApi.updateParam('updateGameTime', '')
for i in range(len(data)): # print data[i]['round'] + " " + data[i]['tournamentId'] self.storeData(data[i]["tournamentId"], data[i]["round"]) print self._thisRound def updateGames(self): sina = GamesFromSina() self.getGamesOfThisWeek() # After query, self._thisRound's value would like this: # {17: [17], 18: [16], 19: [18], 20: [16, 17], 21: [16]} keys = self._thisRound.keys() for i in range(len(keys)): tourId = keys[i] rounds = self._thisRound[keys[i]] for j in range(len(rounds)): leagueId = self._tourId2UrlId.get(tourId) if None != leagueId: print leagueId, rounds[j] sina.getRoundGames(leagueId, rounds[j]) sina.uploadRoundGames() if __name__ == "__main__": updater = UpdateSoccerGameTime() updater.updateGames() webApi = WebApi() webApi.updateParam("updateGameTime", "")
def __init__(self): self._tmp = 'tmp.html' self._date = '' self._time = '' self._webApi = WebApi()
import sys import re from WebApi import WebApi date = None time = None guestTeam = None hostTeam = None matches = 0 webHandler = WebApi() def getPage(file): file = open(file) if not file: print "open %s error" % file sys.exit() line = file.readline() while line: checkDate(line) # TODO if is date, then jump next 2 checkTime(line) checkTeam(line) line = file.readline() file.close() global matches print matches + 1