Esempio n. 1
0
  def build(self):
    try: 
      coinbase_url = 'https://' + self.sconfig['host'] + self.sconfig['path']
      print coinbase_url
      coinbase_api = urllib.urlopen(coinbase_url)
      response = coinbase_api.read()
      response_dictionary = json.loads(response)
      # reads bit coin value from coinbase
      btc_price=response_dictionary['subtotal']['amount']
      whole_price = int(floor(float(btc_price)))
      decimal_price = int(floor((float(btc_price) - whole_price)*100))
      btc_price = bsn.n2w(int(whole_price)) + ' dollars'
      if decimal_price > 0:
        btc_price += ' and ' + bsn.n2w(int(decimal_price)) + ' cents'

      btc = 'The value of 1 bitcoin is: ' + btc_price + '.  '
    except Exception:
      btc = 'Failed to connect to coinbase.  '

  #print response_dictionary['amount']
  #print response_dictionary['subtotal']['amount']

    if self.debug:
      print btc

    self.content = btc
Esempio n. 2
0
import better_spoken_numbers as bsn
from math import floor
import ConfigParser
Config = ConfigParser.ConfigParser()
try:
    Config.read('alarm.config')
except:
    raise Exception('Sorry, Failed reading alarm.config file.')

try:
    coinbase_api = urllib.urlopen('https://coinbase.com/api/v1/prices/buy')
    response = coinbase_api.read()
    response_dictionary = json.loads(response)
    # reads bit coin value from coinbase
    btc_price = response_dictionary['subtotal']['amount']
    whole_price = int(floor(float(btc_price)))
    decimal_price = int(floor((float(btc_price) - whole_price) * 100))
    btc_price = bsn.n2w(int(whole_price)) + ' dollars'
    if decimal_price > 0:
        btc_price += ' and ' + bsn.n2w(int(decimal_price)) + ' cents'

    btc = 'El valor de 1 bitcoin es: ' + btc_price + '.  '
except Exception:
    btc = 'Failed to connect to coinbase.  '

#print response_dictionary['amount']
#print response_dictionary['subtotal']['amount']

if Config.get('main', 'debug') == str(1):
    print btc
Esempio n. 3
0
        api = urllib2.urlopen(
            'http://finance.yahoo.com/webservice/v1/symbols/' + ticker +
            '/quote?format=json',
            timeout=4)
        response = api.read()
        response_dictionary = json.loads(response)
        stock_name = response_dictionary['list']['resources'][0][
            'resource']['fields']['name'].replace("Common Stock", '').replace(
                ' Inc', '').replace(',', '').replace('.',
                                                     '').replace('(NS) O', '')

        # get the price
        stock_price = response_dictionary['list']['resources'][0]['resource'][
            'fields']['price']
        # trim it to something sane
        stock_price = round(decimal.Decimal(stock_price), 2)

        whole_price = floor(stock_price)
        decimal_price = floor((stock_price - whole_price) * 100)
        stock_price = bsn.n2w(int(whole_price)) + ' dólares'
        if decimal_price > 0:
            stock_price += ' y ' + bsn.n2w(int(decimal_price)) + ' céntimos'

        stocks += stock_name + ' se está intercambiando a ' + stock_price + '.  '

    except Exception:
        stocks = 'Fallo al conectar con Yahoo Finance.  '

if Config.get('main', 'debug') == str(1):
    print stocks
