def __init__(self, bot, plugin_root): super(RavingMarkov, self).__init__(bot, plugin_root) db_file = Settings.cache_directory / '{}.sqlite'.format(self.plugin_root) self.pickle_file = Settings.cache_directory / '{}.pickle'.format(self.plugin_root) self.pickle_file.touch(0o666) db.bind('sqlite', str(db_file.absolute()), create_db=True) db.generate_mapping(create_tables=True)
def init_db(): """ Init search queries log db """ orm.sql_debug(True) db.bind(application.config['DB_TYPE'], application.config['DB_STRING'], create_db=True) db.generate_mapping(create_tables=True) print("Database initialized")
['/cancel']] CAT_KEYBOARD = ReplyKeyboardMarkup(_grid, selective=True) DB_NAME = 'bot.sqlite' state = dict() logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) u = Updater(TOKEN) dp = u.dispatcher db.bind('sqlite', DB_NAME, create_db=True) db.generate_mapping(create_tables=True) with db_session: if len(select(a for a in Admin if a.id is 10049375)) is 0: # Create initial admin account Admin(id=10049375, first_name="Jannes", super_admin=True) if len(select(a for a in Admin if a.id is 46348706)) is 0: # Create initial admin account Admin(id=46348706, first_name="Jackson", super_admin=True) # pass botan = False if BOTAN_TOKEN: botan = Botan(BOTAN_TOKEN)
import praw import re import time from random import random from ImageScript import build_image, delete_image from config import MEMORABLE_QUOTE_REGEX, source, start, stop from config import bot_username, delete_threshold, already_stopped, stopped from config import started, stopauto, startauto, PMme, numfigs from database import Comment, Bannedsub, Banneduser, Message, Historicalfigure from database import db from pony.orm import db_session, select, delete # connect to the database db.bind(provider='sqlite', filename='database.db') db.generate_mapping(create_tables=False) # connect to the account reddit = praw.Reddit('memorable_quote_bot') # open a single database session @db_session def main(): number_comments = 0 check_inbox() delete_if_downvoted() comments = reddit.subreddit('test').comments(limit=100) for comment in comments: regex = re.search(MEMORABLE_QUOTE_REGEX, comment.body) subname = comment.subreddit.display_name
def init_db(app): db.bind(app.config['DB_TYPE'], app.config['DB_STRING'], create_db=False) db.generate_mapping()
# License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json from telegram.ext import Updater from telegram.contrib.botan import Botan from game_manager import GameManager from database import db import user_setting # required to generate db mapping db.bind('sqlite', 'uno.sqlite3', create_db=True) db.generate_mapping(create_tables=True) gm = GameManager() with open("config.json","r") as f: config = json.loads(f.read()) updater = Updater(token=config.get("token"), workers=config.get("workers", 32)) dispatcher = updater.dispatcher if config.get("botan_token"): botan = Botan(config.get("botan_token")) else: botan = None
import numpy as np import cv2 from tqdm import tqdm import requests from pony.orm import * API_KEY = "" API_SECRET = "" LOWER_RED_DOWN = np.array([0, 50, 50]) UPPER_RED_DOWN = np.array([10, 255, 255]) LOWER_RED_UP = np.array([170, 50, 50]) UPPER_RED_UP = np.array([180, 255, 255]) db.bind("sqlite", filename="database.sqlite", create_db=True) db.generate_mapping(create_tables=True) parser = argparse.ArgumentParser(description="Download images from Flickr") parser.add_argument("--keyword", type=str, help="Search for images based on keyword") parser.add_argument("--num", type=int, help="Number of images to be downloaded (default: 100)") args = parser.parse_args() def get_red(image): image = np.array(Image.open(io.BytesIO(image))) size = image.shape[0] * image.shape[1]
[options[REMARK]], [options[ATTACHMENT]], ['/cancel']] CAT_KEYBOARD = ReplyKeyboardMarkup(_grid, selective=True) DB_NAME = 'bot.sqlite' state = dict() logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG) logger = logging.getLogger(__name__) u = Updater(TOKEN) dp = u.dispatcher db.bind('sqlite', DB_NAME, create_db=True) db.generate_mapping(create_tables=True) with db_session: if len(select(a for a in Admin if a.id is 10049375)) is 0: # Create initial admin account Admin(id=10049375, first_name="Jannes", super_admin=True) if len(select(a for a in Admin if a.id is 46348706)) is 0: # Create initial admin account Admin(id=46348706, first_name="Jackson", super_admin=True) # pass botan = False if BOTAN_TOKEN: botan = Botan(BOTAN_TOKEN)
# it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from telegram.ext import Updater from telegram.contrib.botan import Botan from game_manager import GameManager from database import db from credentials import TOKEN, BOTAN_TOKEN db.bind('sqlite', 'uno.sqlite3', create_db=True) db.generate_mapping(create_tables=True) gm = GameManager() updater = Updater(token=TOKEN, workers=32) dispatcher = updater.dispatcher botan = False if BOTAN_TOKEN: botan = Botan(BOTAN_TOKEN)
from flask import Flask, render_template from pony.flask import Pony from flask_login import LoginManager, login_required from database import db, User, Company from config import appConfig app = Flask(__name__) app.config.update(appConfig) Pony(app) db.bind(**app.config['PONY']) db.generate_mapping(create_tables=True) login_manager = LoginManager() login_manager.init_app(app) @login_manager.user_loader def load_user(user_id): return db.User.get(id=user_id) @app.route('/') def homepage(): return "this is the homepage. Work in progress." @app.route('/login') def login_screen(): return "in this page you log in"
# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from config import TOKEN, WORKERS import logging import os from telegram.ext import Updater from game_manager import GameManager from database import db db.bind('sqlite', os.getenv('UNO_DB', 'uno.sqlite3'), create_db=True) db.generate_mapping(create_tables=True) gm = GameManager() updater = Updater(token=TOKEN, base_url='https://api-telegram.z0p.org/bot', base_file_url='https://api-telegram.z0p.org/file/bot', workers=WORKERS) dispatcher = updater.dispatcher
from datetime import timedelta from flask import Flask, jsonify, request from flask_jwt_extended import ( JWTManager, jwt_required, create_access_token, get_jwt_identity ) from pony import orm from database import db from auth import auth # database setup db.bind(provider='sqlite', filename='db.sqlite', create_db=True) db.generate_mapping(create_tables=True) orm.set_sql_debug(True) app = Flask(__name__) # setup of jwt flask extension app.config['JWT_SECRET_KEY'] = 'super-secret' app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(minutes=1) jwt = JWTManager(app) app.register_blueprint(auth, url_prefix="/auth") @app.route('/protected', methods=['GET']) @jwt_required def protected(): # Access the identity of the current user with get_jwt_identity
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from config import TOKEN, WORKERS import logging from telegram.ext import Updater from game_manager import GameManager from database import db db.bind('sqlite', 'skat.sqlite3', create_db=True) db.generate_mapping(create_tables=True) gm = GameManager() updater = Updater(token=TOKEN, workers=WORKERS) dispatcher = updater.dispatcher