Esempio n. 1
0
File: P.py Progetto: MrLpk/nba
    def start(self):
        _path = 'db/1/'
        _data = []
        _count = 1

        for x in os.listdir(_path):
            if x == '.DS_Store':
                continue
            _p = _path + '3704.db'
            # print 'path:',  _p
            _f = open(_p, 'r').read()
            _json = json.loads(_f)
            '''view one player'''
            for i in _json:
                _point = self.count(_json[i])
                _playoffsP = self.count_playoffs(_json[i])
                _o = {i: [{'n': _point}, {'o': _playoffsP}]}
                _data.append(_o)
                print u'%s -- %f -- %d times' % (i, _point, _count)
                print u'%s -- %f -- %d times' % (i, _playoffsP, _count)
                _count += 1
            # break
            return
        _json = json.dumps({'p': _data})
        m = MTool()
        m.save(self.path, _json)
Esempio n. 2
0
def countAllAverage():
	''' count the average of all '''
	PATH = 'AScore.dt'
	_twAllScore = 0
	_tlAllScore = 0
	_fwAllScore = 0
	_flAllScore = 0
	_times = 0
	_content = open(PATH, 'r').read()
	_object = json.loads(_content)
	for _item in _object:
		for x in _item:
			x = _item[x]
			# print x
			_twAllScore += x['t']['w']
			_tlAllScore += x['t']['l']
			_fwAllScore += x['f']['w']
			_flAllScore += x['f']['l']
			_times += 1

	_twAverageScore = _twAllScore / float(_times)
	_tlAverageScore = _tlAllScore / float(_times)
	_fwAverageScore = _fwAllScore / float(_times)
	_flAverageScore = _flAllScore / float(_times)

	_str = {'tw':_twAverageScore,
			'tl':_tlAverageScore,
			'fw':_fwAverageScore,
			'fl':_flAverageScore
			}
	_json = json.dumps(_str)
	m = MTool()
	m.save('Average.dt', _json)
Esempio n. 3
0
def countAllAverage():
    ''' count the average of all '''
    PATH = 'AScore.dt'
    _twAllScore = 0
    _tlAllScore = 0
    _fwAllScore = 0
    _flAllScore = 0
    _times = 0
    _content = open(PATH, 'r').read()
    _object = json.loads(_content)
    for _item in _object:
        for x in _item:
            x = _item[x]
            # print x
            _twAllScore += x['t']['w']
            _tlAllScore += x['t']['l']
            _fwAllScore += x['f']['w']
            _flAllScore += x['f']['l']
            _times += 1

    _twAverageScore = _twAllScore / float(_times)
    _tlAverageScore = _tlAllScore / float(_times)
    _fwAverageScore = _fwAllScore / float(_times)
    _flAverageScore = _flAllScore / float(_times)

    _str = {
        'tw': _twAverageScore,
        'tl': _tlAverageScore,
        'fw': _fwAverageScore,
        'fl': _flAverageScore
    }
    _json = json.dumps(_str)
    m = MTool()
    m.save('Average.dt', _json)
Esempio n. 4
0
File: P.py Progetto: MrLpk/nba
	def start(self):
		_path = 'db/1/'
		_data = []
		_count = 1

		for x in os.listdir(_path):
			if x == '.DS_Store':
				continue
			_p = _path + '3704.db'
			# print 'path:',  _p
			_f = open(_p, 'r').read()
			_json = json.loads(_f)

			'''view one player'''
			for i in _json:
				_point = self.count(_json[i])
				_playoffsP = self.count_playoffs(_json[i])
				_o = {i:[{'n':_point}, {'o':_playoffsP}]}
				_data.append(_o)
			 	print u'%s -- %f -- %d times' %(i, _point, _count)
			 	print u'%s -- %f -- %d times' %(i, _playoffsP, _count)
			 	_count+=1
			# break
			return
		_json = json.dumps({'p':_data})
		m = MTool()
		m.save(self.path, _json)
Esempio n. 5
0
def countAllTeam():
	''' count every team's point '''
	_allTeam = []
	for x in xrange(1,31):
		PATH = 'db/%d.dt' %x
		_json = open(PATH, 'r').read()
		_obj = json.loads(_json)

		_result = countOneTeam1(_obj) 
		_allTeam.append({str(x):_result})

	_json = json.dumps(_allTeam)
	m = MTool()
	m.save('AScore.dt', _json)