Esempio n. 4
0
  def build(self):
    tickers=self.sconfig['tickers'].split(',')

    stocks='Stock update: '
    stocks_display='markets: '

    for ticker in tickers:
      try: 
        apiurl = 'https://' + \
                 self.sconfig['host'] + \
                 self.sconfig['path'] + \
                 ticker + \
                 self.sconfig['pathtail']
        #api = urllib2.urlopen('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%27'+ticker+'%27)%20&format=json&env=store://datatables.org/alltableswithkeys', timeout=4)
        api = urllib2.urlopen(apiurl, timeout=4)
        response = api.read()
        response_dictionary = json.loads(response)

        #print response_dictionary
        stock_name = response_dictionary['query']['results']['quote']['Name'].replace("Common Stock", '').replace(' Inc','').replace(',','').replace('.','').replace('(NS) O','')
        symbol = response_dictionary['query']['results']['quote']['symbol']
        
        # get the price
        stock_price = response_dictionary['query']['results']['quote']['LastTradePriceOnly']
        # trim it to something sane
        stock_price = round(decimal.Decimal(stock_price),2)

        #find the change
        stock_change = response_dictionary['query']['results']['quote']['Change']
        # trim it to something sane
        stock_change = round(decimal.Decimal(stock_change),2)
        stock_change = str(stock_change)
        stock_change = stock_change.replace("-",'▼').replace("+",'▲').strip()
    #    print stock_change


        #other stuff in case I ever want it
        stock_high = response_dictionary['query']['results']['quote']['DaysHigh']
        stock_high = round(decimal.Decimal(stock_high),2)
        stock_low = response_dictionary['query']['results']['quote']['DaysLow']
        stock_low = round(decimal.Decimal(stock_low),2)
        market_cap = response_dictionary['query']['results']['quote']['MarketCapitalization']

        whole_price = floor(stock_price)
        decimal_price = floor((stock_price - whole_price)*100)
        stock_price_spoken = bsn.n2w(int(whole_price)) + ' dollars'
        if decimal_price > 0:
          stock_price_spoken += ' and ' + bsn.n2w(int(decimal_price)) + ' cents'
        
        stocks += stock_name + ' is trading at ' + stock_price_spoken + '.  '
        stocks_display += str(symbol) + ' ' + str(stock_price) + str(stock_change) + ', '


      except Exception:
        if self.debug:
          print ticker + ' Failed.'
        stocks = 'Failed to connect to Yahoo Finance.  '

    if self.debug:
      print stocks
      print stocks_display

    self.content = stocks
Esempio n. 5
0
        # find the change
        stock_change = response_dictionary["query"]["results"]["quote"]["Change"]
        # trim it to something sane
        stock_change = round(decimal.Decimal(stock_change), 2)
        stock_change = str(stock_change)
        stock_change = stock_change.replace("-", "▼").replace("+", "▲").strip()
        #    print stock_change

        # other stuff in case I ever want it
        stock_high = response_dictionary["query"]["results"]["quote"]["DaysHigh"]
        stock_high = round(decimal.Decimal(stock_high), 2)
        stock_low = response_dictionary["query"]["results"]["quote"]["DaysLow"]
        stock_low = round(decimal.Decimal(stock_low), 2)
        market_cap = response_dictionary["query"]["results"]["quote"]["MarketCapitalization"]

        whole_price = floor(stock_price)
        decimal_price = floor((stock_price - whole_price) * 100)
        stock_price_spoken = bsn.n2w(int(whole_price)) + " dollars"
        if decimal_price > 0:
            stock_price_spoken += " and " + bsn.n2w(int(decimal_price)) + " cents"

        stocks += stock_name + " is trading at " + stock_price_spoken + ".  "
        stocks_display += str(symbol) + " " + str(stock_price) + str(stock_change) + ", "

    except Exception:
        stocks = "Failed to connect to Yahoo Finance.  "

if Config.get("main", "debug") == str(1):
    print stocks
    print stocks_display
Esempio n. 6
0
tickers=Config.get('stocks','tickers').split(',')

stocks='Stock update: '

for ticker in tickers:
  try: 
    api = urllib2.urlopen('http://finance.yahoo.com/webservice/v1/symbols/'+ticker+'/quote?format=json', timeout=4)
    response = api.read()
    response_dictionary = json.loads(response)
    stock_name = response_dictionary['list']['resources'][0]['resource']['fields']['name'].replace("Common Stock", '').replace(' Inc','').replace(',','').replace('.','').replace('(NS) O','')

    # get the price
    stock_price = response_dictionary['list']['resources'][0]['resource']['fields']['price']
    # trim it to something sane
    stock_price = round(decimal.Decimal(stock_price),2)

    whole_price = floor(stock_price)
    decimal_price = floor((stock_price - whole_price)*100)
    stock_price = bsn.n2w(int(whole_price)) + ' dollars'
    if decimal_price > 0:
      stock_price += ' and ' + bsn.n2w(int(decimal_price)) + ' cents'
    
    stocks += stock_name + ' is trading at ' + stock_price + '.  '
    
  except Exception:
    stocks = 'Failed to connect to Yahoo Finance.  '

if Config.get('main','debug') == str(1):
  print stocks
