-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
82 lines (66 loc) · 2.45 KB
/
utils.py
File metadata and controls
82 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
'''
utils.py:
Helper Methods
'''
import icalendar
from datetime import datetime
import pytz
import sys
import socket
INFO = 'INFO'
ERR = 'ERR '
WARN = 'WARN'
def log(lvl, msg):
'''logging'''
str_log = '[%s] %s: %s' % (str(datetime.now().strftime("%y%m%d-%H%M%S")), lvl, msg)
print(str_log)
with open('./logs/general.log', 'a+') as f:
f.write(str_log + '\n')
def utc_now():
'''return absolute datetime object of datetime.now()'''
return datetime.utcnow()
def print_progress(iteration, total, prefix='PROG', suffix='',
decimals=1, length=25, fill='>'):
percent = ("{0:." +
str(decimals) + "f}").format(100 * (iteration / float(total)))
filledLength = int(length * iteration // total)
bar = fill * filledLength + '-' * (length - filledLength)
sys.stdout.write('\r[%s] %s: |%s| %s%% %s' % (str(datetime.now().strftime("%y%m%d-%H%M%S")),
prefix, bar, percent, suffix))
# Print New Line on Complete
if iteration == total:
print("")
def print_cal_events(gcal):
''' Get all details of all scheduled VEVENTs'''
log(INFO, 'EVENT list of ICS file:')
for component in gcal.walk():
if component.name == "VEVENT":
log(INFO, ' ' + component.get('summary'))
log(INFO, ' start:' + str(component.get('dtstart').dt))
log(INFO, ' end: ' + str(component.get('dtend').dt))
def get_cal(filename):
''' return Calendar Object from .ics File'''
log(INFO, 'LOADING GCAL from ' + filename)
g = open(filename, 'rb')
gcal = icalendar.Calendar.from_ical(g.read())
if gcal:
log(INFO, 'LOADING Successful.')
else:
log(ERR, 'UNABLE TO LOAD ICS FILE.')
return gcal
def writeINFO(save_path, wb, com, args):
'''generate INFO at save_path'''
now = datetime.now()
with open(save_path + 'INFO', 'w+') as f:
f.write('[course]' + '\n')
f.write('id: ' + args[1] + '\n')
f.write('term: ' + args[0] + '\n')
f.write('' + '\n')
f.write('[pres]' + '\n')
f.write('start: ' + now.strftime('%y,%m,%d,%H,%M,%S') + '\n')
f.write('duration: ' + str(int(args[2])) + '\n')
f.write('source: ' + socket.gethostname() + '\n')
f.write('timestamp: ' + str(int(now.timestamp())) + '\n')
f.write('whiteboardCount: ' + str(wb) + '\n')
f.write('computerCount: ' + str(com) + '\n')