日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python下载后是黑的_python下载文件记录黑名单的实现代码

發布時間:2023/12/19 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python下载后是黑的_python下载文件记录黑名单的实现代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

具體代碼如下所示:

#!/usr/bin/python

# -*- coding: GBK -*-

# -*- coding: UTF-8 -*-

from ftplib import FTP

import os

import datetime

ftp_server = '127.0.0.1' # 對應ftp服務器地址

username = 'ponshine' # 用戶名

password = '1qaz2wsx' # 密碼

ftp_path = '/GBCC/' # ftp目錄

local_path = "C:Fpythonpythonwangtestwyjj2" #本地的目錄

# 連接FTP

def 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:Fpythonpythonwangtestwyjj2")

補充:python 黑名單過濾

需要過濾一些詞語

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

總結

以上是生活随笔為你收集整理的python下载后是黑的_python下载文件记录黑名单的实现代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。