Hi guys, I have question about python. I mean I need a litle help.
How can I increase date from date given in file by start after midnight?

File looks like:

PROGRAMSKA SHEMA ZA PETAK, 13.12.2013.   

06:00 ZMBT televoting
06:05 Madhubala, igrana serija, 138. epizoda, r.
06:50 Tajne, igrana serija, 55. epizoda, r.
07:30 Naša kuhinja
08:25 TV izlog
08:45 Bratzillaz, crtani film, 7. i 8. epizoda
08:55 ZMBT televoting
09:00 Prva dama, igrana serija, 89. epizoda
10:00 Štrumfovi, crtani film, 20. epizoda
10:30 Pčelica Maja, crtani film, 5. epizoda
10:52 Monster high, crtani film, 404. i 405. epizoda 
10:55 Monsuno, crtani film, 20. epizoda
11:20 TV izlog 
11:40 Tokovi novca
11:45 Vijesti           
11:57 Biometeorološka prognoza
12:00 Madhubala, igrana serija, 138. epizoda, r.
12:50 Prva dama, igrana serija, 90. epizoda 
13:50 Tajne, igrana serija, 55. epizoda
14:40 TV izlog
15:15 ZMBT televoting 
15:20 Muzički program
15:45 ZMBT televoting 
15:50 Karadayi, igrana serija, 68. epizoda 
16:50 Po spisku, talk show
17:45 Krv nije voda, serijski program, 107. epizoda
18:39 International Health
18:49 Domaćica Ovako
19:00 Vijesti u 7, informativni program
19:28 Vremenska prognoza
19:29 Biometeorološka prognoza
19:31 Sport
19:38 Stanje na putevima 
19:45 Tokovi novca
19:55 ZMBT televoting
20:00 Kolo sreće
20:05 Madhubala, igrana serija, 139. epizoda
21:05 ZMBT 6, show uživo
23:55 Sport centar
00:00 Dolina vukova, igrana serija, 97. i 98. epizoda   
Reprizni program Hayat TV-a    
01:55 ZMBT televoting
02:00 Vijesti u 7, informativni program
02:30 ZMBT 6, show
04:45 Muzički program

OK with regex i get date, and start time.
My code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import re
import time 
import glob
import logging
from datetime import datetime
import datetime


def get_date_time():

    # Values for date 
    # Example         : '''YYYY-MM-DD, YYYY-DD-MM, DD MM YYYY, MM DD YYYY'''
    # Example of time : '''(00:00:00, 00:00, 0:00 -- 24 Time) | (00:00, 0:00 -- AM, PM)'''
    ######################################################################################
    #Let's add some date/time examples

    ######################################################################################
    # TS -> 05h 
    # Calculating time 
    # Open File for checking
    input_file = open('date.txt','r')

    # Open Output file for writting
    output     = open('date_change.txt','w')

    for line in input_file:
        # Let's take date with regex on example --> 1/6/2014 (MM-DD-YYYY), Time --> 24h (0:00| 00:00)

        if re.search(r'\d{2}.\d{2}.\d{4}', line):

            line_date1  = re.findall(r'\d{2}.\d{2}.\d{4}',line)[0]

        else:

            if not re.search(r'\d{2}.\d{2}.\d{4}',line):
                line_date = ''
                print line_date
                # Start

        if re.search(r'\d{2}:\d{2}.*',line):
            line_start = re.findall(r'\d{2}:\d{2}',line)[0]
            var2 = line_start+' '+line_date1

            var = line_start



            if var > '00:00':

                var1 = var
                Date = datetime.datetime.strptime(line_date1, "%d.%m.%Y")
                EndDate = Date + datetime.timedelta(days=1)
                print str(EndDate) + ' '+var1

            else:
                Date = datetime.datetime.strptime(line_date1, "%d.%m.%Y")

                print str(Date)+' '+var1




get_date_time()

Can you guys give me advice, I want automaticly to increse date after 23:59 to new date, increse for one day.

Thx, for reading this post and i hope for some good answers guys.

This might help ...

''' datetime_add_time101.py
add 1 second to a time near midnight

some time format specifiers ...
%a  Locale's abbreviated weekday name
%A  Locale's full weekday name
%b  Locale's abbreviated month name
%B  Locale's full month name
%c  Locale's appropriate date and time representation
%d  Day of the month as a decimal number [01,31]
%H  Hour (24-hour clock) as a decimal number [00,23]
%I  Hour (12-hour clock) as a decimal number [01,12]
%m  Month as a decimal number [01,12]
%M  Minute as a decimal number [00,59]
%p  Locale's equivalent of either AM or PM
%S  Second as a decimal number [00,61]. Yes, 61 !
%y  Year without century as a decimal number [00,99]
%Y  Year with century as a decimal number
'''

import datetime as dt

# mm/dd/yyyy hh:mm:ss style
date_time_str = "12/25/2013 23:59:59"
print(date_time_str)
date_time_format = "%m/%d/%Y %H:%M:%S"
# parse to form an datetime object
dt_object = dt.datetime.strptime(date_time_str, date_time_format)

# create a one second time delta
one_second = dt.timedelta(seconds=1)
# add the one second time delta to the dt object
new_dt_object = dt_object + one_second

print("one second added ...")
# format the date object to mm/dd/yyyy hh:mm:ss style 
print(dt.datetime.strftime(new_dt_object, date_time_format))

''' result ...
12/25/2013 23:59:59
one second added ...
12/26/2013 00:00:00
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.