from ftplib import FTP import zipfile import csv filename = 'XXX.ZIP' ftp = FTP('ftp.XXXX.com') ftp.login() ftp.cwd("/XXX") gFile = open(filename, "wb") ftp.retrbinary('RETR XXX.zip', gFile.write) gFile.close() ftp.quit() # Unzip file with zipfile.ZipFile(filename,"r") as zip_ref: zip_ref.extractall() # read csv filewith open("XXX.csv") as f: reader = csv.DictReader(f) next(reader) data = [] for r in reader: data.append(r) for i in range(0,len(data)): data[i]['api'] = data[i].pop('API_Number') data[i]['well_name'] = data[i].pop('Well_Name') data[i]['well_number'] = data[i].pop('Well_Number') data[i]['operator_code'] = data[i].pop('Operator') data[i]['operator'] = data[i].pop('Operator_Name') data[i]['well_status'] = data[i].pop('Well_Status') data[i]['well_type'] = data[i].pop('Well_Type') data[i]['county_code'] = data[i].pop('County') data[i]['location_datum'] = data[i].pop('Loc_Type') data[i]['township'] = data[i].pop('Twp') data[i]['range'] = data[i].pop('Range') data[i]['section'] = data[i].pop('Sec') data[i]['principle_meridian'] = data[i].pop('PM') data[i]['latitude'] = data[i].pop('Lat_Y') data[i]['longitude'] = data[i].pop('Long_X') data[i]['measured_depth'] = data[i].pop('Measured_TotalDepth') data[i]['vertical_depth'] = data[i].pop('TrueVertical_Depth') data[i]['spud_date'] = data[i].pop('Spud')
Friday, June 8, 2018
Python -Start scraping - 5. connect to ftp website
Labels:
Python
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment