Example #1
0
def getTmpContent(headers):
	print 'Please enter a number:'
	n = raw_input()
	urls = db.selectTmpFilm(int(n))
	
	minute = 8*60
	
	start = int(time.time())
	for ur in urls:	
		current_time = int(time.time())
		cost = current_time - start
		if( (cost != 0) and (cost%minute == 0)):		
			second = random.uniform(60, 180)
			print 'sleep ' + str(second) + '.....'			
			time.sleep(second)
			print 'wake up!Start to work...'
		
		url = ur[3]
		tag_id = ur[2]
		film_id = ur[0]	

		# global req_header
		# html = cheat_get_html(url,req_header)
		
		
		try:
			# html = getDouban_module.getHtml(url)
			# global req_header
			w = random.randint(0, 1)
			req_header = headers[w]
			html = cheat_get_html(url,req_header)
			
		except:
			msg = 'get ' + str(tag_id) + ' ' + url + ' faild\n'
			filename = 'filmError.txt'
			print 'Error:' + msg + '\n'
			getDouban_module.saveData(msg,filename)
			error_if = 1
			db.setTempFilmError(film_id,error_if)
			continue
		tmp_title = getDouban_module.getTitle(html)
		# print title
		tmp_info = getDouban_module.getInfo(html)
		tmp_related_info = getDouban_module.getRelatedInfo(html)
		db.saveTmpFilmContent(tag_id, tmp_title, tmp_info,  tmp_related_info)
		db.setTmpFilmIf(1,film_id)
		msg = tmp_title + ' save success'
		msg = msg.decode('utf-8').encode('gbk','ignore')
		print msg
	print 'for loop is over'		
	music()
Example #2
0
def getTmpContent(headers):
    print 'Please enter a number:'
    n = raw_input()
    urls = db.selectTmpFilm(int(n))

    minute = 8 * 60

    start = int(time.time())
    for ur in urls:
        current_time = int(time.time())
        cost = current_time - start
        if ((cost != 0) and (cost % minute == 0)):
            second = random.uniform(60, 180)
            print 'sleep ' + str(second) + '.....'
            time.sleep(second)
            print 'wake up!Start to work...'

        url = ur[3]
        tag_id = ur[2]
        film_id = ur[0]

        # global req_header
        # html = cheat_get_html(url,req_header)

        try:
            # html = getDouban_module.getHtml(url)
            # global req_header
            w = random.randint(0, 1)
            req_header = headers[w]
            html = cheat_get_html(url, req_header)

        except:
            msg = 'get ' + str(tag_id) + ' ' + url + ' faild\n'
            filename = 'filmError.txt'
            print 'Error:' + msg + '\n'
            getDouban_module.saveData(msg, filename)
            error_if = 1
            db.setTempFilmError(film_id, error_if)
            continue
        tmp_title = getDouban_module.getTitle(html)
        # print title
        tmp_info = getDouban_module.getInfo(html)
        tmp_related_info = getDouban_module.getRelatedInfo(html)
        db.saveTmpFilmContent(tag_id, tmp_title, tmp_info, tmp_related_info)
        db.setTmpFilmIf(1, film_id)
        msg = tmp_title + ' save success'
        msg = msg.decode('utf-8').encode('gbk', 'ignore')
        print msg
    print 'for loop is over'
    music()
Example #3
0
def getU():
	print 'Enter a number:'
	n = raw_input()	
	res = db.selectTags(int(n))
	for r in res:
		url = r[3]
		tag_id = int(r[0])
		start = time.time()	
		getUrls(url,	tag_id)
		end = time.time()
		cost = end - start
		log = str(tag_id) + ' cost ' + str(cost) + '\n'
		print log
		getDouban_module.saveData(log,'time.txt')		
	# else:
	print 'for loop is over'		
	music()
	print 'Do you want to continue?Y/N'
	yn = raw_input()
	if yn == 'Y':
		getU()
	elif yn == 'N':
		print 'Game over!'
Example #4
0
def getU():
    print 'Enter a number:'
    n = raw_input()
    res = db.selectTags(int(n))
    for r in res:
        url = r[3]
        tag_id = int(r[0])
        start = time.time()
        getUrls(url, tag_id)
        end = time.time()
        cost = end - start
        log = str(tag_id) + ' cost ' + str(cost) + '\n'
        print log
        getDouban_module.saveData(log, 'time.txt')
    # else:
    print 'for loop is over'
    music()
    print 'Do you want to continue?Y/N'
    yn = raw_input()
    if yn == 'Y':
        getU()
    elif yn == 'N':
        print 'Game over!'