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

import sys,os,re
from CopyArticle import copyArticle

ID=long(sys.argv[0])
if not ID:
	sys.exit(1)

title,data=copyArticle(ID,0)
print title
print title
if title and type(title)==str:
	destdir='download'
	try:
		os.mkdir(destdir)
	except OSError:
		pass
	title=re.sub(r'[\:\?\*\\\/\>\<]','_',title)
	try:
		f=file(destdir+'\\'+title+'.txt', 'wt') # U?
		f.write(data)
		f.close()
	except IOError, errinfo:
		print title+'.txt'+': '+errinfo[1]