Skip to content
Browse files

Update projects/fdic/save_to_csv.py

Minor code tweaks; added header row to output
  • Loading branch information...
1 parent c24cc9b commit 60eecf6072cad82e88af6308a14d9ea9485e2b3d @cschnaars cschnaars committed
Showing with 23 additions and 7 deletions.
  1. +23 −7 projects/fdic/save_to_csv.py
View
30 projects/fdic/save_to_csv.py
@@ -11,8 +11,10 @@
outputheaders = ['bank', 'city', 'state', 'cert_num', 'acq_inst',
'closed', 'updated', 'url']
-# Import scraper function and necessary libraries
-from scraper import scrape_data
+# Import module created in Part I
+# from scraper import scrape_data
+
+# Import datetime modules
from datetime import datetime
import csv
@@ -30,7 +32,7 @@ def convertdatestring(datestring):
# Store the results of the scrape_data function
# Results are dictionaries that look like below
-"""
+
data = [
{
'bank': 'First Alliance',
@@ -41,11 +43,20 @@ def convertdatestring(datestring):
'closed': 'February 15, 2013',
'updated': 'February 20, 2013',
'url': 'http://www.fdic.gov/bank/individual/failed/firstalliance.html'
+ },
+ {
+ 'bank': 'First Alliance',
+ 'city': 'Manchester',
+ 'state': 'NH',
+ 'cert_num': '34264',
+ 'acq_inst': 'Southern New Hampshire Bank & Trust',
+ 'closed': 'February 15, 2013',
+ 'updated': 'February 20, 2013',
+ 'url': 'http://www.fdic.gov/bank/individual/failed/firstalliance.html'
}
]
-"""
-data = scrape_data()
+# data = scrape_data()
# Let's mess up one row to demo try/except:
# data[0]['closed'] = 'Jnauary 15, 2013'
@@ -74,8 +85,13 @@ def convertdatestring(datestring):
except:
row['updated'] = ''
-with open(savedir + 'fdic_output.csv', 'w') as outputfile:
- wtr = csv.DictWriter(outputfile, delimiter= '|', fieldnames=outputheaders)
+with open(savedir + 'fdic_output.txt', 'w') as outputfile:
+ wtr = csv.DictWriter(outputfile, delimiter= '|', fieldnames=outputheaders,
+ lineterminator = '\n')
+
+ # Add headers to output
+ wtr.writeheader()
for row in data:
wtr.writerow(row)
+

0 comments on commit 60eecf6

Please sign in to comment.
Something went wrong with that request. Please try again.