Skip to content

Commit

Permalink
fix: right column type for date
Browse files Browse the repository at this point in the history
  • Loading branch information
polomarcus committed Oct 3, 2024
1 parent 2775546 commit 2a18df0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('channel_metadata', sa.Column('program_grid_start', sa.String(), server_default='2023-04-01', nullable=False))
op.add_column('channel_metadata', sa.Column('program_grid_end', sa.String(), server_default='', nullable=True))
op.add_column('channel_metadata', sa.Column('program_grid_start', sa.DateTime(), nullable=True))
op.add_column('channel_metadata', sa.Column('program_grid_end', sa.DateTime(), nullable=True))
# ### end Alembic commands ###


Expand Down
8 changes: 6 additions & 2 deletions postgres/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class Channel_Metadata(Base):
id = Column(Text, primary_key=True)
channel_name = Column(String, nullable=False)
channel_title = Column(String, nullable=False)
program_grid_start = Column(String, nullable=False, server_default='2023-04-01')
program_grid_end = Column(String, nullable=True, server_default='')
program_grid_start = Column(DateTime(), nullable=False, server_default='2023-04-01')
program_grid_end = Column(DateTime(), nullable=True, server_default='')
duration_minutes= Column(Integer)
weekday= Column(Integer)

Expand All @@ -113,6 +113,8 @@ class Program_Metadata(Base):
public = Column(Boolean, nullable=True)
infocontinue = Column(Boolean, nullable=True)
radio = Column(Boolean, nullable=True)
program_grid_start = Column(DateTime(), nullable=True)
program_grid_end = Column(DateTime(), nullable=True)

def get_sitemap(id: str):
session = get_db_session()
Expand Down Expand Up @@ -200,6 +202,8 @@ def update_program_metadata(engine):
'channel_program_type': item['program_type'],
'start': item['start'],
'end': item['end'],
'program_grid_start': datetime.strptime(item['program_grid_start'], '%Y-%m-%d'),
'program_grid_end': datetime.strptime(item['program_grid_end'], '%Y-%m-%d'),
}
session.merge(Program_Metadata(**metadata))

Expand Down
3 changes: 3 additions & 0 deletions transform_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def generate_program_id(channel_name, weekday, program_name):
end_time = program_data['end']
duration_minutes = calculate_duration(start_time, end_time)

if program_data['program_grid_start'] == '':
program_data['program_grid_start'] = '2100-01-01'

# Add duration to the program data
program_data['duration'] = duration_minutes

Expand Down

0 comments on commit 2a18df0

Please sign in to comment.