国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python下載文件記錄黑名單的實現代碼

2020-02-16 10:27:49
字體:
來源:轉載
供稿:網友

具體代碼如下所示:

#!/usr/bin/python# -*- coding: GBK -*-# -*- coding: UTF-8 -*-from ftplib import FTPimport osimport datetimeftp_server = '127.0.0.1' # 對應ftp服務器地址username = 'ponshine' # 用戶名password = '1qaz2wsx' # 密碼ftp_path = '/GBCC/' # ftp目錄local_path = "C:/F/python/pythonwangtest/wyjj2//" #本地的目錄# 連接FTPdef ftpconnect():  ftp = FTP()  ftp.set_debuglevel(2) # 打開調試級別2,顯示詳細信息  ftp.connect(ftp_server, 21) # 連接  ftp.login(username, password) # 登錄,如果匿名登錄則用空串代替即可  return ftp# 獲取當前的年月日時分秒def getdatetime():  i = datetime.datetime.now()  date = ("%s%s%s%s%s%s" % (i.year, i.month, i.day, i.hour,i.minute,i.second))  return date # 需返回才能取值# 獲取當前的年月日def getdate():  import datetime  i = datetime.datetime.now()  date = ("%s%s%s" % (i.year, i.month, i.day))  return date # 需返回才能取值def downloadfile(remotepath, localpath):  ftp = ftpconnect() # 連接ftp  print ftp.getwelcome() # 顯示ftp服務器歡迎信息  ftp_filename = ftp.nlst(remotepath) # 運用nlst()獲取文件名  print 'ftp_filename: ', ftp_filename # ftp上的文件名  for eachfile in ftp_filename: # 循壞取文件名    if eachfile.endswith('.AVL'):      localpath_files = eachfile.split("/")      localpath_file = localpath_files[len(localpath_files) - 1] # 文件名:localpath_file= GBCC_201611102155_01.AVL      print "localpath_file--->" + localpath_file      # 創建記錄下載文件名的文件名      writefiletext = local_path + getdate() + ".txt" # 記錄下載后的文件名      print "writefile_text--->" + writefiletext             if os.path.exists(writefiletext):        print writefiletext + "is exists"      else:        print writefiletext + "is not exists"        makefile = open(writefiletext,"w+")        makefile.close()      files = open(writefiletext, "r") # 打開黑名單表      print "writefiletext--->" + writefiletext      try:        all_the_text = files.read()        print "all_the_text-------》" + all_the_text        if all_the_text.__contains__(localpath_file):          print "文件已下載,不需要重復下載"        else:          print "文件沒有下載,現在開始下載"          bufsize = 1024 # 設置緩沖塊大小          fp = open(localpath + localpath_file, "wb+")          ftp.retrbinary('RETR ' + eachfile, fp.write, bufsize) # 下載文件          fo = open(writefiletext,"ab+")          fo.write(localpath_file + "/n") # 將每個文件名寫入文件          fo.flush() # 刷新文件          fo.close()          fp.flush()      finally:        print "結束了"        files.close()  ftp.set_debuglevel(0)  ftp.close()if __name__ == "__main__":  downloadfile("/GBCC", "C:/F/python/pythonwangtest/wyjj2//")

  補充:python 黑名單過濾

  需要過濾一些詞語

寫了下面這個函數,在blacklist 文件中添加需要過濾的詞語

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麦盖提县| 囊谦县| 台中市| 安国市| 台湾省| 长岭县| 克山县| 大英县| 东乡| 凤阳县| 绥棱县| 奉节县| 延川县| 如皋市| 南平市| 金寨县| 龙南县| 句容市| 姜堰市| 普安县| 茂名市| 黎川县| 大安市| 达孜县| 凤城市| 柳江县| 泸溪县| 大方县| 海原县| 塔城市| 萝北县| 游戏| 高台县| 清水县| 汝阳县| 承德县| 华容县| 贵定县| 民勤县| 子洲县| 广西|