#!/usr/bin/env python
import datetime
import sqlite3
import sys

import pandas.io.data as web
import pandas.io.sql as sql


def get_stock(stock, start, end):
    """
    Return data frame of Yahoo! Finance data for stock.

    Takes stock name and start and end dates as datetimes.
    """
    return web.DataReader(stock, 'yahoo', start, end)


def scrape_stock(stock, start, end):
    """
    Write SQLite table of stock data from Yahoo! Finance
    
    Take a stock name and start and end dates as datetimes.
    """
    sqlite_db.execute("drop table if exists {};".format(stock))
    frame = (get_stock(stock, start, end))
    # make Date not an index so it appears in table
    frame = frame.reset_index()
    # force Date datetime to string
    frame[['Date']] = frame[['Date']].applymap(lambda x: x.isoformat())
    sql.write_frame(frame, stock, sqlite_db)


def parse_wanted_stocks(stocks_string):
    """
    Take comma-separated string of stocks; return list of strings.
    >>> parse_wanted_stocks('TWTR,FB')
    ['TWTR', 'FB']
    >>> parse_wanted_stocks('TWTR')
    ['TWTR']
    """
    return stocks_string.split(',')


def main():
    """
    Save stock ticker data from Yahoo! Finance to sqlite.
    """
    global sqlite_db
    sqlite_db = sqlite3.connect("scraperwiki.sqlite")
    # arbitrary start
    start = datetime.datetime(2014, 3, 1)
    end = datetime.datetime.today()
    for ticker in parse_wanted_stocks(sys.argv[1]):
        scrape_stock(ticker, start, end)

if __name__ == '__main__':
    main()

@@ -15,16 +15,249 @@
  python%0A
+%22%22%22 pandas_finance.%0A%0AUsage:%0A    pandas_finance.py STOCKS START_DATE END_DATE%0A%0AArguments:%0A    STOCKS     comma separated stock ticker symbols, e.g. FB,TWTR%0A    START_DATE start date, yyyy/mm/dd%0A    END_DATE   end date, yyyy/mm/dd%0A%22%22%22%0A
 import d
@@ -283,19 +283,22 @@
 te3%0A
+%0A
 import 
-sys%0A
+docopt
 %0Aimp
@@ -1360,24 +1360,126 @@
 plit(',')%0A%0A%0A
+def get_arguments():%0A    %22%22%22 Get arguments from command line. %22%22%22%0A    return docopt.docopt(__doc__)%0A%0A%0A
 def main():%0A
@@ -1474,24 +1474,24 @@
 def main():%0A
-
     %22%22%22%0A    
@@ -1548,24 +1548,56 @@
 te.%0A    %22%22%22%0A
+    arguments = get_arguments()%0A
     global s
@@ -1801,18 +1801,26 @@
 cks(
-sys.argv%5B1
+arguments%5B'STOCKS'
 %5D):%0A

Use docopt instead of sys.argv.