Esempio n. 6
0
def countAllTeam():
    ''' count every team's point '''
    _allTeam = []
    for x in xrange(1, 31):
        PATH = 'db/%d.dt' % x
        _json = open(PATH, 'r').read()
        _obj = json.loads(_json)

        _result = countOneTeam1(_obj)
        _allTeam.append({str(x): _result})

    _json = json.dumps(_allTeam)
    m = MTool()
    m.save('AScore.dt', _json)
Esempio n. 7
0
def collectMatch1(startYear, endYear):
	m = MTool()

	for x in xrange(10,13):
		URL = 'http://liansai.500.com/lq/177/proc/980/0_%d_%d/' %(startYear, x)
		print URL
		_content = urllib2.urlopen(URL).read()
		_name = 'match/%d-%d.html' %(startYear, x)
		m.save(_name, _content)

	for x in xrange(1, 5):
		URL = 'http://liansai.500.com/lq/177/proc/980/0_%d_%d/' %(endYear, x)
		print URL
		_content = urllib2.urlopen(URL).read()
		_name = 'match/%d-%d.html' %(endYear, x)
		m.save(_name, _content)
Esempio n. 8
0
def collectionAllTeam():
	''' view all teams '''
	for x in xrange(1,31):
		zhuURL = 'http://liansai.500.com/lq/177/team/%d/schedule_%d/' %(x, 1)
		keURL  = 'http://liansai.500.com/lq/177/team/%d/schedule_%d/' %(x, 2)

		_zhuContent = urllib2.urlopen(zhuURL).read()
		_keContent  = urllib2.urlopen(keURL).read()

		_zhuObj = collectionOneTeam(_zhuContent)
		_keObj  = collectionOneTeam(_keContent, False)

		_obj = {'t':_zhuObj, 'f':_keObj}
		_json = json.dumps(_obj)
		m = MTool()
		m.save('db/%d.dt' %x, _json)
Esempio n. 9
0
def collectionAllTeam():
    ''' view all teams '''
    for x in xrange(1, 31):
        zhuURL = 'http://liansai.500.com/lq/177/team/%d/schedule_%d/' % (x, 1)
        keURL = 'http://liansai.500.com/lq/177/team/%d/schedule_%d/' % (x, 2)

        _zhuContent = urllib2.urlopen(zhuURL).read()
        _keContent = urllib2.urlopen(keURL).read()

        _zhuObj = collectionOneTeam(_zhuContent)
        _keObj = collectionOneTeam(_keContent, False)

        _obj = {'t': _zhuObj, 'f': _keObj}
        _json = json.dumps(_obj)
        m = MTool()
        m.save('db/%d.dt' % x, _json)
Esempio n. 10
0
def downloadTeamData(teams, years, months):
	# time.sleep(1)
	strMonth = ''
	if months < 10:
		strMonth = '0%s' %months
	else:
		strMonth = '%s' %months
	URL = 'http://nba.sports.sina.com.cn/team_match.php?month=1&years=%d&months=%s&teams=%d' %(years, strMonth, teams)
	      
	# print 'URL----',URL
	html = urllib2.urlopen(URL).read()

	m = MTool()
	name = u'%d年-%d月.html' %(years, months)
	path = '%d/' %teams
	path2 = '%d/' %years
	m.save(name, html, True, path, path2)
Esempio n. 11
0
def downloadTeamData(teams, years, months):
    # time.sleep(1)
    strMonth = ''
    if months < 10:
        strMonth = '0%s' % months
    else:
        strMonth = '%s' % months
    URL = 'http://nba.sports.sina.com.cn/team_match.php?month=1&years=%d&months=%s&teams=%d' % (
        years, strMonth, teams)

    # print 'URL----',URL
    html = urllib2.urlopen(URL).read()

    m = MTool()
    name = u'%d年-%d月.html' % (years, months)
    path = '%d/' % teams
    path2 = '%d/' % years
    m.save(name, html, True, path, path2)
