SSブログ
- | 次の10件

Creation of the data for ManyTime app from Google calendar

The data for ManyTime app is created from Google calendar.
Here, it is assumed that all the events of Google calendar are events
all day and all scripts runs on Mac.

1: The data in Google calendar is acquired using the ICAL function
of Google calendar.
Please refer to explanation of the following URL.
https://support.google.com/calendar/answer/37648?hl=
As a result, basic.ics is downloaded.

2: The ical2org program is downloaded and corrected.
org-mode is the mode using the Emacs environment as an outline
processor, a TODO list, etc., and org seems to be the data format
for org-mode.
Since it is transformed in the form that is near the data for
ManyTime app also by chance, ical2org is used.

With reference to explanation of the following URL, the ical2org
program (gawk script) which translates ics data into org data
should download.
http://orgmode.org/worg/org-tutorials/org-google-sync.html

Only the events for seven days can be treated in initial setting
of the ical2org program in the above-mentioned URL report.
Please change the corresponding section of the program as follows.
max_age = -1; # in days

3: The shell script is performed and translates the data of Google
calendar from basic.ics to output-7.txt.
It works in the terminal on Mac OS X 10.7.5.
The Ruby 1.8.7 is used on the script.

The ical2org program downloaded in step 2 makes enable execution
by using chmod u+x.
$ chmod u+x ical2org
Also the shell script tajikan.sh makes enable execution by using
chmod u+x.
$ chmod u+x tajikan.sh
$ ./tajikan.sh

4: The duplication line check of output-7.txt.
It sorts by the 2nd field(start time).
$ sort -k2 output-7.txt > output-7b.txt
This is confirmed whether there is any difference.
$ diff output-7.txt output-7b.txt
If there are duplicate lines by this check, these lines should
be deleted from output-7.txt.
  $ vi output-7.txt

5: The data for ManyTime app is created.
The data for ManyTime app with the event length corresponding
to the number of duplicate lines is created.
$ ruby tajikan-3.rb output-7.txt > output-8.txt

tajikan.rb:
#Start Time
def startTime(day, num)
 return day + " 00:00:00"
end

#End Time
def endTime(day, num)
  return day + " 23:59:00"
end

#Create the data for ManyTime from the date and the comment 
#that you extracted from the ics data of Google calendar.
aHash = Hash.new
File.open(ARGV[0], "r") {
  | f |
  while line = f.gets
    # Creating an array by dividing the row delimiter
    dayArray = line.split("\t")
    # If the hash value is not nil, the hash value will be added 1.
    # The hash key is the start date string.
    if (aHash[dayArray[0]] != nil)
      aHash[dayArray[0]] = aHash[dayArray[0]] + 1
    else
      aHash[dayArray[0]]  = 0
    end
    # Output
    puts(startTime(dayArray[0],aHash[dayArray[0]]) + "\t" +
      endTime(dayArray[0],aHash[dayArray[0]]) + "\t" + dayArray[1]);
  end
}

tajikan-2.rb:
require 'shell'
=begin
The start date is the second field of the first argument(ARGV[0]). 
The program searches in the second argument(ARGV[1]).
It adds the number of rows of the first field to the beginning 
of the matching row of the first argument file.
=end
File.open(ARGV[0], "r") {
  | f |
  while line = f.gets
    # Creating an array by dividing the row delimiter
    dayArray = line.split(" ")
    # The program runs a search command by sed.
    aCommand = "gsed -n ''\\/" + dayArray[1].to_s + "\\/{s\\/^\\/" + dayArray[0].to_s + "\\\t\\/p}'' " + ARGV[1]
    system(aCommand)
  end
}

tajikan.sh:
#!/bin/sh
#
# Convert basic.ics to the format org.
./ical2org < basic.ics > output-1.txt

# Example of the output line:
# END:VEVEN
# *  Happy Birthday
#  <2013-04-04 THU 00:00>--<2013-04-05 FRI 00:00>
# :PROPERTIES:
#
# Extract the above two lines from each event in the output-1.txt.
cat output-1.txt | awk '/\*  / || / output-2.txt

# Convert the line feed of the asterisk line to the tab character 
# in the output-1.txt.
cat output-2.txt | awk '{if(/\*  /) printf $2 "\t"; else print $0}'  > output-3.txt

# Extract the first date and the comment from the output-3.txt
cat output-3.txt | awk '{print $2 "\t" $1}' | sed 's/ output-4.txt

# Reverse the order of the file contents of the output-4.txt. 
# Then sort by date.
awk '1 { last = NR; line[last] = $0; } END { for (i = last; i > 0; i--) { print line[i]; } }' output-4.txt | sort > output-5.txt

# Create the data for ManyTime app.
ruby tajikan.rb output-5.txt > output-6.txt

# Count the number of lines that start time overlap.
# Then, create the count.txt from the number of lines and the start time.
cut -f 1 output-6.txt | sort | uniq -c > count.txt

# Merge the output-6.txt and count.txt
ruby tajikan-2.rb count.txt output-6.txt > output-7.txt

