<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -32,6 +32,7 @@ import string
 import urlparse
 import time
 import datetime
+import csv
 
 def latest_news():
     &quot;&quot;&quot;
@@ -223,6 +224,46 @@ def cmte_filings(cmte):
     make_rss_20(intro, 'Committee finance reports.', data, 'latest_cmte_filings.xml')
 
 
+def latest_electioneering_filings():
+    &quot;&quot;&quot;
+    Returns a list of the most recent electioneering communications filings
+    with the FEC by processing a CSV file on ftp.fec.gov and printing the 10
+    most recent filings out as RSS 2.0.
+    
+    Uses a slightly altered version of the MONTHS_3 format used by Django to parse dates from FEC file.    
+    &quot;&quot;&quot;
+    try:
+        url = &quot;ftp://ftp.fec.gov/FEC/electioneering.csv&quot;
+        ec = urllib.urlopen(url)
+        reader = csv.DictReader(ec)
+        reader.next()
+    except IOError:
+        print &quot;Network Error: File cannot be accessed.&quot;
+        raise SystemExit
+    
+    # dictionary mapping three-letter months to Python month numbers for use in building Python dates
+    MONTHS_3 = { 'JAN': 1, 'FEB': 2, 'MAR': 3, 'APR': 4, 'MAY': 5, 'JUN': 6, 'JUL': 7, 'AUG':8, 'SEP':9, 'OCT':10, 'NOV':11, 'DEC':12}
+    
+    base_url = 'http://images.nictusa.com/cgi-bin/fecimg/?_'
+    data = []
+    for row in reader:
+        d = row[' RECEIPT_DT'].strip().split('-')
+        d[1] = str(MONTHS_3[d[1]])
+        date_date = time.strptime(&quot;-&quot;.join(d), '%d-%m-%y')
+        if row[' PUBLIC_DISTRIBUTION_DT '] == '':
+            dd = d
+        else:
+            dd = row[' PUBLIC_DISTRIBUTION_DT '].strip().split('-')
+            dd[1] = str(MONTHS_3[dd[1]])
+        dist_date = time.strftime(&quot;%b %d, %Y&quot;, time.strptime(&quot;-&quot;.join(dd), '%d-%m-%y')) # the date the ad(s) aired.
+        pubDate = time.strftime('%a, %d %b %Y 00:00:00 GMT', date_date) # the filing date
+        record = (row[' FILER_NAME '], base_url+row[' BEGIN_IMAGE_NUM ']+'+0', &quot;Amount Spent: $&quot;+ row[' TOTAL_DISBURSEMENTS_THIS_STMT '] + &quot; first airing on &quot;+ dist_date, pubDate)
+        data.append(record)
+    data = data[:10] # limits feed to 10 most recent.
+    intro = &quot;Latest Electioneering Communications filings&quot;
+    make_rss_20(intro, 'Electioneering communications', data, 'elect_comm.xml')
+
+
 def cand_summary_by_state(year, state):
     &quot;&quot;&quot;
     Partially working function to return summary</diff>
      <filename>fec.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8cbb117f8006464981adad81345b8dbc926853b8</id>
    </parent>
  </parents>
  <author>
    <name>Derek Willis</name>
    <email>dwillis@Derek-Willis-Laptop.home</email>
  </author>
  <url>http://github.com/dwillis/fec-utilities/commit/cf4bd065f4ba678b8312df48b8785dac11495d0c</url>
  <id>cf4bd065f4ba678b8312df48b8785dac11495d0c</id>
  <committed-date>2008-06-22T19:33:24-07:00</committed-date>
  <authored-date>2008-06-22T19:33:24-07:00</authored-date>
  <message>added latest electioneering communications feed generator</message>
  <tree>01e22bf97d1848d32846ffbe0a06f02dcb33746e</tree>
  <committer>
    <name>Derek Willis</name>
    <email>dwillis@Derek-Willis-Laptop.home</email>
  </committer>
</commit>
