2018-08-31

datetime

log _ Saturday

memo_with_datetime_0.2

# title : memo_with_datetime_0.2.py
# date  : 2106-06-10-FRI
# des   : make input, and save file in folder( one line -> datetime info  and string )
# impro : tag support 
# state : success  ( two function )

import datetime 
import logging 

logging.basicConfig(level=logging.DEBUG)

# get input 
# get now's datetime
# write file with one line 

# OUTPUT SAMPLE : 
# Jun-04-Sat : * last check time 

# impro : if there's more item in one day, then..
# Jun-04-Sat :  * library
#               * borrow comic book 
# More impro : use database ( learn about that course. )

def get_memo():
    # input 2 -> return : event_description(str), event_datetime(datetime)
    get_event = input('WRITE EVENT >' )

    while True:
        try: 
            t_get_datetime = input('WRITE DATE (16/08/23) >')
            get_datetime = datetime.datetime.strptime(t_get_datetime,'%y/%m/%d')
        except ValueError: 
            # When there's no valid datetime
            continue 
        else: 
            break 

    return (get_event, get_datetime)

def record(a_tup): # get str type
    # get tup (<str>, <datetime>) and write file 
    try: 
        file = open('memo_with_datetime_0.2.txt', 'a')
        logging.info('File is opened with append mode.')
    except FileExistsError:
        file = open('memo_with_datetime.0.2.txt', 'x')
        logging.info('File is opened with first creating.')
    finally:
        a_str, a_datetime = a_tup
        t_fmt = '{!s} : {!s}\n'
        file.write(t_fmt.format(a_datetime.strftime('%y/%m/%d'), a_str))
        logging.info('File is typed.')
        file.close()


# === EXPERIMENT 
a, b = get_memo()
# convert b to str
a_day = b.year, b.month, b.day 
print(a + ' : ' + '{}/{}/{}'.format(*a_day))

# success 

record((a,b))
outcome


number_factory_0.3

# Author    : JiYoung
# Day       : 2106-06-09-THU / 2106-06-10-Fri
# About     : Simple Vertical Calendar 
# File_name : number_factory.py
# version   : 0.3 
''' out put :  input =  3-5
3
4
5
'''
import datetime

def get_number():
    get = input('insert two number to generate (ex:3-5)>')
    return get


def parse_it(get_string):
    one, two = get_string.split('-')
    return (int(one), int(two))

# need to change( datetime.... )
def show(a_tup):
    # import pdb; pdb.set_trace()
    one, two = a_tup
    for _ in range(one, two + 1):  # range function exclude last argument 
        print(_)


def show_datetime(a_tup): # get two datetime and return day list  
    one, two = a_tup
    a_datetime_list = []
    a_datetime_day_list =[]  # int type 

    a_datetime_list.append(one)
    a_datetime_day_list.append(int(one.day))

    one_day_delta =  datetime.timedelta(days=1)
    while(a_datetime_list[-1] != two):
        next_datetime = a_datetime_list[-1] + one_day_delta
        a_datetime_list.append(next_datetime)
        a_datetime_day_list.append(int(next_datetime.day))


    return a_datetime_list, a_datetime_day_list 

# show(parse_it(get_number()))
a_1 = datetime.datetime(year=2016, month=5, day=29)
a_2 = a_1 + datetime.timedelta(days=40)
# experiment ( especially days )
tups = a_1 , a_2 
datetime_list, day_list = show_datetime(tups)

for index, a_datetime in enumerate(datetime_list):
    that_month =  datetime_list[index].month
    that_day = datetime_list[index].day
    print(a_datetime.strftime('%b-%d-%a'))



 

댓글 없음:

댓글 쓰기