tajikan-3.rb:
# startTime(day:Date and time string, num:order, count:the number of lines)
# Return the time string (yyyy-MMM-dd HH:00:00) by calculating the start time.
def startTime(day, num, count)
  # Decide timeLength (event length) by the count value.
  timeLength = 0
  if count == "1"
    timeLength = 24
  elsif count == "2"
    timeLength = 12
  elsif count == "3"
    timeLength = 8
  elsif count == "4"
    timeLength = 6
  elsif count == "5"
    timeLength = 4
  elsif count == "6"
    timeLength = 4
  elsif count == "7"
    timeLength = 3
  elsif count == "8"
    timeLength = 3
  else
    timeLength = 1
  end
  # Determine the (hour part) start time (hour part).
  aHour = 0
  if num == 0
    aHour = 0
  else
    aHour = num * timeLength
  end
  # String processing of the start time (hour part)
  if aHour.to_s.length == 1
    aHourStr = " 0" + aHour.to_s
  else
    aHourStr = " " + aHour.to_s
  end
  # Extract the date portion (yyyy-MM-dd) from the start time string(day). 
  dayArray = day.split(" ")
  # Return the start time string (yyyy-MM-dd HH:00:00).
  return dayArray[0] + aHourStr + ":00:00"
end

# endTime(day:Date and time string, num:order, count:the number of lines)
# Return the time string (yyyy-MMM-dd HH:59:00) by calculating the end time.
def endTime(day, num, count)
  # Decide timeLength (event length) by the count value.
  timeLength = 0
  if count == "1"
    timeLength = 24
  elsif count == "2"
    timeLength = 12
  elsif count == "3"
    timeLength = 8
  elsif count == "4"
    timeLength = 6
  elsif count == "5"
    timeLength = 4
  elsif count == "6"
    timeLength = 4
  elsif count == "7"
    timeLength = 3
  elsif count == "8"
    timeLength = 3
  else
    timeLength = 1
  end
  # Determine the (hour part) end time (hour part).
  aHour = 0
  if num == 0
    aHour = 0
  else
    aHour = num * timeLength
  end
  # Subtract 1 hour after adding the event length to the end time(hour part).
  aHour = aHour + timeLength - 1
  # String processing of the end time (hour part)
  if aHour.to_s.length == 1
    aHourStr = " 0" + aHour.to_s
  else
    aHourStr = " " + aHour.to_s
  end
  # Extract the date portion (yyyy-MM-dd) from the end time string(day). 
  dayArray = day.split(" ")
  # Return the end time string (yyyy-MM-dd HH:59:00).
  return dayArray[0] + aHourStr + ":59:00"
end

# Create ManyTime data from the date and the comment that extracted 
# from the ics data of Google calendar.
aHash = Hash.new
File.open(ARGV[0], "r") {
  | f |
  while line = f.gets
    #Creating an array by dividing the row delimiter
    dayArray = line.split("\t")
    # If the hash value is not nil, the hash value will be added 1.
    # The hash key is the start date string.
    if (aHash[dayArray[1]] != nil)
      aHash[dayArray[1]] = aHash[dayArray[1]] + 1
    else
      aHash[dayArray[1]]  = 0
    end
    # Do a line output. 
    # Specify the same argument values ​​in the startTime method and the endTime method.
    puts(startTime(dayArray[1],aHash[dayArray[1]],dayArray[0]) + "\t" +
      endTime(dayArray[1],aHash[dayArray[1]],dayArray[0]) + "\t" + dayArray[3]);
  end
}

Use of a spreadsheet

post: 2013-05-03
update: 2014-01-18

You can create ManyTime data with the spreadsheet.

a: Since the data format is a tab-delimited text, the data on Dropbox
can be treated with a general spreadsheet.
b: If yyyy-MM-dd HH-mm-ss is set up by the custom time format setting
of a general spreadsheet, it is useful for edit.
c: The usual text editor can also treat the data.

Since the above method may be difficult, I write another way.

Step1:
In the cell of general spreadsheets, for example if you type 2013-12-20
19:30:00, it is recognized as date information, the string input will
be automatically converted to 2013/12/20 19:30:00.
If you place the appropriate symbol character at the end, you can avoid
the automatic conversion. For example, if you type 2013-12-20 19:30:00@,
it is recognized as a string.

I think display of spreadsheet and is as follows.

2013-12-18 21:30:00@ 2013-12-18 21:30:00@ It is rain today.
2013-12-19 20:30:00@ 2013-12-19 21:00:00@ It is also rain today.
2013-12-20 19:30:00@ 2013-12-20 20:00:00@ Rain, but also sunny today.

Step2:
In order to get ManyTime data from a spreadsheet, export the text file.
Select and output the (text tab-delimited) text file from the spreadsheet.
It looks like this: when you open a text editor the exported data.

20131220.tsv:
2013-12-18 21:30:00@ 2013-12-18 21:30:00@ It is rain today.
2013-12-19 20:30:00@ 2013-12-19 21:00:00@ It is also rain today.
2013-12-20 19:30:00@ 2013-12-20 20:00:00@ Rain, but also sunny today.

