The journal Module

Moments Journal object and functions related to using journals

A journal holds a collection of Moments (and Entries, for moments with no timestamps)

class moments.journal.Journal(path=None, items=[], title=None, debug=False)[source]

Main Moments module for collecting Moment entries in one place

*2011.06.26 13:50:20 not sure that it even makes sense to base this on a standard list should use a list internally but we really don’t use any of the methods for a list to interact with a Journal object

so we could have self._entries self._tags self._dates

to store everything internally and then use custom methods for interacting with the Journal these methods should be the same whether the Journal is a local, native, instance, or if it is remote.

i.e. using journal object attributes directly in code is discouraged to ensure that local and remote journal objects work identically

associate_data()[source]

add a new property to the Journal: datas at one point this was generated automaticaly, but that slowed things down

this allows it to be generated when it is needed which so far is only when then node.directory object is looking for a default image

associate_files()[source]

add a new property to the Journal: files similar to associate_datas

but checks each entry’s data for path information if path is found just take the filename portion and associate the entry with that portion

otherwise associate each line of the entry’s data (as is)

clear()[source]

clear mind start fresh

in practice it’s probably easier to just create a new journal but reload might need this

date(date_key=None)[source]

lookup date_key in self._dates date_key should be compact stamp

dates()[source]

return a dictionary with: all dates as keys, and number of entries for each date as values

entries()[source]

return a list of entries making a function call rather than an attribute to make consistent between local and remote calls

entry(index=None)[source]

return the item at index point in list is this already defined on a list object? should be consistent

load(log_name, add_tags=[])[source]

adds a log file to the journal object currently in memory

this can be called multiple times with different filenames to merge those files/entries into the journal

>>> from journal import *
>>> j = Journal()
>>> j.load("sample_log.txt")
>>> len(j.entries)
1

return True if the file was able to be loaded False if it was not a journal/Log file

load_instance(instance_name, instance_file)[source]

load the first entry tagged instance_name from the instance file

make(data, tags=[], created=None, source='', position=0)[source]

helper for making a new entry right in a journal object this way should not need to import moments.entry.Entry elsewhere

range(start=None, end=None)[source]

if no start and end specified return the time range for the entries in the currently loaded journal

if only start return the entries in range for the accuracy of the start (e.g. 1 day)

if start and end return all entries in the journal that fall in that range

should accept a string, a datetime object, or a Timestamp object

related(key)[source]

look for tags if no matching tags see if it is a date string (get range, find entries there)

either way return tags that are related (maybe as a dictionary {‘tag’:number_of_items} ...

same as self._tags)
reload()[source]

create a new instance of a journal based on the paths we have previously loaded (self.loaded)

load everything that was previously loaded then swap out the contents old journal for the new one

remove(entry)[source]

remove associations from self._dates and self._tags then remove the entry from the journal.

remove_many(entries)[source]

take a list of entry objects, remove each one

save(filename=None, order='original', include_path=False)[source]
>>> from entry import Entry
>>> e = Entry("test entry")
>>> j.add_entry(e)
>>> j.to_file("sample_log2.txt")
>>> k = Journal()
>>> k.load("sample_log2.txt")
>>> len(k.entries)
2
save_instance(instance_file)[source]

save the currently loaded sources to an instance file

save_originals()[source]

loop through all self.sources or self.loaded and save the corresponding entries back (only if there is an actual change???)

might want to return any entries that don’t have a destination or would it be better to return an error? or not save if entries don’t have a destination

search(look_for, data=False, limit=0)[source]

scan tags for tags matching (searching) look_for if data is True, look in entry.data too

sort(order='original')[source]

Sorts the items in our Journal’s ._entries list

returns a list of the rearranged order of the entries in the journal

can specify order:

‘original’ to keep the original order that the entries were added to the journal

‘reverse’

‘chronological’ or ‘oldest to newest’ oldest entries first in the list

‘reverse-chronological’ or ‘newest to oldest’

if not all entries are wanted, see self.range()

tag(tag_key=None)[source]

lookup tag_key in self._tags

should only return a list of entries associated with that tag not a dict with the tag name server can do that but server needs to be a little different

tags(tags=[])[source]

return a dictionary with: all tags as keys, and number of entries for each tag as values

*2011.07.10 10:38:07 also could use mindstream.entries_tagged to accept a list of tags and combine all of those entries into a single list and return that

update(entry, position=None, source=None)[source]

checks if an entry already exists in the journal if other entries in with that time stamp are similar, see if they can be merged easily (i.e. only tags differ)

otherwise just add it as a separate entry no longer attempting to choose which one to keep here since journal can hold multiple entries with the same timestamp

can merge later as needed using dedicated script for that purpose

update_many(entries, source=None)[source]

loop over a list of entries to add/update each one to the journal

class moments.journal.RemoteJournal(source)[source]

This is a drop in replacement for Journal but rather than load and store the data in an internal data structure all information is retrieved from a journal_server using json

ultimately this avoids needing to reload a large journal set when working on applications to leverage information in a journal.

wraps calls to a journal_server to make the object interaction behave the same as a local Journal object

Uses the following calls for GET and POST requests:

POST: req = urllib2.urlopen(url, params) GET: req = urllib2.urlopen(url)

clear()[source]

call the load option on server

load(path='')[source]

call the load option on server

load_post(path='')[source]

call the load option on server using POST

range(start=None, end=None)[source]
save(path='')[source]

call the save option on server

save_post(path='')[source]

call the save option on server using POST

tags(item='')[source]

returns a dictionary of tags (with count) if no item specified otherwise returns a list of moments for item specified

update(entry, source=None, position=0)[source]

with a remote journal, we can’t really have an update.. it’s just a make behind the scenes so we’ll call that

moments.journal.log_action(destination, message, tags=[])[source]

this is a common need... open a journal create a new entry (now) and save the journal/log

this returns the entry created.

This Page