Created
June 4, 2017 17:07
-
-
Save varsharmsh/8d630f6f4ab74a31096319b5dfe66731 to your computer and use it in GitHub Desktop.
TrailDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from traildb import TrailDBConstructor, TrailDB | |
# using the trailDB provided as a part of the tutorial | |
ob = TrailDB("wikipedia-history-small") | |
def getEvents(): | |
""" | |
get all events of db | |
""" | |
for uuid, events in ob.trails(): | |
print uuid, list(events) | |
def getTitles(): | |
""" | |
get all the item values of 'title' field | |
""" | |
titles = ob.lexicon('title') | |
for title in titles: | |
print title | |
def getUUIDEvents(uuid): | |
""" | |
get all events corresponding to a UUID | |
""" | |
trailId = ob.get_trail_id(uuid) | |
events = ob.trail(trailId, rawitems=False, parsetime=True) | |
for event in events: | |
print event | |
def query(title_1,title_2,user): | |
""" | |
performs the query 'user' = user and ('title' = title_1 or 'title' = title_2) and prints events | |
""" | |
filteredTrails = ob.trails(event_filter=[[('user', user)], [ | |
('title', title_1), ('title', title_2)]]) | |
for trailid, trail in filteredTrails: | |
for event in trail: | |
print event |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment