def test_purge_table(): table_name = 'some-other-table' db = Flata(storage=MemoryStorage) db.table(table_name) assert set([table_name]) == db.tables() db.purge_table(table_name) assert not set([table_name]) == db.tables()
def saveTemplate(path_db, item, dic): db = Flata(path_db, storage=JSONStorage) if db.get(item): tb = db.table(item) tb.purge() else: tb = db.table(item) tb.insert(dic)
def init_db(db_path, table_name): #Create db db_init = Flata(db_path, storage=JSONStorage) #Create first table db_init.table(table_name, id_field='id') database = db_init.get(table_name) return database
def test_json_readwrite(tmpdir): """ Regression test for issue #1 """ path = str(tmpdir.join('test.db.json')) # Create Flata instance db = Flata(path, storage=JSONStorage) # Create table test_table tb = db.table('test_table') item = {'data': 'data exists'} item2 = {'data': 'data not exists'} get = lambda s: tb.get(where('data') == s) tb.insert(item) assert dict(get('data exists'))['data'] == 'data exists' assert get('data not exists') is None tb.remove(where('data') == 'data exists') assert get('data exists') is None db.close()
def saveInJson(db_path, dic, mg): db = Flata(db_path, storage=JSONStorage) tb = db.table(mg) dic_mu = {} for name, mu_list in dic.items(): dic_mu[name] = listIR2dict(mu_list) tb.insert(dic_mu) return tb
def test_multiple_dbs(): db1 = Flata(storage=MemoryStorage) db2 = Flata(storage=MemoryStorage) db1.table('t').insert({'int': 1, 'char': 'a'}) db1.table('t').insert({'int': 1, 'char': 'b'}) db1.table('t').insert({'int': 1, 'value': 5.0}) db2.table('t').insert({'color': 'blue', 'animal': 'turtle'}) assert len(db1.table('t').all()) == 3 assert len(db2.table('t').all()) == 1
def json_update(path_db, mg, key, val, new_dict): db = Flata(path_db, storage=JSONStorage) table = db.table(mg) dic_re = table.all()[0] for row in dic_re['out_Report']: if row[key] == val: if new_dict: for k, v in new_dict.items(): row[k] = v table.purge() table.insert(dic_re) return table
def test_gc(tmpdir): path = str(tmpdir.join('test.db.json')) db = Flata(path) table = db.table('foo') table.insert({'something': 'else'}) table.insert({'int': 13}) assert len(table.search(where('int') == 13)) == 1 assert table.all() == [{ 'id': 1, 'something': 'else' }, { 'id': 2, 'int': 13 }] db.close()
def test_json_kwargs(tmpdir): db_file = tmpdir.join('test.db.json') db = Flata(str(db_file), sort_keys=True, indent=4, separators=(',', ': ')) # Create table test_table tb = db.table('test_table') # Write contents tb.insert({'b': 1}) # tb.insert({'a': 1}) print(db_file.read()) assert db_file.read() == '''{ "test_table": [ { "b": 1, "id": 1 } ] }''' db.close()
from flata import Flata, where, Query from flata.storages import JSONStorage import json import threading import time t = None logger = logging.getLogger('discord') logger.setLevel(logging.DEBUG) handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w') handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) logger.addHandler(handler) db = Flata('db.json', storage=JSONStorage) db.table('stats') tb = db.get('stats') # Start if script client = Bot(description="Discord BOT that collects info about people being in voice channel", command_prefix="$", pm_help = False) @client.event async def on_ready(): print('Logged in as '+client.user.name+' (ID:'+client.user.id+') | Connected to '+str(len(client.servers))+' servers | Connected to '+str(len(set(client.get_all_members())))+' users') print('--------') print('Current Discord.py Version: {} | Current Python Version: {}'.format(discord.__version__, platform.python_version())) print('--------') print('Use this link to invite {}:'.format(client.user.name)) print('https://discordapp.com/oauth2/authorize?client_id={}&scope=bot&permissions=8'.format(client.user.id)) print('--------') print('You are running VoiceStatBot v0.1') #Do not change this. This will really help us support you, if you need support.
metadata_file = 'metadata.json' data_file = 'public/data.js' database_file = 'database.json' DATETIME_FORMAT = '%Y.%m.%dT%H:%M:%S%z' # FlataDB from flata import Flata, Query, where from flata.storages import JSONStorage db = Flata(database_file, storage=JSONStorage) q = Query() # Init metadata_uid = 1 metadataTable = db.table('metadata', id_field='uid') recordsTable = db.table('records', id_field='uid') def get_db(): return db # So we don't need to write strings category = 'category' sub_category = 'sub_category' producer = 'producer' product_type = 'product_type' product = 'product' kosher_type = 'kosher_type' kosher_stamp = 'kosher_stamp'
def setup(table_name: str, id_field: str): """Creates the specified table if not yet exists in the db.json and returns its reference either way""" db = Flata('db.json', storage=JSONStorage) db.table(table_name, id_field=id_field) return db.get(table_name)
def db(): db_ = Flata(storage=MemoryStorage) db_.purge_tables() db_.table('t').insert_multiple({'int': 1, 'char': c} for c in 'abc') return db_
## Made by Samuel Pratt ## Victoria, BC, Canada import os import json from flask_cors import CORS from flask import Flask, jsonify, render_template from flata import Flata, where from flata.storages import JSONStorage from apscheduler.scheduler import Scheduler from scraper import get_data # Initialize db db = Flata('./db.json', storage=JSONStorage) db.table('table1') db.get('table1') app = Flask(__name__) CORS(app) # Scheduler object sched = Scheduler(daemon=True) sched.start() # Valid departure terminals departure_terminals = [ "tsawwassen", "swartz-bay", "nanaimo-(duke-pt)", "nanaimo-(dep.bay)", "horseshoe-bay", "langdale" ] # Valid destination terminals
import os from flata import Flata, Query from flata.storages import JSONStorage from flask import Flask, request, render_template, url_for, redirect from random import choice, randint from string import ascii_letters app_storage_file = os.getenv('APP_STORAGE_FILE', '/tmp/db.json') app_tiny_baseurl = os.getenv('APP_BASEURL', 'localhost:5000/t') app_protocol = os.getenv('APP_PROTOCOL', 'https') app_name = os.getenv('APP_NAME', 'My') body_text = app_name + ' URL Shortener' db_init = Flata(app_storage_file, storage=JSONStorage) db_init.table('collection1', id_field = 'counter_id') db = db_init.get('collection1') q = Query() tiny_appurl = app_protocol + '://' + app_tiny_baseurl + '/t' def generate_tiny(): tiny_key = ''.join(choice(ascii_letters) + str(randint(0,9)) for x in range(randint(8, 8))).lower() return tiny_key def put_url(destination_url): tiny_id = generate_tiny() tiny_url = '{}/{}'.format(tiny_appurl, tiny_id) db.insert({'id': tiny_id, 'name': tiny_url, 'value': destination_url}) return tiny_url def get_url(tiny_url):
#!/usr/bin/env pipenv run python import sys from pyfancy.pyfancy import pyfancy from flata import Flata, where from flata.storages import JSONStorage db = Flata('db.json', storage=JSONStorage) db.table('todos') args = sys.argv # usage represents the help guide def usage(): usageText = """ todo helps you manage your todo tasks usage: todo <command> commands can be: new: used to create a new todo get: used to retrieve your todos complete: used to mark a todo as complete help: used to print the usage guide """ print(usageText)