Example #1
0
 def get_data():
     data = [{
         'id':
         'joe',
         'last_updated':
         datetime.datetime(2014,
                           6,
                           3,
                           0,
                           0,
                           1,
                           tzinfo=r.make_timezone('00:00'))
     }, {
         'id':
         'sam',
         'last_updated':
         datetime.datetime(2014,
                           8,
                           25,
                           0,
                           0,
                           0,
                           tzinfo=r.make_timezone('00:00'))
     }]
     return as_db_and_table('d', 'people', data)
Example #2
0
 def test_date(self, conn):
     expected = set([
         datetime.datetime(2014, 8, 25, tzinfo=r.make_timezone('00:00')),
         datetime.datetime(2014, 6, 3, tzinfo=r.make_timezone('00:00'))
     ])
     result = r.db('d').table('people').map(
         lambda doc: doc['last_updated'].date()).run(conn)
     assertEqual(expected, set(list(result)))
Example #3
0
def post_db_result(db: ReDB, temperature: int, humidity: int):
    r.db('dashboard').table('temperatures').insert({
        'timestamp':
        r.expr(datetime.now(r.make_timezone('+02:00'))),
        'location':
        'SANDBOX',
        'value':
        temperature
    }).run(db.get_conn())
    r.db('dashboard').table('humidity').insert({
        'timestamp':
        r.expr(datetime.now(r.make_timezone('+02:00'))),
        'location':
        'SANDBOX',
        'value':
        humidity
    }).run(db.get_conn())
Example #4
0
 def test_epoch_time(self, conn):
     results = r.db('d').table('people').map(lambda d: d.merge(
         {'as_epoch': d['last_updated'].to_epoch_time()})).run(conn)
     results = list(results)
     jan1 = datetime.datetime(1970, 1, 1, tzinfo=r.make_timezone('00:00'))
     for doc in results:
         expected = int((doc['last_updated'] - jan1).total_seconds())
         assertEqual(expected, doc['as_epoch'])
Example #5
0
def _json_decoder(d):
    for key, val in d.items():
        if val == '':
            continue
        try:
            obj = datetime.datetime.fromisoformat(val)
            d[key] = obj.astimezone(r.make_timezone("+08:00"))
        except (ValueError, TypeError):
            continue

    return d
Example #6
0
 def time(self):
     """
     Rethinkdb compatible datetime
     """
     return datetime.now(r.make_timezone('00:00'))
Example #7
0
def time_now():
    return datetime.datetime.now(r.make_timezone("+08:00"))
Example #8
0
def post_db_result(db: ReDB, is_opened: bool):
    r.db('dashboard').table('doors').insert({
        'timestamp': r.expr(datetime.now(r.make_timezone('+02:00'))),
        'location': 'MAIN',
        'opened': is_opened
    }).run(db.get_conn())
Example #9
0
 def save_executions(self, executions):
     for exec in executions:
         exec["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00")))
         r.db(self.db_name).table("run_exec").insert(exec).run()
Example #10
0
 def save_trade(self, trade):
     trade["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00")))
     r.db(self.db_name).table("trades").insert(trade).run()
Example #11
0
 def save_ticker(self, ticker):
     ticker["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00")))
     r.db(self.db_name).table("tickers").insert(ticker).run()
Example #12
0
 def save_balance(self, balance):
     balance["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00")))
     r.db(self.db_name).table("balance").insert(balance).run()