-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
64 lines (49 loc) · 1.73 KB
/
classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from flask import Flask
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///recs.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Init my db
db = SQLAlchemy(app)
# Init Marshmallow as ma
ma = Marshmallow(app)
# Channels Class/Model
class Channel(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text)
keyname = db.Column(db.Text)
type = db.Column(db.Text)
url = db.Column(db.Text)
def __init__(self, name, keyname, type, url):
# self.id = id
self.name = name
self.keyname = keyname
self.type = type
self.url = url
# Recording Class/Model
class Recording(db.Model):
id = db.Column(db.Integer, primary_key=True)
channel_id = db.Column(db.Integer)
start_time = db.Column(db.Text) # i set this as datetime but we have an issue on sqlite with datetimes
end_time = db.Column(db.Text) # i set this as datetime but we have an issue on sqlite with datetimes
path = db.Column(db.Text)
def __init__(self, channel_id, start_time, end_time, path):
self.channel_id = channel_id
self.start_time = start_time
self.end_time = end_time
self.path = path
# Channels Schema
class ChannelSchema(ma.Schema):
class Meta:
fields = ('id', 'name', 'keyname', 'type', 'url')
# Recording Schema
class RecordingSchema(ma.Schema):
class Meta:
fields = ('id', 'channel_id', 'start_time', 'end_time', 'path')
# Init schema
channel_schema = ChannelSchema()
channels_schema = ChannelSchema(many=True)
recording_schema = RecordingSchema()
recordings_schema = RecordingSchema(many=True)
db.create_all()