Activities/Turtle Art/Using Turtle Art Sensors: Difference between revisions
| Line 217: | Line 217: | ||
===Saving logged data to the Journal=== | ===Saving logged data to the Journal=== | ||
The following code [[File:Saveheaptojournal.doc]] in the Python Code Block will save the heap as a text file named 'heap' in the Journal. The file 'heap' can then be opened with Write. | The following code [[File:Saveheaptojournal.doc]] in the Python Code Block will save the heap as a text file named 'heap' in the Journal. The file 'heap' can then be opened with Write or Edit. | ||
[[File:Heap to journal.jpg]] | [[File:Heap to journal.jpg]] | ||
def myblock(lc, x): | |||
from tautils import data_to_string, get_path, data_to_file | |||
from sugar.activity import activity | |||
from gettext import gettext as _ | |||
import os.path | |||
from sugar.datastore import datastore | |||
from sugar import profile | |||
# Save the heap to a file (JSON-encoded) | |||
heap_file = os.path.join(get_path(activity, 'instance'), 'heap.txt') | |||
data_to_file(lc.heap, heap_file) | |||
# Create a datastore object | |||
dsobject = datastore.create() | |||
# Write any metadata (specifically set the title of the file | |||
# and specify that this is a plain text file). | |||
dsobject.metadata['title'] = _('heap') | |||
dsobject.metadata['icon-color'] = profile.get_color().to_string() | |||
dsobject.metadata['mime_type'] = 'text/plain' | |||
dsobject.set_file_path(heap_file) | |||
datastore.write(dsobject) | |||
dsobject.destroy() | |||
return | |||
==Logging at regular intervals== | ==Logging at regular intervals== | ||