broadcasts.py 2.55 KB
Newer Older
1
2
3
__author__ = 'michel'
# -*- coding: utf-8 -*-

4
import datetime, os, urllib, sys
5
6
7
8
import pprint



9
#from modules.web import db
10

11
12
from sqlalchemy import Boolean, Column, Date, DateTime, Float, Integer, String, Text, Time, ForeignKey
from libraries.database.database import db
13

14
class Model:
15
16
17
18
19
20
21
22
23
    def store(self, commit=False):
        db.session.add(self)
        if commit:
            self.commit()

    def commit(self):
        db.session.commit()

# ------------------------------------------------------------------------------------------ #
24
class TimeSlotModel(Model):
25
26
27
28
29
30
31
32
33
34
    def get_length(self):
        sec1 = int(datetime.datetime.strptime(self.start[0:16].replace(" ", "T"), "%Y-%m-%dT%H:%M").strftime("%s"))
        sec2 = int(datetime.datetime.strptime(self.end[0:16].replace(" ", "T"), "%Y-%m-%dT%H:%M").strftime("%s"))
        len = sec2 - sec1
        return len

    def pretty_print(self):
        return pprint.pprint(self)

# ------------------------------------------------------------------------------------------ #
35
class TimeSlot(db.Model, TimeSlotModel):
36
    """
37
    One specific Show
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    __tablename__ = 'timeslot'
    timeslot_id = Column(Integer, primary_key=True)
    show_id = Column(Integer)

    timeslot_start = Column(DateTime, nullable=False)
    timeslot_end = Column(DateTime, nullable=False)
    show_name = Column(String(255))
    show_hosts = Column(String(255))

    is_repetition = Column(Boolean())

    fallback_playlist = Column(String(255))
    fallback_pool = Column(String(255))
    station_fallback_pool = Column(String(255))

#    entry_start = Column(DateTime, nullable=False)
#    entry_end = Column(DateTime, nullable=False)
#    source = Column(String(255))

class TimeSlotEntry(db.Model, TimeSlotModel):
    """
    One show can have multiple entries
    """
    #entry_id = Column(Integer, primary_key=True, autoincrement=True)
    timeslot_id = Column(Integer, ForeignKey("timeslot.timeslot_id"))
    entry_start = Column(DateTime, primary_key=True, nullable=False)
    entry_end = Column(DateTime, primary_key=True, nullable=False)
    source = Column(String(255))

#class Trackservice(db.Model, Model):
#    """
#    Trackservice and Logging
#    """
#    __tablename__ = 'trackservice'
#    id = Column(Integer, primary_key=True)
#    show_id = Column(Integer, ForeignKey("timeslot.id"))


def recreateDB():
    print("Recreating Database...")
    db.drop_all()
    print("all dropped. creating...")
    db.create_all()
    print("all created. commiting...")
    db.session.commit()
    print("Database recreated!")
    sys.exit(0)

#recreateDB()