Between the start date and the end date is a tab.
Between the end date and the comment is also a tab.

Step3:
Edit the exported data.

[For Windows]
Replace after the @ character of the end date in the text editor,
save it in (UTF-8 without BOM) as ManyTime data.
String to search: @tab
Replaced string: tab

I wrote a "tab" in the above, but it can not be displayed well.
Enter the tab character actually.
Since it may not be possible to determine the line breaks in Notepad,
use the advanced text editor, such as EmEditor.

[For Mac]
It is not same way as Windows, but I write another way.
In addition, the exported data is 20131220.tsv.
(In this case, it was created in the spreadsheet of Google Drive)
Start the terminal and go to the directory containing the data.
Convert it with sed command.

 $sed -e 's/@ / /g' 20131220.tsv > manytime-2.txt

It is part of 's/@ / /g' above, but it is 's /@tab/tab/g' actually.
If you use bash, type Ctrl + v first and type the tab key.
You can type the tab.

By the way, the command will be the following in Windows PowerShell.
 PS > cat 20131220.tsv | %{ $a = $_ -creplace "@`t","`t"; "$a" } > manytime-2.txt

Note:The character code of manytime-2.txt will be UTF-16LE with BOM.

Step4:
ManyTime data after editing looks like the following.
You can copy the contents to the existing file under the
Dropbox>Apps>manytime folder.

2013-12-18 21:30:00 2013-12-18 21:30:00 It is rain today.
2013-12-19 20:30:00 2013-12-19 21:00:00 It is also rain today.
2013-12-20 19:30:00 2013-12-20 20:00:00 Rain, but also sunny today.

Between the start date and the end date is a tab.
Between the end date and the comment is also a tab.

Data format

a: A format of line -- start time, tab, end time, tab, a comment,
and a line feed mark -- an event.
Sample:
2013-08-12 13:30:00\t2013-08-12 14:00:00\tComment1\n
2013-10-07 07:30:00\t2013-10-07 08:00:00\tComment2\n
*\t is tab and \n is line feed mark.
b: The start time of an event must be before the end time.
c: The unit of time is the minute. If the event length is 1 hour and
the start time is 0 minute, the end time is 59 minutes.
d: The form of start time and end time is yyyy-MM-dd HH:mm:ss.
It has an space character between the date and time.
The seconds portion is 00.
e: The data format is a tab-delimited text.
f: If the line feed mark is \n by Mac, it will become \r\n by Windows.
g: In ManyTime app, it is usually set to \n. It will be changed into \r\n
if the end of line for Windows in the setting screen is turned ON.
h: Events in the file is sorted in ascending order by the start time.

A solution when another file on Dropbox is made

Below, the original file is manytime-1.txt and another file is
manytime-1 (1).txt.

1: Make another file copy.
2: Make another file delete.
3: Paste the contents of another file into the original file.
4: Press the sync button.

Postscript:2013-12-15
If that does not work above:

1: Make backup of the original file.
2: Delete the original file.
3: Press the sync button.
4: Delete another file.

The procedure of editing data on Dropbox.

post:2013-05-03
update:2014-01-18

1: Make the course empty.
2: The applicable file on Dropbox is replaced or edited.
3: Press the sync button.
4: Make ManyTime app reboot.

Reboot after erasing the app from the memory, when there are the following
bad conditions.
a: The sync progress dialog is displayed for a while, and although it seems
that the data downloaded, it is not displayed on the table view.
b: Henceforth, even if the sync button is pressed, the sync progress dialog
will disappear immediately.

If there is no change after restart, try the following steps.

1: After copying the file on Dropbox, delete it from Dropbox.
2: Press the sync button.
3: Reflect the copied content to the new file on Dropbox.
4: Again, press the sync button.

The procedure which empties a course

post:2013-05-03
update:2014-01-18

1: Save the file on Dropbox after you empty it.
2: Press the sync button.

When you edit a file via the Dropbox client software in Mac or PC, you can
work in the same way as a normal file. When you do not use the Dropbox client
software, you can operate a file under the Dropbox>Apps>manytime folder
hierarchy from the Dropbox Website. Click the upload icon in the the Dropbox
Website screen, you can upload an empty file that you have prepared on Mac or
PC. (For example, the empty file is manytime-1.txt.)

By the way, there is the function in the file history management with Dropbox.
If you want to operate a file under the Dropbox>Apps>manytime folder
hierarchy from the Dropbox Web site screen, select the manytime-1.txt and
left-click while holding down the control key. The menu list will be appeared.
Select the "previous versions" from the menu list, you can get the previous
contents of the manytime-1.txt that are specified.

From ManyTime 1.0.2 version, by pressing the button "delete all events on
the course" of the setting screen and press the OK button in the confirmation
dialog box, and all events on the course you have selected can delete.
For example, if you have selected the course 1, events on course 1 only will
be deleted. In this operation, data of Dropbox is not deleted.

- | 次の10件

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。