scripts

Scripts for general automations
git clone git://git.laack.co/scripts.git
Log | Files | Refs

schedule.py (3429B)


      1 # This is the format I use:
      2 
      3 # - [ ] Typing    - 08:45am - 10:30am
      4 # - [ ] Meeting   - 10:30am - 11:00am
      5 # - [ ] Imbue     - 11:30am - 01:00pm
      6 # - [ ] BPP       - 01:20pm - 02:00pm
      7 # - [ ] Leetcode  - 03:05pm - 04:20pm
      8 # - [ ] Lift      - 04:20pm - 05:00pm
      9 # - [ ] Leetcode  - 05:30pm - 06:00pm
     10 # - [ ] Run       - 06:30pm - 08:30pm
     11 # - [ ] Schedule  - 08:30pm - 09:30pm
     12 
     13 # how can I codify this?
     14 
     15 # things I am noticing:
     16     # 1) Each event has one word.
     17         # a) this allows for using the space character as a delimiter. I like that.
     18     # 2) There is a certain degree of consistency
     19         # a) I generally cycle through a set of ~10 options at any given time for things to do in a day.
     20     # 3) Formatting
     21         # a) spaces, not tabs
     22         # b) columnar alignment
     23         # c) 12hour time format with leading 0
     24 
     25 # solution:
     26 
     27 # I could maintain a numbered list of things
     28 # to select from. I then type the number of the item
     29 # and if I need to specify some amount of time that isn't an hour,
     30 # I can then add that as an additional argument.
     31 
     32 # I should maintain a text file. Each line has a different task
     33 # python loads this and assigns line numbers
     34 
     35 # I type in what I want
     36 
     37 # I then get it to print everything by pressing enter at the end
     38 # with no input specified
     39 
     40 ###### ADDL. ######
     41 
     42 # I should add squishify and pushbach.
     43 # this will allow for the removal of an interval
     44 # squishing the times for each other interval into that time
     45 
     46 # the pushback method allows for updating intervals so they don't
     47 # overlap.
     48 
     49 import collections
     50 import datetime
     51 from typing import List
     52 
     53 ListItem = collections.namedtuple("ListItem", ["item", "hours"])
     54 
     55 def time_to_string(time : datetime.datetime):
     56     ret_str = ""
     57     ret_str += time.strftime("%I:%M%p").lower()
     58     return ret_str
     59 
     60 
     61 def schedule_times(items : List[ListItem], start_time : datetime.datetime) -> List[str]:
     62 
     63     current_time = start_time
     64     ret_ls = []
     65 
     66     for item in items:
     67 
     68         current_str = f"- [ ] {item.item}"
     69         current_str = f"{current_str.ljust(16, " ")}"
     70         current_str += "- "
     71         current_str += time_to_string(current_time)
     72         current_str += " - "
     73 
     74         current_time += datetime.timedelta(hours=item.hours)
     75         current_str += time_to_string(current_time)
     76 
     77         ret_ls.append(current_str)
     78 
     79     return ret_ls
     80 
     81 if __name__ == "__main__":
     82 
     83     start_time : datetime.datetime = datetime.datetime.now()
     84 
     85     items : List[ListItem] = []
     86 
     87     f = open("/home/andrew/bin/resources/scheduling.txt", "r")
     88     lines = f.readlines()
     89     f.close()
     90 
     91     lines = [line.rstrip() for line in lines]
     92 
     93 
     94     done = False
     95 
     96     while not done:
     97         for index, line in enumerate(lines):
     98             if index < 10:
     99                 print(f"[{index}]  - {line}")
    100             else:
    101                 print(f"[{index}] - {line}")
    102 
    103         print()
    104 
    105         user_input = input("Selection: ")
    106 
    107         print()
    108 
    109 
    110         if user_input == "":
    111             done = True
    112             continue
    113 
    114         inp = user_input.split(" ")
    115         item = inp[0]
    116         hours = 1
    117 
    118 
    119         if len(inp) > 1:
    120             hours = float(inp[1])
    121 
    122         try:
    123             num = int(item)
    124             items.append(ListItem(lines[num], hours))
    125         except ValueError:
    126             items.append(ListItem(item, hours))
    127 
    128     formatted_schedule = schedule_times(items, start_time)
    129 
    130     for scheduled_item in formatted_schedule:
    131         print(scheduled_item)
    132     print()