Esempio n. 12
0
def downloadMatchDate(years, months):

	strMonth = ''
	if months < 10:
		strMonth = '0%s' %months
	else:
		strMonth = '%s' %months
	URL = 'http://nba.sports.sina.com.cn/match_result.php?day=0&years=%d&months=%s&teams=' %(years, strMonth)
	

	html = urllib2.urlopen(URL).read()

	m = MTool()
	name = u'%d-%d.html' %(years, months)
	if not os.path.isdir('match/'):
		os.mkdir('match/')
	path = 'match/date/'
	path2 = '%d/' %years
	m.save(name, html, True, path, path2)
Esempio n. 13
0
def downloadMatchDate(years, months):

    strMonth = ''
    if months < 10:
        strMonth = '0%s' % months
    else:
        strMonth = '%s' % months
    URL = 'http://nba.sports.sina.com.cn/match_result.php?day=0&years=%d&months=%s&teams=' % (
        years, strMonth)

    html = urllib2.urlopen(URL).read()

    m = MTool()
    name = u'%d-%d.html' % (years, months)
    if not os.path.isdir('match/'):
        os.mkdir('match/')
    path = 'match/date/'
    path2 = '%d/' % years
    m.save(name, html, True, path, path2)
Esempio n. 14
0
def collectMatch(startYear, endYear):
    m = MTool()

    for x in xrange(10, 13):
        URL = 'http://liansai.500.com/lq/177/proc/980/0_%d_%d/' % (startYear,
                                                                   x)
        print URL
        _content = urllib2.urlopen(URL).read()
        _str = executMatch(_content)
        return _str
        # _name = 'match/%d-%d.html' %(startYear, x)
        # m.save(_name, _content)
        break
    return
    for x in xrange(1, 5):
        URL = 'http://liansai.500.com/lq/177/proc/980/0_%d_%d/' % (endYear, x)
        print URL
        _content = urllib2.urlopen(URL).read()
        _name = 'match/%d-%d.html' % (endYear, x)
        m.save(_name, _content)
Esempio n. 15
0
def downloadMatchResult(years):

	INDEX = 'http://nba.sports.sina.com.cn/look_scores.php?id='
	m = MTool();

	if not os.path.isdir('match/scores/'):
		os.mkdir('match/scores/')

	if not os.path.isdir('match/scores/%d/' %years):
		os.mkdir('match/scores/%d/' %years)

	for x in xrange(2, 13):

		# print 'sleep 10 second...'
		# time.sleep(10)

		_path = u'match/date/%d/%d-%d.html' %(years, years, x)
		f = open(_path, 'r').read()
		# key1 = '<td width="90" height="25">(.*)</td>'
		key1 = '<a href="look_scores\.php\?id=(.*)" target="_blank">'

		r1 = re.findall(key1, f)
		
		i = 1
		for y in r1:
			name = '%s.html' %i
			path = 'match/scores/%d/%d/' %(years, x)
			filename = path + name
			if not os.path.exists(filename):
				_url = INDEX + y
				html = urllib2.urlopen(_url).read()
				m.save(name, html, False, path)
			else:
				print 'You already have ' + filename

			i+=1
Esempio n. 16
0
def downloadMatchResult(years):

    INDEX = 'http://nba.sports.sina.com.cn/look_scores.php?id='
    m = MTool()

    if not os.path.isdir('match/scores/'):
        os.mkdir('match/scores/')

    if not os.path.isdir('match/scores/%d/' % years):
        os.mkdir('match/scores/%d/' % years)

    for x in xrange(2, 13):

        # print 'sleep 10 second...'
        # time.sleep(10)

        _path = u'match/date/%d/%d-%d.html' % (years, years, x)
        f = open(_path, 'r').read()
        # key1 = '<td width="90" height="25">(.*)</td>'
        key1 = '<a href="look_scores\.php\?id=(.*)" target="_blank">'

        r1 = re.findall(key1, f)

        i = 1
        for y in r1:
            name = '%s.html' % i
            path = 'match/scores/%d/%d/' % (years, x)
            filename = path + name
            if not os.path.exists(filename):
                _url = INDEX + y
                html = urllib2.urlopen(_url).read()
                m.save(name, html, False, path)
            else:
                print 'You already have ' + filename

            i += 1