Example #1
0
def writeXML(path, xml):
    '''创建xml'''
    currentDirName = path.split('/')[-1]
    print '当前目录名称============='
    print path
    try:
        file = open(path, mode='w')
        file.write(MDCompressFile.gzip_compress(xml.toprettyxml(indent = "\t", newl = "\n", encoding = "utf-8")))
        file.close()
        print '文件目录', path
        print '生成xml成功。。'

    except Exception, e:
        print e
Example #2
0
def writeXML(path, xml):
    '''创建xml'''
    currentDirName = path.split('/')[-1]
    print '当前目录名称============='
    print path
    try:
        file = open(path, mode='w')
        file.write(
            MDCompressFile.gzip_compress(
                xml.toprettyxml(indent="\t", newl="\n", encoding="utf-8")))
        file.close()
        print '文件目录', path
        print '生成xml成功。。'

    except Exception, e:
        print e
Example #3
0
def downXBRLDoc(url, cik,params):
	'''
	下载xbrl文档
	'''
	print "开始下载URL:", url
	period = params[0]
	accepted = params[1].split(' ')[0]
	try:
		content = downUrlRetrieve(url)
		fileDir = os.path.join(os.getcwd() , 'XBRLDown_1' , cik+'#'+accepted+'#'+period)
		fileName = os.path.basename(url)
		if not os.path.exists(fileDir):
			os.makedirs(fileDir)
			print '创建目录。。', fileDir
		desktopPath = os.path.join(fileDir, fileName)
		print '本地化地址-------------' , desktopPath
		print  time.strftime('%Y-%m-%d %X', time.localtime( time.time() ) )
		with open(desktopPath, "wb") as code:
			code.write(MDCompressFile.gzip_compress(content))
#			code.write(content)
	except Exception,e :
		print e
		print '出错了..'
Example #4
0
def downUrlRetrieve(dirName, url, fileName, files):
    '''
    下载URL
    '''
    print "downloading with requests"
    try:
        r = requests.get(url)
        fileDir = os.path.join(os.path.expanduser("/"),'home','XBRL', '%s' % dirName)
        if not os.path.exists(fileDir):
            os.makedirs(fileDir)
            print '创建目录。。', fileDir
        desktopPath = os.path.join(fileDir, fileName)
        with open(desktopPath, "wb") as code:
            code.write(MDCompressFile.gzip_compress(r.content))
            # print '当前目录数为', dirCount
            print  time.strftime('%Y-%m-%d %X', time.localtime(time.time()))
            print '写入文件-------------' , desktopPath
            # code.write(r.content)
    except Exception,e :
        print e
        print "+++++++++++++++++++++++++++++++++++++"
        # consur.fail.insert(files)
        print '错误!插入数据库'
Example #5
0
def downUrlRetrieve(dirName, url, fileName, files):
    '''
    下载URL
    '''
    print "downloading with requests"
    try:
        r = requests.get(url)
        fileDir = os.path.join(os.path.expanduser("/"), 'home', 'XBRL',
                               '%s' % dirName)
        if not os.path.exists(fileDir):
            os.makedirs(fileDir)
            print '创建目录。。', fileDir
        desktopPath = os.path.join(fileDir, fileName)
        with open(desktopPath, "wb") as code:
            code.write(MDCompressFile.gzip_compress(r.content))
            # print '当前目录数为', dirCount
            print time.strftime('%Y-%m-%d %X', time.localtime(time.time()))
            print '写入文件-------------', desktopPath
            # code.write(r.content)
    except Exception, e:
        print e
        print "+++++++++++++++++++++++++++++++++++++"
        # consur.fail.insert(files)
        print '错误!插入数据库'