Created
July 14, 2016 20:48
-
-
Save rmgimenez/ebcd876471dd5d6069cfbc0e3aece0b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from peewee import * | |
import datetime | |
db = SqliteDatabase('banco_dados.sqlite') | |
class BaseModel(Model): | |
class Meta: | |
database = db | |
class Cotacao(BaseModel): | |
simbolo = CharField() | |
dt = DateTimeField() | |
volume = IntegerField(default=0) | |
preco_abertura = FloatField() | |
preco_maximo = FloatField() | |
preco_minimo = FloatField() | |
preco_fechamento = FloatField() | |
from yahoo_finance import Share | |
from models import Cotacao | |
import models | |
models.db.connect() | |
models.db.create_tables([Cotacao], safe=True) | |
acao = Share('FIBR3.SA') | |
cotacoes = acao.get_historical('2016-07-01', '2016-07-17') | |
print(cotacoes[1]['Volume']) | |
for cotacao in cotacoes: | |
existe = True | |
for c in Cotacao.raw('select count(*) total from cotacao where dt = "'+cotacao['dt']+'"'): | |
if c.total == 0: | |
existe = False | |
if(existe == False): | |
cot = Cotacao( | |
simbolo=cotacao['Symbol'], | |
dt=cotacao['Date'], | |
volume=cotacao['Volume'], | |
preco_abertura=cotacao['Open'], | |
preco_maximo=cotacao['High'], | |
preco_minimo=cotacao['Low'], | |
preco_fechamento=cotacao['Close'], | |
) | |
cot.save() | |
from datetime import datetime | |
from datetime import timedelta | |
from yahoo_finance import Share | |
from models import Cotacao | |
import models | |
models.db.connect() | |
models.db.create_tables([Cotacao], safe=True) | |
#c = Cotacao() | |
#x = c.select().where((Cotacao.simbolo=='FIBR3.SA') | (Cotacao.simbolo=='FIBR3.S')).get() | |
#x = c.select().where(Cotacao.simbolo=='FIBR3.SA').where(Cotacao.simbolo=='FIBR3.S').get() | |
#x = c.select().where(Cotacao.simbolo=='FIBR3.SA').where(Cotacao.dt=='2016-05-01').get() | |
x = models.db.execute_sql('select * from cotacao') | |
for c in Cotacao.raw('select count(*) total from cotacao where dt = "2016-07-24"'): | |
print(c.total) | |
y = Cotacao.raw('select count(*) total from cotacao where dt = "2016-07-24"') | |
print(help(y)) | |
date_object = datetime.strptime('2016-01-01', '%Y-%m-%d') | |
print(date_object - timedelta(days=10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment