This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tyme-googlecalendar.sh
executable file
·86 lines (68 loc) · 1.91 KB
/
tyme-googlecalendar.sh
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
83
84
85
86
#!/bin/bash
##
# README
#
# Convert a csv file from Tyme exportation in csv file for Google Calendar.
# First, export your Tyme datas in a csv file.
# Then, launch the script : sudo sh /path/to/tyme-googlecalendar.sh [tyme_export_csv_filename]
# When it's done, import the csv file created on Google Calendar.
# Google Calendar importing : https://support.google.com/calendar/answer/37118
#
# More informations on the Github repository : https://github.com/cba85/tyme-googlecalendar
##
##
# CONFIGURATION
##
FILE=$1
FILENAME=google_calendar_time_tracker.csv
if test $# -eq 1
then
if [ -f $FILE ];
then
##
# INITIALISATION
# Remove previous files
##
rm -rf $FILENAME
##
# INITIALISATION CSV FILE LECTURE
##
OLDIFS=$IFS
IFS=";"
COUNT=0
##
# READ TYME CSV FILE
##
while read ttype date unix_start unix_end day start end category project task subtask amount amount_decimal note sum rounding_minutes rounding_method note
do
# JUMP FIRST LINE
COUNT=$(( $COUNT + 1 ))
if [ $COUNT = 1 ];
then
# GOOGLE CALENDAR HEADER CREATION
echo "Subject,Start Date,Start Time,End Date,End Time,All day event,Description,Location" >> $FILENAME
else
# CONVERT UNIX TIMESTAMPS IN DATES
DATE_START=$(date -r $unix_start +'%Y-%m-%d')
DATE_END=$(date -r $unix_end +'%Y-%m-%d')
# WRITE TIME TRACKING
echo "[$project] $task,$DATE_START,$start:00,$DATE_END,$end:00,,$note," >> $FILENAME
fi
done < $1
##
# END CSV FILE LECTURE
##
IFS=$OLDIFS
##
# CONVERSION DONE
##
echo -e "\033[1m\033[32mTyme csv file export converted in Google Calendar csv files\033[0m"
echo -e "\033[1m\033[36m--> $FILENAME\033[0m"
else
echo -e "\033[31m[ERROR] Tyme CSV file does not exist\033[0m";
fi
# ARGUMENTS NUMBER ERROR
else
echo -e "\033[31m[ERROR] Tyme CSV filename argument is missing\033[0m";
exit 1;
fi