Exemplo n.º 1
0
def main():
    lcd.clear()
    lcd.setBrightness(800)
    lcd.setTextColor(lcd.WHITE, lcd.BLACK)
    lcd.font('SFArch_48.fon')
    lcd.print('BTC Price', lcd.CENTER, 25, lcd.ORANGE)
    prev_price = ''
    timereset = time.ticks_ms() + (60 * 1000)
    while True:
        if not m5cloud.idle():
            break
        try:
            # btc_data = get_btc_price()
            gc.collect()
            lcd.triangle(300, 0, 319, 0, 319, 19, lcd.YELLOW, lcd.YELLOW)
            r = curl.get('http://api.m5stack.com/btc')
            lcd.triangle(300, 0, 319, 0, 319, 19, lcd.BLUE, lcd.BLUE)
            btc_data = ujson.loads(r[2])
            print(btc_data)
            print('')
            if btc_data:
                # Max price
                high = btc_data['high']
                high = high[:(high.find('.') + 3)]
                lcd.font(lcd.FONT_DejaVu18)
                lcd.print('Max:', 20, 192, lcd.GREEN)
                lcd.print(high, 5, 215, lcd.GREEN)

                # Min price
                low = btc_data['low']
                low = low[:(low.find('.') + 3)]
                lcd.font(lcd.FONT_DejaVu18)
                lcd.print('Min:', 255, 192, lcd.RED)
                lcd.print(low, lcd.RIGHT, 215, lcd.RED)

                # Last Price
                price = btc_data['last']
                if not price == prev_price:
                    lcd.rect(0, 100, 320, 48, lcd.BLACK, lcd.BLACK)
                    lcd.font('SFArch_48.fon')
                    lcd.print('$ ' + price, lcd.CENTER, 100, color=lcd.WHITE)

                # Symbol
                _offset = 175
                if price > prev_price:
                    lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
                    lcd.triangle(160, _offset, 140, _offset + 25, 180,
                                 _offset + 25, lcd.GREEN, lcd.GREEN)
                elif price < prev_price:
                    lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
                    lcd.triangle(160, _offset + 25, 140, _offset, 180, _offset,
                                 lcd.RED, lcd.RED)
                prev_price = price

        except:
            pass
        time.sleep(5)
Exemplo n.º 2
0
def getYahooHeadline(categoryIndex):
    if categoryIndex < len(yahooHeadlineURLList):
        categoryURL = yahooHeadlineURLList[categoryIndex]
    else:
        categoryURL = random.choice(yahooHeadlineURLList)

    #Yahooヘッドライン取得(XML)
    yahooHeadLineResponse = urequests.get(categoryURL)
    yahooHeadLine = yahooHeadLineResponse.text

    titleTextList = []
    titleCount = 0
    startIndex = 0
    #<title>と</title>の間を取得。最初のtitleはニュースカテゴリ名だけど気にせず読む。
    while titleCount < 10:  #念のためMAX10まで
        if not m5cloud.idle():
            break
        yahooHeadLine = yahooHeadLine[startIndex:-1]  #前回検索対象となった部分以降のみ取得
        titleStartIndex = yahooHeadLine.find("<title>")
        titleEndIndex = yahooHeadLine.find("</title>")
        if titleStartIndex == -1:
            break
        titleStartIndex = titleStartIndex + 7  #<title>の分をずらす
        titleText = yahooHeadLine[titleStartIndex:titleEndIndex]
        #不謹慎フィルター
        tabooFind = False
        for tabooword in tabooWords:
            if titleText.find(tabooword) != -1:
                tabooFind = True
                break
        if tabooFind == False:
            titleTextList.append(titleText)

        startIndex = titleEndIndex + 1  #以降、この後ろから探す
        titleCount = titleCount + 1

    gc.collect()
    return titleTextList
