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


def ArticleParse(data):
	lc = 0
	Topic = False
	Author = False
	Homepage = False
	Contents = False
	ContentsEnd = False

	for lines in data:
		if Author is False:
			if 'ÀÌ ¸§ &nbsp;&nbsp;' in lines:
				AuthorLine = lc + 1
				Author = True
		elif Homepage is False:
			if 'Homepage &nbsp;&nbsp;' in lines:
				HomepageLine = lc + 1
				Homepage = True
		elif Topic is False:
			if 'Á¦ ¸ñ &nbsp;&nbsp;' in lines:
				TopicLine = lc + 1
				Topic = True
		elif Contents is False:
			if lines.startswith('     <span style=line-height:160%>'):
				ContentsS = lc + 1
				Contents = True
		elif ContentsEnd is False:
			if lines.startswith('     </span>'):
				ContentsE = lc - 1
				ContentsEnd = True
				break
		else:
			pass
		lc +=1
	CON = {}
	#print "AutorLine :" + data[AuthorLine][ data[AuthorLine].find('>') + 1 : -6 ]
	CON["AUTHOR"] = data[AuthorLine][ data[AuthorLine].find('>') + 1 : -6 ]
	try:
		#print "HomePageInfo :" + data[HomepageLine].split("'",2)[1]
		CON["HOMEPAGE"] = data[HomepageLine].split("'",2)[1]
	except:
		CON["HOMEPAGE"] = None
	#print "TopicInfo:" + data[TopicLine][ data[TopicLine].find('>') + 1 : -6 ]
	CON["TOPIC"] =  data[TopicLine][ data[TopicLine].find('>') + 1 : -6 ]
	#print "con:" + repr(data[ContentsS:ContentsE])
	CON["CONTENTS"] = data[ContentsS:ContentsE]
	return CON
