Esempio n. 1
0
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)
Esempio n. 2
0
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
Esempio n. 3
0
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.
	print('Created by Jengas')
Esempio n. 4
0
 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)
Esempio n. 5
0
## 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):