-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from maexled/folder-structure
created folder structure
- Loading branch information
Showing
6 changed files
with
81 additions
and
59 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
|
||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
sql_url = os.environ['SQL_URL'] | ||
engine = create_engine(sql_url) | ||
# use session_factory() to get a new Session | ||
_SessionFactory = sessionmaker(bind=engine) | ||
|
||
Base = declarative_base() | ||
|
||
|
||
def session_factory(): | ||
Base.metadata.create_all(engine) | ||
return _SessionFactory() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from base import Base | ||
from sqlalchemy import Column, Integer, String | ||
|
||
class MystromDevice(Base): | ||
|
||
__tablename__ = 'devices' | ||
|
||
id = Column(Integer, primary_key=True) | ||
|
||
name = Column(String(16)) | ||
ip = Column(String(16)) | ||
|
||
# Lets us print out a user object conveniently. | ||
def __repr__(self): | ||
return "<Device(id='%s', name='%s', ip='%s')>" % ( | ||
self.id, self.name, self.ip) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from base import Base | ||
from sqlalchemy import Column, Integer, Float, DateTime, ForeignKey | ||
from datetime import datetime | ||
|
||
class MystromResult(Base): | ||
|
||
__tablename__ = 'results' | ||
|
||
id = Column(Integer, primary_key=True) | ||
|
||
device_id = Column(Integer, ForeignKey('devices.id')) | ||
|
||
power = Column(Float) | ||
ws = Column(Float) | ||
relay = Column(Integer) | ||
temperature = Column(Float) | ||
date = Column(DateTime(timezone=True), default=datetime.now) | ||
|
||
# Lets us print out a user object conveniently. | ||
def __repr__(self): | ||
return "<Result(deivce_id='%s', power='%s', ws='%s', relay='%s', temperature='%s', date='%s')>" % ( | ||
self.device_id, self.power, self.ws, self.relay, self.temperature, self.date) |