18-09-18 关于建行基金全局函数的整合

# 编译日期:2018-08-23 15:03:20
# 版权所有:www.i-search.com.cn
# coding=utf-8


import xlwings as xw
import datetime
import os
import ubpa.iie as iie


#1创建目录
def create_dir(fund_dir):
now_time = datetime.datetime.now()
yesterday = now_time + datetime.timedelta(days=-1)
yesterday = yesterday.strftime('%Y%m%d')
newdir="E:\\fund_data\\"+fund_dir+"\\pic"+str(yesterday)
if not os.path.exists(newdir):
os.makedirs(newdir)
#print('====newdir====',newdir)
return(newdir)

def move_pic(fund_dir,fund_name):
create_dir(fund_dir)
now_time = datetime.datetime.now()
yesterday = now_time + datetime.timedelta(days=-1)
yesterday = yesterday.strftime('%Y%m%d')
newdir="E:\\fund_data\\"+fund_dir+"\\pic"+str(yesterday) #新目录是PIC+日期
path = "E:\\fund_data\\imgsss\\" #临时目录
dirs_pic = os.listdir(path) #把获取的图片名字按字母排序
#print(dirs_pic)
#对以上获取按字母排序的目录文件列表排序 以是按照创建时间对文件排序
oldfile_list=sorted(dirs_pic,key=lambda x: os.path.getctime(os.path.join(path,x
)))
#dir_list = sorted(dir_list,key=lambda x: os.path.getctime(os.path.join(DIR,x)))
oldfile = path+oldfile_list[0]
print("1oldfile======================================",oldfile)

#获取临时目录下的文件列表
newfile = newdir+"\\"+fund_name+".jpg"
#新文件名字,bankname是传入的参数
#print(oldfile)
#print(newfile)
if os.path.exists(newfile): #必须先判断目标目录是否存在文件
os.remove(newfile)
os.rename(oldfile,newfile)



#
#A获取所有数据
def get_data_all():
for x in range(5, 21):
for y in range(1, 8):

iie.get_text(url=r'https://mail.qq.com/cgi-bin/readmail?folderid=1&folderkey=1&&t=readmail&mailid=ZC3015-abwZcwIFuIb1Oix3ne_ib88&mode=pre&maxage=3600&base=12.16&ver=15253&sid=1QARIVAIgb-Aemw3&newwin=true&nocheckframe=true',selector=r'#mailContentContainer > TBODY:nth-of-type(1) > TR:nth-of-type({0}) > TD:nth-of-type({1})'.format(x, y),waitfor=10)
print("所有数据获取成功")

#A 第一行第一个数据和第二个数据
def get_data_line():
iie.get_text(url=r'http://www.scfund.com.cn/flagfund_2011/index.shtml',selector=r'DIV:nth-of-type(1) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(9) > TABLE:nth-of-type(1) > THEAD:nth-of-type(1) > TR:nth-of-type(1) > TH:nth-of-type(1)',waitfor=10)
iie.get_text(url=r'http://www.scfund.com.cn/flagfund_2011/index.shtml',selector=r'DIV:nth-of-type(1) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(9) > TABLE:nth-of-type(1) > THEAD:nth-of-type(1) > TR:nth-of-type(1) > TH:nth-of-type(2)',waitfor=10)
print("行数据获取成功")

#A 第一列第一个数据和第二个数据
def get_data_col():

iie.get_text(url=r'http://www.scfund.com.cn/flagfund_2011/index.shtml',selector=r'DIV:nth-of-type(1) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(9) > TABLE:nth-of-type(1) > THEAD:nth-of-type(1) > TR:nth-of-type(1) > TH:nth-of-type(1)',waitfor=10)
iie.get_text(url=r'http://www.scfund.com.cn/flagfund_2011/index.shtml',selector=r'DIV:nth-of-type(1) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(9) > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type(1) > TD:nth-of-type(1)',waitfor=10)
print("列数据获取成功")


#东吴基金获取数据1
def get_data_all_1():
list_data=[]
for x in range(1, 25): #每行 多少行
for y in range(1, 12): #每列 td 这个列数和截取的列表要出去空格和空要大于截取的个数
#iie.get_text(url=r'http://www.scfund.com.cn/flagfund_2011/index.shtml',selector=r'DIV:nth-of-type(1) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(9) > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type(1) > TD:nth-of-type(1)',waitfor=10)

data = iie.get_text(url=r'http://www.scfund.com.cn/flagfund_2011/index.shtml',selector=r'DIV:nth-of-type(1) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(2) > DIV:nth-of-type(9) > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type({0}) > TD:nth-of-type({1})'.format(x, y),waitfor=10)
if str(data).__contains__("型"):
continue
elif str(data) == '':
continue
elif str(data)== ' ':
continue
list_data.append(str(data))

#print(list_data)
return list_data


#东吴基金写入数据
def write_data():
list1 = get_data_all_1()
#print(list1)
iters = [iter(list1)]*9
a_data = list(zip(*iters))
#print(a_data)

