Beispiel #1
0
class Car(Model):
    name = CarModel()
    price = Price()
    placa = LicensePlate()

    def __repr__(self):
        return '<%s %s>' % (self.name, self.price)
Beispiel #2
0
def save_product(session, product_dict, shop):
    print("save_product")
    if product_dict['price'] == 0:
        return
    product = session.query(Product).filter_by(
        external_id=product_dict['external_id'], shop_id=shop.id
    ).first()
    if not product:
        product = Product(
            title=product_dict['title'], description=product_dict['description'], url=product_dict['url'],
            current_price=product_dict['price'], lowest_price=product_dict['price'], lowest_price_aberrance=1.0,
            external_id=product_dict['external_id']
        )
        shop.products.append(product)
        session.add(product)
        logging.info("added product with url: {}, title: {}".format(product.url, product.title))
        print("added product with url: {}, title: {}".format(product.url, product.title))
    else:
        logging.info("shop {}, product id {} existiert schon als name {} und url {}\n".format(
            shop.name, product_dict['external_id'], product.title, product.url
        ))
        print("shop {}, product id {} existiert schon als name {} und url {}\n".format(
            shop.name, product_dict['external_id'], product.title, product.url
        ))
        product.title = product_dict['title']
        product.description = product_dict['description']
        product.url = product_dict['url']
        product.current_price = product_dict['price']
        product.lowest_price = min(product_dict['price'], product.lowest_price)
        product.lowest_price_aberrance = product.current_price / product.lowest_price

    product.prices.append(Price(value=product_dict['price'], date=datetime.date.today()))
Beispiel #3
0
def get_max_price():
    price = Price.get_max_price()

    if price is not None:
        return int(price.price)
    else:
        return None
Beispiel #4
0
def add_price(symbol, date_time, price):
    old_price = get_price(symbol, date_time)
    if old_price is None:
        price = Price(symbol, date_time, price)
        db.add(price)
        return db
    else:
        return None
Beispiel #5
0
def db_parse_price(game_info):
    if game_info['is_free']:
        return None
    else:
        price_info = game_info['price_overview']
        return Price(price=price_info['final'] / 100,
                     price_original=price_info['initial'] / 100,
                     discount=price_info['discount_percent'] / 100,
                     currency=price_info['currency'])
Beispiel #6
0
def get_minutes_ago_price(minutes):
    today = datetime.today()
    half_hour_ago = today - timedelta(minutes=minutes)
    price = Price.get_price_before(half_hour_ago)

    if price is not None:
        return int(price.price)
    else:
        return None
Beispiel #7
0
def get_a_day_ago_price():
    today = datetime.today()
    a_day_ago = today - timedelta(days=1)
    price = Price.get_price_before(a_day_ago)

    if price is not None:
        return int(price.price)
    else:
        return None
Beispiel #8
0
def create_price(toy, store, price_dollars, price_effective_date, price_end_date):
    """Create and return a price."""

    price = Price(toy=toy,
                store=store,
                price_dollars = price_dollars,
                price_effective_date= price_effective_date,
                price_end_date = price_end_date)

    db.session.add(price)
    db.session.commit()

    return price
Beispiel #9
0
from sys import argv
from model import Price
from config import DBURL
import pandas as pd
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine

script, filename = argv

engine = create_engine(DBURL)

Session = sessionmaker(bind=engine)

session = Session()

data = pd.read_csv(filename, sep=" ", header=0, names=['code', 'name'])

for i in range(0, len(data)):
    open = data['open'][i]
    high = data['high'][i]
    low = data['low'][i]
    close = data['close']
    wap = data['wap']
    last = data['last']
    volume = data['volume']
    session.add(Price(open, high, low, close, wap, last, volume))

session.commit()