No Error; No Output...Nothing

ryguy7272 ryanshuell at
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 = ''+symbol+'&f=l1&e=.cs'
        fxrate_pure = urllib2.urlopen(url).read()
        fxrate = fxrate_pure.strip()
        if fxrate != "0.00":
            return fxrate
            numberOfAttempts += 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 = '' % 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
            actualUrl = url + "&c=" + str(pageIndex)
        pageResults = p.findall(urllib2.urlopen(actualUrl).read())
        if len(pageResults) == 0:
            finished = True
    return components
# prices = data[:,6] or prices = data[:, title.index("Adj Close")], pl.num2date(data[:,1]) back dates
# syntax{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(''+ str(fromDate.month -1) +'&c='+ str(fromDate.year) +'&b=' + str( + '&e='+  str( + '&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?


More information about the Python-list mailing list