Skip to content

Commit

Permalink
add structure for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
philsupertramp committed Sep 4, 2020
1 parent 2d8c18f commit c5b36a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions models/channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Channel:
def __init__(self, name: str) -> None:
self.name = name


class _ChannelManager:
def __init__(self):
self.channels = {}

def get_or_create(self, name: str):
if name in self.channels.keys():
return self.channels[name]
new_channel = Channel(name)
self.channels[name] = new_channel
return new_channel


ChannelManager = _ChannelManager()
20 changes: 20 additions & 0 deletions models/programme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from datetime import datetime
from typing import Dict

from .channel import Channel, ChannelManager


class Programme:
def __init__(self, channel: Channel, start: datetime, stop: datetime):
self.channel: Channel = channel
self.start: datetime = start
self.stop: datetime = stop

@classmethod
def from_dict(cls, input_dict: Dict) -> 'Programme':
date_format = "%Y%m%d%H%M%S %z"
return cls(
ChannelManager.get_or_create(input_dict['channel']),
datetime.strptime(input_dict['start'], date_format),
datetime.strptime(input_dict['stop'], date_format)
)

0 comments on commit c5b36a2

Please sign in to comment.