Esempio n. 7
0
    def build(self):
        tickers = self.sconfig['tickers'].split(',')

        stocks = 'Stock update: '
        stocks_display = 'markets: '

        for ticker in tickers:
            try:
                apiurl = 'https://' + \
                         self.sconfig['host'] + \
                         self.sconfig['path'] + \
                         ticker + \
                         self.sconfig['pathtail']
                print apiurl
                #api = urllib2.urlopen('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%27'+ticker+'%27)%20&format=json&env=store://datatables.org/alltableswithkeys', timeout=4)
                api = urllib2.urlopen(apiurl, timeout=4)
                response = api.read()
                response_dictionary = json.loads(response)

                #print response_dictionary
                stock_name = response_dictionary['query']['results'][
                    'quote']['Name'].replace("Common Stock", '').replace(
                        ' Inc',
                        '').replace(',', '').replace('.',
                                                     '').replace('(NS) O', '')
                symbol = response_dictionary['query']['results']['quote'][
                    'symbol']

                # get the price
                stock_price = response_dictionary['query']['results']['quote'][
                    'LastTradePriceOnly']
                # trim it to something sane
                stock_price = round(decimal.Decimal(stock_price), 2)

                #find the change
                stock_change = response_dictionary['query']['results'][
                    'quote']['Change']
                # trim it to something sane
                stock_change = round(decimal.Decimal(stock_change), 2)
                stock_change = str(stock_change)
                stock_change = stock_change.replace("-",
                                                    '▼').replace("+",
                                                                 '▲').strip()
                #    print stock_change

                #other stuff in case I ever want it
                stock_high = response_dictionary['query']['results']['quote'][
                    'DaysHigh']
                stock_high = round(decimal.Decimal(stock_high), 2)
                stock_low = response_dictionary['query']['results']['quote'][
                    'DaysLow']
                stock_low = round(decimal.Decimal(stock_low), 2)
                market_cap = response_dictionary['query']['results']['quote'][
                    'MarketCapitalization']

                whole_price = floor(stock_price)
                decimal_price = floor((stock_price - whole_price) * 100)
                stock_price_spoken = bsn.n2w(int(whole_price)) + ' dollars'
                if decimal_price > 0:
                    stock_price_spoken += ' and ' + bsn.n2w(
                        int(decimal_price)) + ' cents'

                stocks += stock_name + ' is trading at ' + stock_price_spoken + '.  '
                stocks_display += str(symbol) + ' ' + str(stock_price) + str(
                    stock_change) + ', '

            except Exception:
                if self.debug:
                    print ticker + ' Failed.'
                stocks = 'Failed to connect to Yahoo Finance.  '

        if self.debug:
            print stocks
            print stocks_display

        self.content = stocks
Esempio n. 8
0
    stock_change = round(decimal.Decimal(stock_change),2)
    stock_change = str(stock_change)
    stock_change = stock_change.replace("-",'▼').replace("+",'▲').strip()
#    print stock_change


    #other stuff in case I ever want it
    stock_high = response_dictionary['query']['results']['quote']['DaysHigh']
    stock_high = round(decimal.Decimal(stock_high),2)
    stock_low = response_dictionary['query']['results']['quote']['DaysLow']
    stock_low = round(decimal.Decimal(stock_low),2)
    market_cap = response_dictionary['query']['results']['quote']['MarketCapitalization']

    whole_price = floor(stock_price)
    decimal_price = floor((stock_price - whole_price)*100)
    stock_price_spoken = bsn.n2w(int(whole_price)) + ' dollars'
    if decimal_price > 0:
      stock_price_spoken += ' and ' + bsn.n2w(int(decimal_price)) + ' cents'
    
    stocks += stock_name + ' is trading at ' + stock_price_spoken + '.  '
    stocks_display += str(symbol) + ' ' + str(stock_price) + str(stock_change) + ', '


  except Exception:
    stocks = 'Failed to connect to Yahoo Finance.  '

if Config.get('main','debug') == str(1):
  print stocks
  print stocks_display
  command = 'tts "' + stocks + '"'
  subprocess.call(command, shell=True, stdout=subprocess.PIPE)
Esempio n. 9
0
from math import floor
import ConfigParser

Config = ConfigParser.ConfigParser()
try:
    Config.read("alarm.config")
except:
    raise Exception("Sorry, Failed reading alarm.config file.")

try:
    coinbase_api = urllib.urlopen("https://coinbase.com/api/v1/prices/buy")
    response = coinbase_api.read()
    response_dictionary = json.loads(response)
    # reads bit coin value from coinbase
    btc_price = response_dictionary["subtotal"]["amount"]
    whole_price = int(floor(float(btc_price)))
    decimal_price = int(floor((float(btc_price) - whole_price) * 100))
    btc_price = bsn.n2w(int(whole_price)) + " dollars"
    if decimal_price > 0:
        btc_price += " and " + bsn.n2w(int(decimal_price)) + " cents"

    btc = "The value of 1 bitcoin is: " + btc_price + ".  "
except Exception:
    btc = "Failed to connect to coinbase.  "

# print response_dictionary['amount']
# print response_dictionary['subtotal']['amount']

if Config.get("main", "debug") == str(1):
    print btc