Exemplo n.º 1
0
 def get(self, ticker):
   stock_price = stockquote.get_quote(ticker.upper())
   stock = Stock.get_by_key_name(ticker)
   if stock:
     quote = StockQuote(stock = stock,
                        value = float(stock_price),
                        time  = datetime.now())
     quote.put()
     self.response.out.write("Successful")
   else:
     stockobj = Stock(ticker = ticker,
                      key_name = ticker,
                      keywords = ["yahoo","yhoo","carol bartz"])
     stockobj.put()
     self.response.out.write("Created")
Exemplo n.º 2
0
  def get(self):
    # api = twitter.Api()
    # moved api call to PopulateDatabase method
    # here we can also have (some) control on rate limits?
    # statuses = api.Search('good')
    query = "yahoo"
    stock_query = Stock.all().filter('keywords =', query).fetch(1)[0]
    
    now_quote = stockquote.get_quote(stock_query.ticker.upper())
    
    tweet_query = Tweet.all().filter('keywords = ', query).order('-created_at')
    statuses = tweet_query.fetch(20)
    count = 20 # otherwise it 'almost' re-searches
    template_values = {
      'stock' : now_quote,
      'ticker' : stock_query.ticker,
      'query' : query,
      'statuses': statuses,
      'count' : count,
      }

    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, template_values))
import urllib
import re

def get_quote(symbol):
    base_url = 'http://finance.google.com/finance?q='
    content = urllib.urlopen(base_url + symbol).read()
    m = re.search('id="ref_694653_l".*?>(.*?)<', content)
    if m:
        quote = m.group(1)
    else:
        quote = 'no quote available for: ' + symbol
    return quote

import stockquote
print stockquote.get_quote('goog')import scraperwiki

# Blank Python

import urllib
import re

def get_quote(symbol):
    base_url = 'http://finance.google.com/finance?q='
    content = urllib.urlopen(base_url + symbol).read()
    m = re.search('id="ref_694653_l".*?>(.*?)<', content)
    if m:
        quote = m.group(1)
    else:
        quote = 'no quote available for: ' + symbol
    return quote
Exemplo n.º 4
0
    columns = [[] for i in xrange(numcols)]
    count = 0
    rest = []
    for col in xrange(panel.width):
        try:
            columns[int((col-count)/percol)].append(col)
        except:
            rest.append(col)
        count = (count + 1) % percol
    # main loop
    for col in xrange(numcols):
        drawCol(panel, columns[col], heights[col], fg=(fore[0]*col, fore[1], fore[2]))
    for col in rest:
        drawCol(panel, [col], 0, edge=(0, 0, 0))
    while True:
        panel.outputAndWait(30)

def getheights(numcols):
    #return [random.randint(0, panel.height-1) for i in xrange(numcols)]
    return heights

if __name__ == "__main__":
    panel = dmx.getDefaultPanel()
    fore = (0.4, 1, 0)
    companies = ["goog", "aapl", "msft", "ibm", "sun"]
    numcols = len(companies)
    heights = []
    for col in xrange(len(companies)):
        heights.append(float(stockquote.get_quote(companies[col]))/25)
    run(panel, numcols)
Exemplo n.º 5
0
def getheights():
    heights.insert(0, (float(stockquote.get_quote("goog"))/25))
    if len(heights) > panel.width:
        heights.pop()
    return heights