def get_auctions_db(db_folder): db_file = os.path.join(db_folder, "auctions.txdb") return TinyDB(db_file, storage=CachingMiddleware(JSONStorage))
""" Creates a tinydb database with all the data of each script traded on nse exchange on that particular day It lets you create scripts history data should be run on daily basis after market close Later this data will be used in candle stick patterns """ from nsetools import Nse from tinydb import TinyDB, Query import json from datetime import datetime print "Script started at: " + str(datetime.now()) try: nse = Nse() stocks_db = TinyDB("all_stocks.json") all_symbols = json.loads(nse.get_stock_codes(as_json=True)) current_date = datetime.now() for each_symbol in all_symbols.keys(): try: current_data = json.loads( nse.get_quote(str(each_symbol), as_json=True)) final_data = { "high": current_data["dayHigh"], "previousClose": current_data["previousClose"], "open": current_data["open"], "close": current_data["closePrice"], "symbol": current_data["symbol"], "low": current_data["dayLow"], "date": str(current_date) }
from tinydb import TinyDB, Query db = TinyDB('db.json') x = db.search(Query().Age == 21) print(x)
#------------------------------------------------------------------------------- #------------------------------------KIVY--------------------------------------- #------------------------------------------------------------------------------- global FILES FILES = [] #global IMG_COUNT IMG_COUNT = 0 CURRENT = '' def resource_path(relative_path): base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) db = TinyDB('./db.json') class CustomDropDown(DropDown): pass class CustomButton(Button): pass class Logo(BoxLayout): pass class VidScreen(Screen): def stop_video(self): self.vid.state = 'stop'
def __init__(self, config_path="config.json", ws_server="localhost", ws_port=4444): # Setting up logging first and foremost self.log = get_logger("midi_to_obs") # Internal service variables self._action_buffer = [] self._action_counter = 2 self._portobjects = [] #load tinydb configuration database self.log.debug("Trying to load config file from %s" % config_path) tiny_database = TinyDB(config_path, indent=4) tiny_db = tiny_database.table("keys", cache_size=20) tiny_devdb = tiny_database.table("devices", cache_size=20) #get all mappings and devices self._mappings = tiny_db.all() self._devices = tiny_devdb.all() #open dbj datebase for mapping and clear self.mappingdb = dbj("temp-mappingdb.json") self.mappingdb.clear() #convert database to dbj in-memory for _mapping in self._mappings: self.mappingdb.insert(_mapping) self.log.debug("Mapping database: `%s`" % str(self.mappingdb.getall())) if len(self.mappingdb.getall()) < 1: self.log.critical("Could not cache device mappings") # ENOENT (No such file or directory) exit(2) self.log.debug("Successfully imported mapping database") result = tiny_devdb.all() if not result: self.log.critical("Config file %s doesn't exist or is damaged" % config_path) # ENOENT (No such file or directory) exit(2) self.log.info("Successfully parsed config file") self.log.debug("Retrieved MIDI port name(s) `%s`" % result) #create new class with handler and open from there, just create new instances for device in result: self._portobjects.append( (DeviceHandler(device, device.doc_id), device.doc_id)) self.log.info("Successfully initialized midi port(s)") del result # close tinydb tiny_database.close() # setting up a Websocket client self.log.debug("Attempting to connect to OBS using websocket protocol") self.obs_socket = WebSocketApp("ws://%s:%d" % (ws_server, ws_port)) self.obs_socket.on_message = lambda ws, message: self.handle_obs_message( ws, message) self.obs_socket.on_error = lambda ws, error: self.handle_obs_error( ws, error) self.obs_socket.on_close = lambda ws: self.handle_obs_close(ws) self.obs_socket.on_open = lambda ws: self.handle_obs_open(ws)
from tinydb import TinyDB, Query import re db = TinyDB('dbScratch.json') prefix = { 'p': 10.0**-12, 'n': 10.0**-9, 'u': 10.0**-6, 'm': 10.0**-3, 'k': 10.0**3 } foo = {} foo['type'] = 'mosfet' foo['part_number'] = 'EPC2034' bar = {} bar['type'] = 'mosfet' bar['part_number'] = 'EPC2032' #b.insert(foo) #db.insert(bar) txtstr = "0.26nC @ 10V" FET = Query() for results in db.search(FET.Vds < 200): print results['partNumber'] print results['status'] print results['Vds']
async def start(self): logger.info("%s opening DB %s", self.name, self.conf['db_filename']) self.db = TinyDB(self.conf['db_filename'], sort_keys=True, indent=4, separators=(',', ': '), storage=CachingMiddleware(JSONStorage))
from tinydb import TinyDB, Query from config_start import path_programm import os path_database = os.path.join(path_programm, "_database", "_database.json") _database = TinyDB(path_database) # table_lama = _database.table('table_lama_1') # table_lama = _database.table('table_lama_2') # table_lama = _database.table('table_cria') tables = ['table_lama_1', 'table_lama_2', 'table_cria'] for table_lama in tables: _database.table(table_lama).update({'gruppe': False}) print('done')
paginate_help, ) from main_startup.config_var import Config from main_startup.helper_func.basic_helpers import ( edit_or_reply, get_text, humanbytes, cb_progress, ) import re import requests import wget from bs4 import BeautifulSoup db_m = TinyDB("./main_startup/Cache/secret.json") db_s = TinyDB("./main_startup/Cache/not4u.json") @bot.on_inline_query() @inline_wrapper async def owo(client, inline_query): string_given = inline_query.query.lower() if "modapk" in inline_query.query.lower(): if not " " in inline_query.query.lower(): return string_given = inline_query.query.lower() sgname = string_given.split(" ", maxsplit=1)[1] print(sgname) PabloEscobar = ( f"https://an1.com/tags/MOD/?story={sgname}&do=search&subaction=search"
def __init__(self, bot): self.bot = bot self.db = TinyDB('reminders.json') self.lock = threading.Lock() self.remind.start() self.untrigger.start()
def onJoin(self, details): middleware = CachingMiddleware(JSONStorage) db = TinyDB(os.path.join(os.path.dirname(__file__),'data','user_data.json'), storage=middleware) auth_config = {'salt': 'fruitfly', 'iterations':5000,'keylen':32} session_user_map = {} chars = string.ascii_letters + string.digits + "@!^_()%[]{}" pwlen = 12 self.log.info('auth started') def auth(realm, authid, details): q = Query() results = db.search(q.username == authid) if not results: raise ApplicationError("User does not exist", "could not authenticate session - no such user {}".format(authid)) auth_details = results[0]['auth_details'] auth_details['authid'] = results[0]['user_details']['fname'] if results[0]['user_details']['lname']: auth_details['authid'] += (" " + results[0]['user_details']['lname']) if not auth_details['authid']: del auth_details['authid'] session_user_map[details['session']]={'username': authid, 'details':details} return auth_details yield self.register(auth, six.u('ffbo.auth_server.auth')) self.log.info("registered ffbo.auth_server.auth") def get_user(session): if session in session_user_map: return session_user_map[session] return {} yield self.register(get_user, six.u('ffbo.auth_server.get_user')) self.log.info("registered ffbo.auth_server.get_user") def generate_password(): rnd = random.SystemRandom() return "".join([rnd.choice(chars) for _ in range(pwlen)]) def register_user(user_details): if user_exists(user_details['username']): return {"error": "User already exists. Please try again"} try: username = user_details['username'] pw = generate_password() salted_pw = ath.derive_key(pw, auth_config['salt'], auth_config['iterations'], auth_config['keylen']) db_rec = {'username':username, 'user_details': user_details, 'auth_details': copy.deepcopy(auth_config)} db_rec['auth_details']['secret'] = salted_pw db_rec['auth_details']['role'] = u'user' del db_rec['user_details']['username'] #print "Registered user ", db_rec db.insert(db_rec) except Exception as e: print(e) return {"error": "Unexpected error occured. Please try again"} print("User added to database") send_email(user_details, pw, username) return {"success": "Successfuly registered. Please check your email for your password."} yield self.register(register_user, six.u('ffbo.auth_server.register_user')) self.log.info("registered ffbo.auth_server.register_user") def send_email(user_details, pw, username): title = "Thank you for registering at NeuroNLP" text = "Hi {fname},\n\n" text += "Here are your login details for NeuroNLP.\n\n" text += "Username: {username}\nPassword: {pw}\n\n" text += "If you have any suggestions or feedback, we would love to hear it!" text += " Please use the feedback button on the top left button of the website to write to us.\n\n" text += "Thank you,\nFruit Fly Brain Observatory" text = text.format(username=username,fname=user_details['fname'], pw=pw) msg = MIMEText(text) msg['Subject'] = title msg['From'] = 'NeuroNLP(Fruit Fly Brain Observatory) <*****@*****.**>' msg['To'] = user_details['email'] sender = msg['From'] try: s = smtplib.SMTP(host='localhost', port=465) except Exception as e: print(e) print("Failed to start SMTP server on localhost") try: # Use a valid smtp server, otherwise the email notification won't be sent out s.sendmail('*****@*****.**', [user_details['email']], msg.as_string()) middleware.flush() print("Email sent to " + user_details['email'] + " for " + user_details['fname'] + ' ' + user_details['lname']) except Exception as e: print(e) print("Failed to send out email") def user_exists(username): q = Query() results = db.search(q.username == username) if not results: return False return True yield self.register(user_exists, six.u('ffbo.auth_server.user_exists')) self.log.info("registered ffbo.auth_server.user_exists") def get_auth_config(): return auth_config yield self.register(get_auth_config, six.u('ffbo.auth_server.get_auth_config')) self.log.info("registered ffbo.auth_server.get_auth_config") def change_password(): pass def send_new_password(): pass
import favicon from bs4 import BeautifulSoup as bs import requests from typer import Option from typing import Optional import webbrowser from fuzzywuzzy import fuzz, process import jinja2 from tabulate import tabulate app = typer.Typer() home = expanduser("~") database_file = os.path.join(home, '.database_cli.json') db = TinyDB(database_file) query = Query() find_list = Query() TEMPLATE = """<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" /> <style> body { font-family: sans-serif; } code, pre { font-family: monospace; } h1 code,
#!/usr/bin/env python3 from decouple import config from multiprocessing import Pool import os import shutil import subprocess from tinydb import TinyDB, Query # Data OUTPUT_DIR = "memes" subprocess.run(["mkdir", "-p", OUTPUT_DIR]) # Database PATH = config("DATABASE_PATH") db = TinyDB(PATH) data = db.all() # MEME_LOOKUP_DB = config("MEME_LOOKUP_DB") # meme_db = TinyDB(MEME_LOOKUP_DB) # meme_db.purge() meme_urls = map(lambda submission: (submission["id"], submission["media"]), data) # Config NUM_WORKERS = 8 def download(post_id, post_url, output_dir=OUTPUT_DIR): """Given an image url, save it to output_dir"""
import sys import getopt from tinydb import TinyDB, Query import time import random import string Colours = ["red", "orange", "yellow", "green", "blue", "purple", "pink", "brown"] Objects = [] DB = TinyDB('Database.json') UserTB = DB.table("UserID") GameTB = DB.table("GamesPins") TurnTB = DB.table("Turns") query = Query() def Debug(*input): if "-d" in sys.argv[1:] or "--degug" in sys.argv[1:]: if len(input) > 0: print("# DEBUG: ",*input) return True return False class GameEngine(): def __init__(self, GamePin=None): self.GamePin = GamePin self.WS = [] self.req = query.GamePin == self.GamePin
from flask import Flask, url_for import os from flask_bootstrap import Bootstrap from tinydb import TinyDB import re from time import strptime, strftime recipyGui = Flask(__name__) recipyGui.config['SECRET_KEY'] = 'geheim' Bootstrap(recipyGui) # TODO: Fix after recipy-gui is merged with recipy db = TinyDB('../Recipy/recipyDB.json') # Function to easily find your assets # In your template use <link rel=stylesheet href="{{ static('filename') }}"> recipyGui.jinja_env.globals['static'] = ( lambda filename: url_for('static', filename=filename)) def register_blueprints(app): # Prevents circular imports from recipyGui.views import routes recipyGui.register_blueprint(routes) register_blueprints(recipyGui) # Custom filters
from fastapi import FastAPI from tinydb import TinyDB, Query import uuid app = FastAPI() user_accounts = TinyDB('user_accounts.json') selector = Query() # Authentication endpoints @app.post("/auth/register") def auth_register( email, password, ): if not email or not password: return {"msg": "No has enviado los datos correctos"} found = user_accounts.search(selector.email == str(email)) if not found: account = [] user_id = str(uuid.uuid4()) user_accounts.insert({ "user_id": user_id[:5], "email": email, "password": password, "accounts": account }) return {"msg": "New user"}
def draw_all_boxes(): db = TinyDB(db_path) parkings = db.all() for parking in parkings: img_url = 'frame.png' draw_boxes_for_image(img_url)
jsonschema.validate(data, POPULATE_DB_SCHEMA) data["video_date"] = validate_date(data["video_date"]) data["tags"] = parse_tags(data["tags"]) if data["video_title"] is None: data[ "video_title"] = f"{data['video_date'].replace('-','')}_{data['hero']}" if data["type"] is None: data["type"] = "highlight" if url_check(data["video_url"]) is True: raise ValueError(f"{data['video_url']} already tracked") if DB is not None: DB.insert(data) else: raise ValueError("No database found") return '', 200 except ValueError as e: return f"Error: {e!s}", 400 except jsonschema.ValidationError as e: return f"Invalid JSON: {e!s}", 400 except Exception as e: return str(e), 500 def shutdown(*_): if DB is not None: DB.close() if __name__ == "__main__": DB = TinyDB("video-metadata.json") app.run(host="127.0.0.1", debug=True)
Tanaka,Taro,7,56,M,Vegetarian food only,"5-2-1 Ginza, Chou-ku Tokyo 170-3293" Tanaka,WanLee,7,54,M,Vegetarian food only,"5-2-1 Ginza, Chou-ku Tokyo 170-3293"''' guests = [] for line in data.split('\n'): profile = line.split(',') last, first, cabin, age, gender, notes, *_ = profile address = ''.join(profile[6:]).replace('"', '') hashed = guest.hash_psw("123456") bookings = ["No Activity" for _ in range(14)] meals = ["Normal meal" for _ in range(14)] guests.append({"username": first[0] + last + str(cabin), "hash": hashed, "last": last, "first": first, "cabin": int(cabin), "age": int(age), "gender": gender, "notes": notes, "address": address, "activities": bookings, "meals": meals}) db = TinyDB("guest.json", indent=2) db.purge_tables() db.insert(date) table_profile = db.table("profiles") for guest in guests: table_profile.insert(guest)
def get_table(table): """Opens a new database connection""" g.tinydb = TinyDB(current_app.config['DATABASE']) person_table = g.tinydb.table(table) return person_table
def test_upsert(tmpdir): """Test upsert.""" db = TinyDB(tmpdir.join('db.json')) # Create Strategy. strat_id = 0 hypers = {'alpha': .001, 'n_restart': 100} seed = 252 strategy = spond.databases.Strategy( strat_id, hypers=hypers, seed=seed ) # Create Task. task_id = 0 rerun = 0 task = spond.databases.Task( task_id, rerun=rerun ) # Create results. results = spond.databases.Results( { 'alignment_score': .1, 'mapping_accuracy': .5 } ) # Insert in database. tsr = {**+task, **+strategy, **+results} db.upsert( tsr, (Query().task == task) & (Query().strategy == strategy) ) # Test insert upsert. s = db.search( (Query().task == task) & (Query().strategy == strategy) ) assert len(s) == 1 assert s[0] == tsr # Update result of record. results = spond.databases.Results( { 'alignment_score': .8, 'mapping_accuracy': .9 } ) tsr = {**+task, **+strategy, **+results} db.upsert( tsr, (Query().task == task) & (Query().strategy == strategy) ) # Test update upsert. s = db.search( (Query().task == task) & (Query().strategy == strategy) ) assert len(s) == 1 assert s[0]['results'] == results
from tinydb import TinyDB, Query def usernameTaking(db, ask): a = input("What is your username?") if len(db.search(ask.username == a)) > 0: print("Username already taken") usernameTaking() else: db.insert({'username': a, 'Name': '', 'Address': ''}) print("Username set") return a ask = Query() db = TinyDB('actual.json') user = usernameTaking(db, ask) Name = input("What is your name?") Address = input("What is your Address?") db.update({'Address': Address, 'Name': Name}, ask.username == user) print("Done")
#!/usr/bin/env python3 import ipfsClient import base64 as b64 from tinydb import TinyDB,Query from time import sleep from datetime import datetime as dt db = TinyDB("lista.json") query = Query() apiServer = "/ip4/127.0.0.1/tcp/5001/http" Client = ipfsClient.ipfsPubSub(apiServer) while True: with Client.sub("RFIDID", True) as A, Client.sub("RFIDName", True) as B: for id in A: for val in id.values(): if not isinstance(val, list): idToDB = b64decode(val) break for name in B: for val in name.values(): if not isinstance(val, list): nameToDB = b64decode(val) break if id != None and name != None: atte = dt.timestamp(dt.now()) db.insert({'ID': str(idToDB), 'Nombre': str(nameToDB), 'Fecha': str(atte)}) db.search(User.Nombre == str(nameToDB))
def get_user_history(user): db = TinyDB(config.history_path + user + '.json') data = db.all() db.close() return data
def __init__(self, database_file): serialization = SerializationMiddleware() serialization.register_serializer(DateTimeSerializer(), 'ArrowDateTime') self.db = TinyDB(database_file, storage=serialization)
import sys,os import discord import asyncio from instascraper import get_post, get_author from setup import get_env from tinydb import TinyDB, Query # fetch env: USER_ID is authorized user (usually bot owner) DISCORD_TOKEN, USER_ID = get_env() # init db sys.path.append(os.path.realpath('..')) listDb = TinyDB('db/urls.json') blockDb = TinyDB('db/blocked.json') # both only store a string, url and author respectively. UrlQ = Query() BlockedAuthor = Query() # Init Discord client client = discord.Client() # globals latest_url = 'None' QUERYING_SPEED = 5 TIMEOUT = 5 # formats post
'''Split stored observations into location pools''' from tinydb import TinyDB observation_db = TinyDB('data/observations.json') with open('data/split_loc.json', 'w'): pass split_db = TinyDB('data/split_loc.json') reads = observation_db.table('reads') observations = reads.all() print('start converting db') for item in observations: print(item) location_id = 1 location = item['location'].lower() if 'back left pillar' in location: if 'outside red wing' in location: location_id = 7 else: location_id = 5 elif 'back right pillar' in location: location_id = 5 elif 'outside back pillar' in location: location_id = 8 elif 'front right pillar' in location:
def test_0(): from tinydb import TinyDB db = TinyDB('simple_db.json') db.insert({'int': 1, 'char': 'a'}) db.insert({'int': 2, 'char': 'b'}) db.close()
from escpos.printer import Serial from twitchio.ext import commands from tinydb import TinyDB, Query from random import randint from threading import Thread import discord from discord.ext import commands as discord_commands import asyncio import time import json db = TinyDB('twitch_users.json') users = db.table('users') admins = db.table('admins') oauthkey = db.table('oauthkey') discord_db = TinyDB('discord_events.json') color_events = TinyDB('color_events') class TwitchBot(Thread): def __init__(self): Thread.__init__(self) def run(self): simple_printer = Serial(devfile='/dev/cu.BlueToothPrinter-SPPsla', baudrate=9600, bytesize=8, parity='N', stopbits=1,
def circuit_db(self): os.makedirs(config.CDB_FILE_PATH, exist_ok=True) return TinyDB(os.path.join(config.CDB_FILE_PATH, config.CDB_FILE_NAME))