num = '2'
for v in a_data:
b_num = 'A'+str(num)
v = list(v) #本身是个生成器 不加list是不能写入成功
#print('v',v)
wb = xw.Book(r"E:\fund_data\dongwu.xlsx")
sht = wb.sheets[0]
sht.range(b_num).value = v
num = str(int(num) + 1)
wb.save()

return ('写入成功')

#def write_data1():
# a = [1,2,3,4,5,6]
# wb = xw.Book(r'C:\Users\WY\Desktop\sheet.xls')
# sht = wb.sheets[0]
#sht.range('A1').value = a
#wb.save()

#import ubpa.iimg as iimg
#def click():
#iimg.do_click_pos(win_title=r'QQ邮箱 - 收件箱 - Internet Explorer',img_res_path=r'C:\ueba\studio-v6\project\foun_text\screenshots',image=r'a.png',button=r'left',curson=r'Center',offsetX=100,offsetY=200,times=1,image_size=r'201X53',waitfor=30)


def get_data_line():
iie.get_text(url=r'https://www.wjasset.com/index.html',selector=r'#tabCot_jj_1 > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type(1) > TH:nth-of-type(1)',waitfor=10)
iie.get_text(url=r'https://www.wjasset.com/index.html',selector=r'#tabCot_jj_1 > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type(1) > TH:nth-of-type(2)',waitfor=10)

def get_data_col():
iie.get_text(url=r'https://www.wjasset.com/index.html',selector=r'#tabCot_jj_1 > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type(1) > TH:nth-of-type(1)',waitfor=10)
iie.get_text(url=r'https://www.wjasset.com/index.html',selector=r'#tabCot_jj_1 > TABLE:nth-of-type(1) > TBODY:nth-of-type(1) > TR:nth-of-type(2) > TD:nth-of-type(1)',waitfor=10)

#万家基金获取数据
def get_data_all_w():
list_data_w=[]
for x in range(2,12): #每行 多少行
for y in range(1, 9): #每列 td 这个列数和截取的列表要出去空格和空要大于截取的个数
data = iie.get_text(url=r'https://www.wjasset.com/index.html',selector=r'#tabCot_jj_1 > TABLE:nth-of-type(1) >TBODY:nth-of-type(1) > TR:nth-of-type({0}) > TD:nth-of-type({1})'.format(x, y),waitfor=10)
list_data_w.append(data)
return list_data_w

#万家基金写数据
def write_data_w():
list_2 = get_data_all_w()
iters = [iter(list_2)]*8
w_data = list(zip(*iters))
print("w_data",w_data)
num = '2'
for v in w_data:
b_num = str("A"+ str(num))
v = list(v)
wb = xw.Book(r"E:\fund_data\wanjia.xlsx")
sht = wb.sheets[0]
sht.range(b_num).value = v
num = str(int(num)+1)
wb.save()
return "写入成功"



#获取中加基金数据1
def get_data_all_zj():
list_data_zj=[]
for x in range(2,29): #每行 多少行
for y in range(1, 10): #每列 td 这个列数和截取的列表要出去空格和空要大于截取的个数
data = iie.get_text(url=r'http://www.bobbns.com/',selector=r'#tableSort_0 > TBODY:nth-of-type(1) >TR:nth-of-type({0}) > TD:nth-of-type({1})'.format(x, y),waitfor=10)
if str(data).__contains__("\r\n"):
data = str(data).replace("\r\n",'')
list_data_zj.append(data)
else:
list_data_zj.append(data)
return list_data_zj

#写入欠十行数据
def write_data_zj():
list_3 = get_data_all_zj()
iters = [iter(list_3)]*9
zj_data = list(zip(*iters))
print("zj_data",zj_data)
num = '2'
for v in zj_data:
b_num = str("A"+ str(num))
v = list(v)
wb = xw.Book(r"E:\fund_data\zhongjia.xlsx")
sht = wb.sheets[0]
sht.range(b_num).value = v
num = str(int(num)+1)
wb.save()
return "写入成功"


#获取中加基金数据2
def get_data_all_zj1():
list_data_zj=[]
for x in range(15,29): #每行 多少行
for y in range(1, 10): #每列 td 这个列数和截取的列表要出去空格和空要大于截取的个数
data = iie.get_text(url=r'http://www.bobbns.com/',selector=r'#tableSort_0 > TBODY:nth-of-type(1) >TR:nth-of-type({0}) > TD:nth-of-type({1})'.format(x, y),waitfor=10)
if str(data).__contains__("\r\n"):
data = str(data).replace("\r\n",'')
list_data_zj.append(data)
else:
list_data_zj.append(data)
return list_data_zj

#写入后边十行数据
def write_data_zj1():
list_4 = get_data_all_zj1()
iters = [iter(list_4)]*9
zj_data = list(zip(*iters))
print("zj_data",zj_data)
num = '15'
for v in zj_data:
b_num = str("A"+ str(num))
v = list(v)
wb = xw.Book(r"E:\fund_data\zhongjia.xlsx")
sht = wb.sheets[0]
sht.range(b_num).value = v
num = str(int(num)+1)
wb.save()
return "写入成功"


猜你喜欢

转载自www.cnblogs.com/xiaoluoboer/p/9669501.html
18