Exemplo n.º 3
0
def main():
    lcd.clear()
    lcd.setBrightness(800)
    lcd.setTextColor(lcd.WHITE, lcd.BLACK)
    lcd.font('SFArch_48.fon')
    lcd.print('BTC Price', lcd.CENTER, 25, lcd.ORANGE)
    prev_price = ''
    timereset = time.ticks_ms() + (60 * 1000)
    while True:
        if not m5cloud.idle():
            break
        try:
            # btc_data = get_btc_price()
            gc.collect()
            lcd.triangle(300, 0, 319, 0, 319, 19, lcd.YELLOW, lcd.YELLOW)
            r = urequests.get('https://m5stack.it/btc.php')
            lcd.triangle(300, 0, 319, 0, 319, 19, lcd.BLUE, lcd.BLUE)
            btc_data = ujson.loads(r.text)
            print(btc_data)
            print('')
            if btc_data:
                # Max price
                high = btc_data['high_24h']
                high = high[:(high.find('.') + 3)]
                lcd.font(lcd.FONT_DejaVu18)
                lcd.print('Max:', 20, 192, lcd.GREEN)
                lcd.print(high, 5, 215, lcd.GREEN)

                # Min price
                low = btc_data['low_24h']
                low = low[:(low.find('.') + 3)]
                lcd.font(lcd.FONT_DejaVu18)
                lcd.print('Min:', 255, 192, lcd.RED)
                lcd.print(low, lcd.RIGHT, 215, lcd.RED)

                # Last Price
                price = btc_data['current_price']
                if not price == prev_price:
                    lcd.rect(0, 100, 320, 48, lcd.BLACK, lcd.BLACK)
                    lcd.font('SFArch_48.fon')
                    lcd.print('$ ' + price, lcd.CENTER, 100, color=lcd.WHITE)

                # Symbol
                _offset = 175
                if price > prev_price:
                    lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
                    lcd.triangle(160, _offset, 140, _offset + 25, 180,
                                 _offset + 25, lcd.GREEN, lcd.GREEN)
                elif price < prev_price:
                    lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
                    lcd.triangle(160, _offset + 25, 140, _offset, 180, _offset,
                                 lcd.RED, lcd.RED)
                prev_price = price

                # update time
                tstr = 'Update: %s' % (btc_data['last_updated'])
                lcd.font(lcd.FONT_Default)
                lcd.print(tstr, 3, 3, 0x666666)

        except Exception as e:
            sys.print_exception(e)
            pass

        time.sleep(5)
Exemplo n.º 4
0
def main():
    lcd.clear()
    lcd.setBrightness(800)
    lcd.setTextColor(lcd.WHITE, lcd.BLACK)
    lcd.font('SFArch_48.fon')
    lcd.print('BTC Price', lcd.CENTER, 25, lcd.ORANGE)
    prev_price = ''
    timereset = time.ticks_ms() + (60 * 1000)
    while True:
        if not m5cloud.idle():
            break
        try:
            # btc_data = get_btc_price()
            gc.collect()
            lcd.triangle(300, 0, 319, 0, 319, 19, lcd.YELLOW, lcd.YELLOW)
            r = urequests.get("http://api.m5stack.com/btc")
            # r = urequests.get("http://api.coindesk.com/v1/bpi/currentprice/usd.json")
            lcd.triangle(300, 0, 319, 0, 319, 19, lcd.BLUE, lcd.BLUE)
            btc_data = ujson.loads(r.text)
            print(btc_data)
            print('')
            if btc_data:
                # Max price
                high = btc_data['high']
                high = high[:(high.find('.') + 3)]
                lcd.font(lcd.FONT_DejaVu18)
                lcd.print('Max:', 20, 192, lcd.GREEN)
                lcd.print(high, 5, 215, lcd.GREEN)

                # Min price
                low = btc_data['low']
                low = low[:(low.find('.') + 3)]
                lcd.font(lcd.FONT_DejaVu18)
                lcd.print('Min:', 255, 192, lcd.RED)
                lcd.print(low, lcd.RIGHT, 215, lcd.RED)

                # Last Price
                price = btc_data['last']
                # price = btc_data['bpi']['USD']['rate_float']
                # price = '%.2f' % price
                if not price == prev_price:
                    lcd.rect(0, 100, 320, 48, lcd.BLACK, lcd.BLACK)
                    lcd.font('SFArch_48.fon')
                    lcd.print('$ ' + price, lcd.CENTER, 100, color=lcd.WHITE)

                # Symbol
                _offset = 175
                if price > prev_price:
                    lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
                    lcd.triangle(160, _offset, 140, _offset + 25, 180,
                                 _offset + 25, lcd.GREEN, lcd.GREEN)
                elif price < prev_price:
                    lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
                    lcd.triangle(160, _offset + 25, 140, _offset, 180, _offset,
                                 lcd.RED, lcd.RED)
                prev_price = price

                # # updated time
                # lcd.font(lcd.FONT_Default)
                # lcd.print('Updated:'+btc_data['time']['updated'], lcd.CENTER, 222, 0x999999)
        except:
            pass
        time.sleep(5)