#!/usr/bin/python

import sys , os

try:
	from cfg import CFG
except:
	pass
from cPickle import dump

from urllib import quote
from ListParser import *
from ArticleParser import *
from RSSMaker import *
from HtmlStrip import strip
from RSSReader import GetLastArticleTime
from RSSWriter import CheckIt

Listdata = getData(CFG["ZBINFO"]["url"])
ArticleDataList = []
for url , time in  DataParser(Listdata):
	url = os.path.join( CFG["BASEURL"] , url ) 
	ArticleData = getData( url )
	ArticleDataList.append(ArticleParse(ArticleData) )
	ArticleDataList[-1]["TIME"] = time
	#ArticleDataList[-1]["URL"] = quote(url)
	ArticleDataList[-1]["URL"] = url
	#break
NewRss = RssMaker(ArticleDataList,CFG,strip=strip)
if os.path.exists(CFG["ZBINFO"]["xmlfile"]):
	if CheckIt(NewRss,CFG["ZBINFO"]["xmlfile"],GetLastArticleTime):
		print "NEW!"
		raise SystemExit
NewRss.seek(0)
file(CFG["ZBINFO"]["xmlfile"],'w').write(NewRss.read())
