#!/usr/bin/python
# -*- coding: UTF-8 -*-

import urllib



def isData(lines):
	if len(lines) > 6:
		if '¿ù' in lines[-4]:
			return True
		else:
			return False
	else:	
		return False


def getData(url):
	opener = urllib.URLopener()
	datafp = opener.open(url)
	return  datafp.readlines()

def GetOne(datalist):
	#time = datalist[-4][ datalist[-4].find("title='") + 6 : ("'",1)[0]
	time = datalist[-4].split("title='",1)[1].split("'",1)[0]
	url = datalist[-6].split('a href="',1)[1].split(' ',1)[:-1][0] 
	return ( url[: url.find("&PHPSESSID")] , time )

def DataParser(data):
	Tr = False
	DataBuffer = []
	Articles = []
	for lines in data:
		if lines.startswith("<tr") and Tr is not True:
			DataBuffer = []
			Tr = True
		if Tr is True:
			DataBuffer.append(lines)
		if Tr is True and lines.startswith("</tr") and lines.strip() == "</tr>":
			if isData(DataBuffer):
				Articles.append(GetOne(DataBuffer))
			Tr = False
	return Articles
