Index: client/rfp.py
===================================================================
--- client/rfp.py	(revision 42132d73a168bd3850f88bd33190fc61063bf259)
+++ client/rfp.py	(revision 42132d73a168bd3850f88bd33190fc61063bf259)
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+import csv
+import datetime
+import os.path
+
+from mechanize import Browser
+
+import downloader
+import sapweb
+
+class RfpDownloader(object):
+    def __init__(self, br=None):
+        if not br:
+            br = Browser()
+        self.br = br
+        self._make_dirs()
+        self.csrftoken = None
+
+    def _make_dirs(self, ):
+        label = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
+        basepath = os.path.dirname(downloader.pathtpl)
+        self.dirname = os.path.join(basepath, label+"-rfps")
+        self.docs_dir = os.path.join(self.dirname, 'docs')
+        os.makedirs(self.docs_dir) # makes all parents, so dirname too
+
+    def getRfpsCsv(self, ):
+        self.br.open(downloader.baseurl + 'vouchers/generate/rfps.csv')
+        if self.br.viewing_html():
+            print self.br.response().get_data()
+            assert not self.br.viewing_html()
+        downloaded_rfps_name = os.path.join(self.dirname, "inbound.csv")
+        data = self.br.response().get_data()
+        with open(downloaded_rfps_name, 'w') as fd:
+            fd.write(data)
+        return downloaded_rfps_name
+
+    def _manage_csrf(self, ):
+        if self.csrftoken: return
+        cookiejar = self.br._ua_handlers["_cookies"].cookiejar
+        for cookie in cookiejar:
+            if cookie.name == 'csrftoken':
+                assert self.csrftoken == None
+                self.csrftoken = cookie.value
+        self.br.addheaders.append(('X-CSRFToken', self.csrftoken))
+
+    def putRfpsCsv(self, results):
+        upload_name = os.path.join(self.dirname, "outbound.csv")
+        with open(upload_name, 'w') as fd:
+            writer = csv.DictWriter(fd, ['id', 'rfp_number'], extrasaction='ignore')
+            writer.writeheader()
+            for result in results:
+                writer.writerow(result)
+        with open(upload_name, 'r') as fd:
+            data = fd.read()
+            self._manage_csrf()
+            self.br.open(downloader.baseurl + 'vouchers/generate/rfps.csv', data)
+            print self.br.response().get_data()
+            assert not self.br.viewing_html()
+
+    def process(self):
+        downloader.login2Admin(self.br)
+        rfp_name = self.getRfpsCsv()
+        with open(rfp_name, 'r') as rfps:
+            created = sapweb.create_rfps(rfps, self.docs_dir)
+        self.putRfpsCsv(created)
+
+if __name__ == '__main__':
+    d = RfpDownloader()
+    d.process()
Index: client/sapweb.py
===================================================================
--- client/sapweb.py	(revision 952d9fb4c6511ffe9b30ea660e9dda2e36098726)
+++ client/sapweb.py	(revision 42132d73a168bd3850f88bd33190fc61063bf259)
@@ -2,5 +2,8 @@
 
 import csv
+import os
 import sys
+import urllib2
+import urlparse
 
 import selenium.common.exceptions
@@ -8,4 +11,7 @@
 import pysapweb.rfp
 import pysapweb.sap_profiles
+
+use_browser = False
+use_browser = True
 
 def get_profile():
@@ -35,19 +41,38 @@
     return id, name, address, line_item, payee
 
-def create_rfps(fd):
+def download_doc(url, docs_dir):
+    parsed_url = urlparse.urlparse(url)
+    basename = os.path.basename(parsed_url.path)
+    doc_fn = os.path.join(docs_dir, basename)
+    doc_data = urllib2.urlopen(url).read()
+    with open(doc_fn, 'w') as doc_fd:
+        doc_fd.write(doc_data)
+    return doc_fn
+
+def create_rfps(fd, docs_dir):
     reader = csv.DictReader(fd)
-    browser = get_profile()
+    if use_browser:
+        browser = get_profile()
+    created = []
     for line in reader:
         id, name, address, line_item, payee = read_rfp_info(line)
+        doc_url = line['documentation']
+        doc_path = download_doc(doc_url, docs_dir)
         args = dict(
             name=name,
             payee=payee,
             line_items=(line_item, ),
+            receipts=(doc_path, ),
         )
         if not payee[0]:
             args['address'] = address
-        print "args=%s" % (args, )
-        rfp = pysapweb.rfp.create(browser, **args)
+        if use_browser:
+            rfp = pysapweb.rfp.create(browser, **args)
+        else:
+            rfp = 123456
         print "Created voucher %d -> RFP %s" % (id, rfp)
+        line['rfp_number'] = rfp
+        created.append(line)
+    return created
 
 def create_test_rfp():
