No Error; No Output...Nothing

ryguy7272 ryanshuell at gmail.com
Tue Oct 21 23:44:13 CEST 2014


Hey everyone, I'm trying to run this code.

import os
import pickle
#import urllib2
from urllib.request import urlopen
#import cookielib
import http.cookiejar
import re
import time
import numpy as np
#import pylab as pl
 
# symbol - USDEUR=X - problem that the server sometimes returns 0.0
def getSpotPrice(symbol):
    numberOfAttempts = 0
    while numberOfAttempts < 10:
        url = 'http://download.finance.yahoo.com/d/quotes.csv?s='+symbol+'&f=l1&e=.cs'
        fxrate_pure = urllib2.urlopen(url).read()
        fxrate = fxrate_pure.strip()
        if fxrate != "0.00":
            return fxrate
        else:
            numberOfAttempts += 1
            time.sleep(1)
    raise Exception("Unable to obtain market data from Yahoo! ... wrong ticker???")
 
# symbol = the yahoo ticker; the expected tickers of the components contain alphanumerical characters or dot or hyphen; if the yahoo format changes, nothing is returned
def getConstituentsOfAnIndexFromYahoo(symbol):
    url = 'http://finance.yahoo.com/q/cp?s=%s' % symbol
    p = re.compile('<td class=\"yfnc_tabledata1\"><b><a href=\"/q\?s=([A-Z0-9\.\-]*)\">')
    components = []
    pageIndex = 0
    finished = False
    while not finished:
        if pageIndex == 0:
            actualUrl = url
        else:
            actualUrl = url + "&c=" + str(pageIndex)
        pageResults = p.findall(urllib2.urlopen(actualUrl).read())
        if len(pageResults) == 0:
            finished = True
        else:
            components.extend(pageResults)
            pageIndex+=1
    return components
 
# prices = data[:,6] or prices = data[:, title.index("Adj Close")], pl.num2date(data[:,1]) back dates
# syntax http://ichart.yahoo.com/table.csv?s={Yahoo.Symbol.[isin]}&a={Von.M-1}&b={Von.T}&c={Von.J}&d={Bis.M}&e={Bis.T}&f={Bis. J}&g=d&y=0&z=jdsu&ignore=.csv
def getNumpyHistoricalTimeseries(symbol,fromDate, toDate):
    f = urllib2.urlopen('http://ichart.yahoo.com/table.csv?a='+ str(fromDate.month -1) +'&c='+ str(fromDate.year) +'&b=' + str(fromDate.day) + '&e='+  str(toDate.day) + '&d='+ str(toDate.month-1) +'&g=d&f=' + str(toDate.year) + '&s=' + symbol + '&ignore=.csv')
    header = f.readline().strip().split(",")
    #return np.loadtxt(f, dtype=np.float, delimiter=",", converters={0: pl.datestr2num})

I commented out the import pylab as pl because I couldn't get the matplotlib.pylab import working.  So, anyway, I hit F5, and it seems to run, but it doesn't really do anything.  Isn't this either supposed to be downloading data from the web, or throwing an error so I can troubleshoot, and try to figure out what's going on?  It's hard to troubleshoot, when you don't get any error.  Does this work for others?

Thanks.



More information about the Python-list mailing list