Skip to content

Instantly share code, notes, and snippets.

@dirkk0

dirkk0/add.py

Last active Oct 24, 2015
Embed
What would you like to do?
Erratic bevaviour in tinydb
from tinydb import TinyDB, where
db = TinyDB('stack.json')
print db.insert({'type': 'job', 'cmd': 'tweet', 'txt': 'Heya!', 'prio': 1})
import time
from tinydb import TinyDB, where
while True:
stack = TinyDB('stack.json')
el = stack.get(where('prio') == 1)
if el:
print 'id is ' + str(el.eid)
process = TinyDB('process.json')
print process.insert({'cmd': el['cmd'], 'txt': el['txt'], 'time': time.time() + 3})
# process.close()
stack.remove(eids = [el.eid])
# stack.close()
time.sleep(1)
import time
from tinydb import TinyDB, where
process = TinyDB('process.json')
# processed = TinyDB('processed.json')
while True:
el = process.get(where('time') <= time.time())
# db.remove(eids=[1, 2])
print time.time()
if el:
print el
print('processed ' + el['txt'])
print el.eid
# processed.insert(el)
process.remove(eids = [el.eid])
time.sleep(2)
import time
from tinydb import TinyDB, where
stack = TinyDB('stack.json')
process = TinyDB('process.json')
while True:
el = stack.get(where('prio') == 1)
if el:
print 'id is ' + str(el.eid)
print process.insert({'cmd': el['cmd'], 'txt': el['txt'], 'time': time.time() + 3})
# process.close()
stack.remove(eids = [el.eid])
# stack.close()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.