Created
October 14, 2017 16:02
-
-
Save boochow/4947028327f6723b542484b0e7572d42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
import network, socket, ujson | |
from machine import Pin | |
nic = network.WIZNET5K(pyb.SPI(2), Pin('PB12'), Pin('PC8')) | |
addr = socket.getaddrinfo('api.fixer.io',80)[0][-1] | |
s = socket.socket() | |
s.connect(addr) | |
s.send(bytes('GET /latest?base=USD&symbols=JPY HTTP/1.0\r\nHost: api.fixer.io\r\n\r\n', 'utf8')) | |
result = s.recv(1000) | |
s.close() | |
lines = result.splitlines() | |
pos = lines.index(b'') | |
parsed = ujson.loads(lines[pos + 1]) | |
print(parsed["date"]) | |
print("JPY/" + parsed["base"] + ": " + str(parsed["rates"]["JPY"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://blog.boochow.com/article/454179047.html