-
-
Save sergiogarciadev/b4bef99fb25887e11f3e60887b1b4915 to your computer and use it in GitHub Desktop.
Cotações da Bovespa Intraday
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
#!/usr/bin/env python | |
from datetime import datetime | |
from json import loads | |
from time import gmtime, mktime, strptime | |
# LevelDict é um wrapper usando dicionário para LevelDB | |
# https://github.com/maurobaraldi/leveldict | |
from leveldict import LevelJsonDict | |
from requests import get | |
base = 'http://cotacoes.economia.uol.com.br/ws/asset' | |
assets = base + '/stock/list?size=10000' | |
intraday = base + '/{asset}/intraday?size=400&callback=uolfinancecallback0' | |
assets = {i['code']: i['idt'] for i in get(assets).json()['data']} | |
# 3 ativos para teste | |
# assets = {'PETR4.SA': 484, 'CTAX4.SA': 227, 'IGUA3.SA': 364} | |
db = LevelJsonDict('./intraday') | |
def from_ts(ts): | |
''' Convert timestamp (13 digits support) to datetime''' | |
return datetime.fromtimestamp(mktime(gmtime(ts / 1000.0))) | |
def to_ts(dt): | |
''' From strftime to timestamp (13 digits support)''' | |
return int(mktime(strptime(dt, "%Y-%m-%d %H:%M")) * 1000) | |
def get_intraday(asset): | |
url = intraday.format(**{'asset': asset}) | |
return loads(get(url).content[20:-2]) | |
if __name__ == '__main__': | |
for asset, code in assets.iteritems(): | |
today = datetime.now().strftime('%Y%m%d') | |
quote = get_intraday(code).get('data', {}) | |
db.setdefault(asset) | |
db[asset] = {today: quote} |
Author
sergiogarciadev
commented
Oct 3, 2019
via email
Eu só clonei esse repositorio daqui:
https://gist.github.com/maurobaraldi/40ec1daf0005530dd94a
Talves seja melhor falar com o autor original.
…On Thu, Oct 3, 2019 at 1:00 AM andreseg2 ***@***.***> wrote:
Não consigo instalar de jeito nenhum a biblioteca "leveldict", dando o
erro:
ERROR: Command errored out with exit status 1:
command: 'C:\Users\André\Anaconda3\python.exe' -c 'import sys, setuptools,
tokenize; sys.argv[0] =
'"'"'C:\Users\ANDR1\AppData\Local\Temp\pip-install-8iy8b8mu\leveldb\setup.py'"'"';
file='"'"'C:\Users\ANDR1\AppData\Local\Temp\pip-install-8iy8b8mu\leveldb\setup.py'"'"';f=getattr(tokenize,
'"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info
--egg-base pip-egg-info
cwd: C:\Users\ANDR~1\AppData\Local\Temp\pip-install-8iy8b8mu\leveldb
Complete output (1 lines):
Don't know how to compile leveldb for Windows!
ERROR: Command errored out with exit status 1: python setup.py egg_info
Check the logs for full command output.
Saberia dizer como poderia instalar?
Ou há alguma alternativa para LevelJsonDict ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/b4bef99fb25887e11f3e60887b1b4915?email_source=notifications&email_token=AAFGRNJVWPCGPFXYGFYFVHLQMVU6DA5CNFSM4I46CU42YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZZUG#gistcomment-3044163>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFGRNLBL4VDP324XUSBTQ3QMVU6DANCNFSM4I46CU4Q>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment