def gen_txt_file(prefilename, savedir, labellist, rowlist): filename = prefilename + ".txt" labelstr = u"序号" + "," + ",".join(labellist) f = open("/tmp/%s" % filename, 'wb') f.write(labelstr) f.write("\n") for rownum, rowvalue in enumerate(rowlist): rowdata = "%s" % (rownum + 1) + "," + ",".join(rowvalue) f.write(rowdata) f.write("\n") f.close() Config = HandleConfig() logger = getLog("Upload txt file to hdfs") HdfsObj = WebHadoop(Config.HdfsHost, Config.HdfsPort, Config.HdfsUser, logger, Config.HdfsPrefix) HdfsObj.put_file("/tmp/%s" % (filename), savedir + filename, overwrite="true") #Delete Tmp File os.remove("/tmp/%s" % (filename))
def delAll(Config, uidObj, redisconn, filelist, logger): #删除hadoop中的vid文件 HdfsObj = WebHadoop(Config.HdfsHost, Config.HdfsPort, Config.HdfsUser, logger, Config.HdfsPrefix) uid = uidObj.Uid for i in filelist: uidObj.del_vid(i) i = i.encode('utf-8') path_inhdfs = "/static/%s/%s" % (uid, i) HdfsObj.remove(path_inhdfs) #HdfsObj.remove(file_sorcefile) playlist_list = uidObj.get_playinfo(uid) playlist_newlist = [] for i in playlist_list: vid_inplaydir = json.loads(redisconn.get('%s_info' % i)) vid_inplaylist = [j for j in vid_inplaydir.itervalues()] print vid_inplaylist for k in filelist: if vid_inplaylist and k in vid_inplaylist: playlist_newlist.append(i) updateXmlandRefresh(Config, uidObj, redisconn, HdfsObj, playlist_newlist)
def delAll(Config,uidObj,redisconn,filelist,logger): #删除hadoop中的vid文件 HdfsObj = WebHadoop(Config.HdfsHost,Config.HdfsPort,Config.HdfsUser,logger,Config.HdfsPrefix) uid = uidObj.Uid for i in filelist: uidObj.del_vid(i) i = i.encode('utf-8') path_inhdfs = "/static/%s/%s"%(uid,i) HdfsObj.remove(path_inhdfs) #HdfsObj.remove(file_sorcefile) playlist_list = uidObj.get_playinfo(uid) playlist_newlist = [] for i in playlist_list: vid_inplaydir = json.loads(redisconn.get('%s_info'%i)) vid_inplaylist = [ j for j in vid_inplaydir.itervalues()] print vid_inplaylist for k in filelist: if vid_inplaylist and k in vid_inplaylist: playlist_newlist.append(i) updateXmlandRefresh(Config,uidObj,redisconn,HdfsObj,playlist_newlist)
def gen_excel_file(prefilename, savedir, labellist, rowlist): filename = prefilename + ".xls" wbk = xlwt.Workbook() sheet = wbk.add_sheet(filename) #Font Define font = xlwt.Font() font.name = "Times New Roman" font.bold = True font.colour_index = 2 #Alignment Define alignment = xlwt.Alignment() alignment.horz = xlwt.Alignment.HORZ_LEFT alignment.vert = xlwt.Alignment.VERT_BOTTOM #Borders Define borders = xlwt.Borders() borders.left = xlwt.Borders.THIN borders.right = xlwt.Borders.THIN borders.top = xlwt.Borders.THIN borders.bottom = xlwt.Borders.THIN borders.left_colour = 0x40 borders.right_colour = 0x40 borders.top_colour = 0x40 borders.bottom_colour = 0x40 style = xlwt.XFStyle() style.font = font style.borders = borders style.alignment = alignment #Write Label for colnum, colvalue in enumerate(labellist): sheet.write(0, colnum, colvalue, style) sheet.col(colnum).width = 6000 #Write Data row = 1 for rowdata in rowlist: for colnum, colvalue in enumerate(rowdata): sheet.write(row, colnum, colvalue, style) row += 1 #Save Excel File wbk.save("/tmp/%s" % filename) Config = HandleConfig() logger = getLog("Upload excel file to hdfs") HdfsObj = WebHadoop(Config.HdfsHost, Config.HdfsPort, Config.HdfsUser, logger, Config.HdfsPrefix) HdfsObj.put_file("/tmp/%s" % (filename), savedir + filename, overwrite="true") #Delete Tmp File os.remove("/tmp/%s" % (filename))
def gen_excel_file(prefilename,savedir,labellist,rowlist): filename = prefilename + ".xls" wbk = xlwt.Workbook() sheet = wbk.add_sheet(filename) #Font Define font = xlwt.Font() font.name = "Times New Roman" font.bold = True font.colour_index = 2 #Alignment Define alignment = xlwt.Alignment() alignment.horz = xlwt.Alignment.HORZ_LEFT alignment.vert = xlwt.Alignment.VERT_BOTTOM #Borders Define borders = xlwt.Borders() borders.left = xlwt.Borders.THIN borders.right = xlwt.Borders.THIN borders.top = xlwt.Borders.THIN borders.bottom = xlwt.Borders.THIN borders.left_colour = 0x40 borders.right_colour = 0x40 borders.top_colour = 0x40 borders.bottom_colour = 0x40 style = xlwt.XFStyle() style.font = font style.borders = borders style.alignment = alignment #Write Label for colnum,colvalue in enumerate(labellist): sheet.write(0,colnum,colvalue,style) sheet.col(colnum).width = 6000 #Write Data row = 1 for rowdata in rowlist: for colnum,colvalue in enumerate(rowdata): sheet.write(row,colnum,colvalue,style) row += 1 #Save Excel File wbk.save("/tmp/%s"%filename) Config = HandleConfig() logger = getLog("Upload excel file to hdfs") HdfsObj = WebHadoop(Config.HdfsHost,Config.HdfsPort,Config.HdfsUser,logger,Config.HdfsPrefix) HdfsObj.put_file("/tmp/%s"%(filename), savedir+filename,overwrite="true") #Delete Tmp File os.remove("/tmp/%s"%(filename))
def gen_txt_file(prefilename,savedir,labellist,rowlist): filename = prefilename + ".txt" labelstr = u"序号" + "," + ",".join(labellist) f = open("/tmp/%s"%filename,'wb') f.write(labelstr) f.write("\n") for rownum,rowvalue in enumerate(rowlist): rowdata = "%s"%(rownum+1)+","+",".join(rowvalue) f.write(rowdata) f.write("\n") f.close() Config = HandleConfig() logger = getLog("Upload txt file to hdfs") HdfsObj = WebHadoop(Config.HdfsHost,Config.HdfsPort,Config.HdfsUser,logger,Config.HdfsPrefix) HdfsObj.put_file("/tmp/%s"%(filename), savedir+filename,overwrite="true") #Delete Tmp File os.remove("/tmp/%s"%(filename))
def run(self): while True: uid = self.queue.get() userObj = UidInfo(self.mysql_conn,self.mongoconn,uid) playlist_info = userObj.get_uid_playlist(uid) CreatXml(uid,playlist_info,"adaptive","PC") CreatXml(uid,playlist_info,"video","IOS") CreatXml(uid,playlist_info,"video","Android") "写入默认播放列表" defaultplaylist = {} for i in xrange(0,len(playlist_info)): vid_inlist = playlist_info[i][1] defaultplaylist[str(i+1)] = vid_inlist self.redata.set("%sA0_info"%(uid),ujson.encode(defaultplaylist)) filename1 = uid + "A0.xml" filename2 = uid + "A05.xml" filename3 = uid + "A0A.xml" Base_Hdfs_Path = "/static/" + uid + "/" HdfsObj = WebHadoop(self.Config.HdfsHost,self.Config.HdfsPort,self.Config.HdfsUser,self.logger,self.Config.HdfsPrefix) HdfsObj.put_file("/tmp/%s"%(filename1), Base_Hdfs_Path+filename1,overwrite="true") HdfsObj.put_file("/tmp/%s"%(filename2), Base_Hdfs_Path+filename2,overwrite="true") HdfsObj.put_file("/tmp/%s"%(filename3), Base_Hdfs_Path+filename3,overwrite="true") refresh_url1 = "/%s/%sA0.xml" % (uid,uid) refresh_url2 = "/%s/%sA05.xml" % (uid,uid) refresh_url3 = "/%s/%sA0A.xml" % (uid,uid) self.redata.rpush("cacheurl_list",refresh_url1) self.redata.rpush("cacheurl_list",refresh_url2) self.redata.rpush("cacheurl_list",refresh_url3) self.queue.task_done()
def run(self): while True: uid = self.queue.get() userObj = UidInfo(self.mysql_conn, self.mongoconn, uid) playlist_info = userObj.get_uid_playlist(uid) CreatXml(uid, playlist_info, "adaptive", "PC") CreatXml(uid, playlist_info, "video", "IOS") CreatXml(uid, playlist_info, "video", "Android") "写入默认播放列表" defaultplaylist = {} for i in xrange(0, len(playlist_info)): vid_inlist = playlist_info[i][1] defaultplaylist[str(i + 1)] = vid_inlist self.redata.set("%sA0_info" % (uid), ujson.encode(defaultplaylist)) filename1 = uid + "A0.xml" filename2 = uid + "A05.xml" filename3 = uid + "A0A.xml" Base_Hdfs_Path = "/static/" + uid + "/" HdfsObj = WebHadoop(self.Config.HdfsHost, self.Config.HdfsPort, self.Config.HdfsUser, self.logger, self.Config.HdfsPrefix) HdfsObj.put_file("/tmp/%s" % (filename1), Base_Hdfs_Path + filename1, overwrite="true") HdfsObj.put_file("/tmp/%s" % (filename2), Base_Hdfs_Path + filename2, overwrite="true") HdfsObj.put_file("/tmp/%s" % (filename3), Base_Hdfs_Path + filename3, overwrite="true") refresh_url1 = "/%s/%sA0.xml" % (uid, uid) refresh_url2 = "/%s/%sA05.xml" % (uid, uid) refresh_url3 = "/%s/%sA0A.xml" % (uid, uid) self.redata.rpush("cacheurl_list", refresh_url1) self.redata.rpush("cacheurl_list", refresh_url2) self.redata.rpush("cacheurl_list", refresh_url3) self.queue.task_done()