ical2txt.py - implemented start and stop dates to limit the amount of output. If not specified, everything is written.
This commit is contained in:
parent
f9a7cf07f2
commit
01656d6f53
25
ical2txt.py
25
ical2txt.py
@ -6,6 +6,7 @@ from icalendar import Calendar
|
|||||||
import csv
|
import csv
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import warnings
|
import warnings
|
||||||
|
from dateutil.parser import parse
|
||||||
|
|
||||||
warnings.filterwarnings("ignore", category=UserWarning, module='bs4') # We don't want warnings about URL's. We just what the URL printed, if there.
|
warnings.filterwarnings("ignore", category=UserWarning, module='bs4') # We don't want warnings about URL's. We just what the URL printed, if there.
|
||||||
|
|
||||||
@ -89,21 +90,29 @@ def txt_write(icsfile):
|
|||||||
prevdate=""
|
prevdate=""
|
||||||
spent=0
|
spent=0
|
||||||
evcount=0
|
evcount=0
|
||||||
|
evskip=0
|
||||||
|
istart=0
|
||||||
|
istop=4102441200.0 # The year 2100. Hopefully this will not be in use by then ...
|
||||||
|
if sys.argv[2] != '':
|
||||||
|
istart=parse(sys.argv[2]).timestamp()
|
||||||
|
if sys.argv[3] != '':
|
||||||
|
istop=parse(sys.argv[3]).timestamp()
|
||||||
print("Processing events :", end=" ")
|
print("Processing events :", end=" ")
|
||||||
try:
|
try:
|
||||||
with open(txtfile, 'w') as myfile:
|
with open(txtfile, 'w') as myfile:
|
||||||
for event in sortedevents:
|
for event in sortedevents:
|
||||||
|
|
||||||
if prevdate != event.start.strftime("%Y-%m-%d"): # Make a header for each day
|
if prevdate != event.start.strftime("%Y-%m-%d") and spent > 0: # Make a header for each day
|
||||||
if prevdate != '': # If you don't want a summary of the time spent added, comment this section.
|
if prevdate != '': # If you don't want a summary of the time spent added, comment this section.
|
||||||
th=divmod(spent, 3600)[0]
|
th=divmod(spent, 3600)[0]
|
||||||
tm=divmod(spent, 3600)[1]/60
|
tm=divmod(spent, 3600)[1]/60
|
||||||
myfile.write("Time Total: " + '{:02.0f}'.format(th) + ":" + '{:02.0f}'.format(tm) + "\n")
|
myfile.write("\nTime Total: " + '{:02.0f}'.format(th) + ":" + '{:02.0f}'.format(tm) + "\n")
|
||||||
spent=0
|
spent=0
|
||||||
|
if event.start.timestamp() > istart and event.start.timestamp() < istop:
|
||||||
|
if prevdate != event.start.strftime("%Y-%m-%d"): # Make a header for each day
|
||||||
prevdate = event.start.strftime("%Y-%m-%d")
|
prevdate = event.start.strftime("%Y-%m-%d")
|
||||||
myfile.write("\nMMO (IAM) Worklog, " + prevdate + "\n=============================\n")
|
myfile.write("\nWorklog, " + prevdate + "\n===================\n")
|
||||||
|
|
||||||
if event.end == None: print("Event without end. Me no like: " + prevdate + " - " + event.summary.encode('utf-8').decode())
|
|
||||||
duration = event.end - event.start
|
duration = event.end - event.start
|
||||||
ds = duration.total_seconds()
|
ds = duration.total_seconds()
|
||||||
spent += ds
|
spent += ds
|
||||||
@ -122,9 +131,13 @@ def txt_write(icsfile):
|
|||||||
myfile.write(values+"\n")
|
myfile.write(values+"\n")
|
||||||
print("", end=".")
|
print("", end=".")
|
||||||
evcount+=1
|
evcount+=1
|
||||||
print("\n\nWrote " + str(evcount) + " events to ", txtfile, "\n")
|
else:
|
||||||
|
print("", end="S")
|
||||||
|
evskip+=1
|
||||||
|
|
||||||
|
print("\n\nWrote " + str(evcount) + " events to ", txtfile, " and skipped ", str(evskip), " events\n")
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Could not open file! Please close Excel!")
|
print("Could not open file!")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user