def __init__(self): self._index = "no information" with open('last_update.pickle', 'rb') as f: self._update = pickle.load(f) with db: db.create_tables([Player])
def getData(): db.connect() db.create_tables([ Einrichtung ]) url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTbxaxdxBH9aYfQgsi7diiIJ-OBdIWo63BXlXOkv-hZiw_0H8cr2Ko0VDUAaH0TdpHOKWYz1pv9uloJ/pub?gid=0&single=true&output=csv' r = requests.get(url, allow_redirects=True) r.encoding = 'utf-8' reader = csv.DictReader(StringIO(r.text), delimiter=',') for row in reader: if len(row.get('Name')) == 0 or len(row.get('Longitude')) == 0: continue einrichtung = Einrichtung() einrichtung.id = str(uuid.uuid4()) einrichtung.name = row.get('Name') einrichtung.adresse = row.get('Adresse') einrichtung.plz = row.get('PLZ') einrichtung.ort = row.get('Ort') einrichtung.laengengrad = row.get('Longitude') einrichtung.breitengrad = row.get('Latitude') einrichtung.website = row.get('Website') einrichtung.telefon = row.get('Telefon') einrichtung.vollblutspende = (row.get('Vollblutspende') == 'ja') einrichtung.thrombozytenspende = (row.get('Thrombozytenspende') == 'ja') einrichtung.plasmaspende = (row.get('Plasmaspende') == 'ja') einrichtung.erythrozytenspende = (row.get('Erythrozyten') == 'ja') einrichtung.save(force_insert=True)
def create_tables(): db.connect(reuse_if_open=True) db.create_tables([ Season, Franchise, Player, Team, PlayerSeason, Roster, Shot, LeagueAverageShootingPct, ])
def create_tables(): ''' Attempts to initialize database table. If it exists, db returns OperationalError; continue ''' try: with db.transaction(): db.create_tables([Person]) app.logger.debug('Database tables initialized') except db_exceptions['OperationalError']: app.logger.debug('Database tables already initialized') pass except Exception as e: app.logger.error('Database error: {}'.format(str(e)))
def db_status_fill(cls): from db import db, ApodStatus db.drop_tables([ApodStatus]) db.create_tables([ApodStatus]) from datetime import datetime with db.atomic(): print() for page_name, status in reversed(STATUS.items()): print(f'***Inserting into db page {page_name}', end='\r') d = cls.page_name2date(page_name) ApodStatus.create(date=d, f_name=page_name, status=status.name, status_int=status.value) print('Done') db.commit()
async def main(): db.init(os.getenv("DB")) db.connect() db.create_tables([User, Raid, Log, PriorActivity]) async with Session() as kol: await kol.login(os.getenv("KOL_USER"), os.getenv("KOL_PASS")) cache = pickle.load(open("oaf.cache", "rb")) bot = commands.Bot("!") bot.kol = kol bot.raid_guild = int(os.getenv("DISCORD_GUILD")) bot.raid_channel = int(os.getenv("DISCORD_CHANNEL")) bot.add_cog(Verification(bot)) bot.add_cog(RaidLogs(bot, clans)) bot.add_cog(Whitelist(bot, clans)) bot.add_cog(OAF(bot, cache)) bot.add_cog(Stop(bot)) await bot.login(os.getenv("DISCORD_TOKEN")) await bot.connect() pickle.dump(cache, open("oaf.cache", "wb"))
def initdb(): models = __get_all_models() exists_models = [m for m in models if m.table_exists()] drop_tables(exists_models) db.create_tables(models) print('success create tables', models)
def create_tables(): db.create_tables([TeenEvent, YoungEvent, User, Metrics])
if __name__ == '__main__': uses_netloc.append('postgres') url = urlparse(os.environ['DATABASE_URL']) db.initialize( PostgresqlDatabase(database=url.path[1:], user=url.username, password=url.password, host=url.hostname, port=url.port)) # Connect to our database. db.connect() # Create the tabactive les. db.create_tables([User, Wish, Room]) # Enable logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) # Set up the Updater updater = Updater(TOKEN) dispatcher = updater.dispatcher # Add handlers dispatcher.add_handler(CommandHandler('start', start)) choose_lang_filter = ChooseLangFilter()
def initialize(): db.connect() db.create_tables([Category, Product])
def __initalize_runserver__(): db.connect() db.create_tables([ Entry, ]) api.run(address="0.0.0.0", debug=env == 'DEBUG')
def create_tables(): with db: db.create_tables([User])
from src.amazon_parser.parse_client import ParseClient from src.utils import load_keywords from src.models.product import ProductORM from src.crud import product_crud from config import Config from db import db if __name__ == '__main__': keyword_list = load_keywords('res/keywords.txt') db.create_tables([ProductORM]) client = ParseClient() try: client.set_location(zip_code=Config.PARSING_ZIP_CODE) for keyword in keyword_list: keyword_data = client.parse_keyword( keyword, page_per_keyword=Config.PAGE_PER_KEYWORD) product_crud.create_many(obj_in_list=keyword_data) finally: db.close()
link = product.find("a").attrs["href"] except Exception as e: continue try: input = product.find("input") brand = input.attrs["data-brand"] currency = input.attrs["data-currency"] description = input.attrs["data-description"] old_price = re.sub('[^0-9]', '', price_item.find("p", class_="price-old").find("span").text) except: brand = "" currency = "" description = "" old_price = now_price if id not in data.keys(): data[id] = {"id": id, "label": label, "now_price": now_price, "old_price": old_price, "brand": brand, "currency": currency, "description": description, "link": link} insert(shop, label, now_price, old_price, link) with open('../data/nk.json', 'w', encoding='utf8') as json_file: json.dump(data, json_file, ensure_ascii=False) return 0 if __name__ == "__main__": create_tables() delete("price") crawl_hhm() crawl_cps() crawl_nk()
from flask import Flask import routes.einrichtung import routes.wartezeit from db import db from models.einrichtung import Einrichtung from models.wartezeit import Wartezeit app = Flask(__name__) app.register_blueprint(routes.einrichtung.blueprint, url_prefix='/einrichtungen') app.register_blueprint(routes.wartezeit.blueprint, url_prefix='/wartezeit') db.connect() db.create_tables([Einrichtung, Wartezeit]) if __name__ == "__main__": app.run()
logger = logging.getLogger('insta') logger.setLevel(logging.DEBUG) fh = logging.FileHandler('insta_log.txt') fh.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) if DEBUG: formatter = logging.Formatter( '[LINE:%(lineno)d]#%(asctime)s: %(message)s') else: formatter = logging.Formatter('%(asctime)s: %(message)s') ch.setFormatter(formatter) fh.setFormatter(formatter) logger.addHandler(ch) logger.addHandler(fh) app = QApplication(sys.argv) db.connect( reuse_if_open=True ) # иначе ошибка peewee.OperationalError: Connection already opened. db.create_tables([Config, Historys]) main_window = MainWindow() main_window.show() try: app.exec_() except: logger.exception('main')
from peewee import Model, CharField, DateField from db import db class Question(Model): question_text = CharField() pub_date = DateField() class Meta: database = db if db.table_exists('question') is False: db.create_tables([Question])
import json import requests import time from db import db #Path to sqlite3 database sqlite3_db_path = "database" #Connect/Create database conn = db.create_connection(sqlite3_db_path) #Create the tables if they don't exists db.create_tables(conn) users_to_crawl = ['a17xxxxx', 'a17xxxxx', 'a17xxxxx'] #Global variables already_scanned = False user_to_scan = len(users_to_crawl) user_scanned = 0 def coordinator(): global already_scanned global user_to_scan global user_scanned for user in users_to_crawl: percent_left = user_scanned / user_to_scan * 100
def init_db(): db.create_tables([User, Session, UserSession])
from gevent import monkey; monkey.patch_all() from gevent.pool import Pool from db import db, Word, Quiz from glob import glob from peewee import chunked, fn, Expression from wiktionaryparser import WiktionaryParser parser = WiktionaryParser() db.connect() db.create_tables([Word, Quiz]) RANDOM_FACTOR = 100 WRONG_FACTOR = 10 MOST_RECENT = 4 POOL_SZ = 16 def mod(lhs, rhs): return Expression(lhs, '%', rhs) # init for fname in glob('./words/*.txt'): with open(fname, 'r') as f: for chunk in chunked([(w,) for w in f.read().splitlines()], 500): Word.insert_many(chunk, fields=[Word.name]) \ .on_conflict_ignore() \ .execute()
import logging import sys from setup import logger from PyQt5 import QtWidgets from app.main_window import MainWindow from db import db if __name__ == "__main__": logger.setLevel(logging.DEBUG) logger.info('App start') app = QtWidgets.QApplication(sys.argv) main_window = None try: db.connect() db.create_tables([]) # fixme main_window = MainWindow(app) main_window.show() sys.exit(app.exec()) except Exception as e: logger.exception(e) finally: db.close() # todo check if main_window: main_window.stop() logger.info('App close')
from db import db from models import House, Person, Point db.create_tables([House, Person, Point]) House.get_or_create(name="gryffindor") House.get_or_create(name="ravenclaw") House.get_or_create(name="hufflepuff") House.get_or_create(name="slytherin") House.get_or_create(name="unknown") houses = [i.name for i in House.select()] print houses
ext = args["image"].filename.split(".")[1] else: ext = "jpg" fname = f"{uuid.uuid4()}.{ext}" img.save(os.path.join("media", fname)) p.image = fname p.save() return _to_json(p), 201 class ProductResource(Resource): """Product REST resource.""" def get(self, product_id): p = _get_or_404(product_id) return _to_json(p) def delete(self, product_id): p = _get_or_404(product_id) p.delete_instance() return "", 204 api.add_resource(ProductsResource, "/products") api.add_resource(ProductResource, "/products/<product_id>") if __name__ == "__main__": db.create_tables([Product]) app.run(debug=True)
import os from peewee import fn import matplotlib.pyplot as plt from matplotlib.colors import Normalize from db import db, Tweet from racuni import accounts, important PATH = os.path.dirname(os.path.abspath(__file__)) db.init(os.path.join(PATH, 'db.sqlite')) db.connect() db.create_tables([Tweet]) plt.tight_layout() fig = plt.figure(figsize=(10, len(accounts.items()) * 4)) plots = len(accounts.items()) for i, (acc, val) in enumerate(accounts.items()): ax1 = fig.add_subplot(plots, 1, i + 1) ax1.set_xlabel("Tedni") ax1.set_ylabel("Tvitov/teden") data = [] prev_week = 1 for week, count in Tweet.select( fn.strftime('%W', Tweet.date).alias('week'), fn.Count(Tweet.id.distinct())).where(Tweet.user == acc).group_by(
def get_dict(self): return {'name': self.name, 'category': self.category, 'id': self.id} class Pairing(BaseModel): why = CharField() starting_with = ForeignKeyField(Recipe, related_name='pairings') ending_with = ForeignKeyField(Recipe, related_name='pairingsResults') def get_dict(self): return { 'starting_with': self.starting_with.get_dict(), 'ending_with': self.ending_with.get_dict(), 'why': self.why, 'id': self.id } class Ingredient(BaseModel): name = CharField() class IngredientUsed(BaseModel): recipe = ForeignKeyField(Recipe, related_name='ingredients') ingredient = ForeignKeyField(Ingredient, related_name='uses') amount = IntegerField() unit = CharField() db.create_tables([Recipe, Ingredient, IngredientUsed, Pairing], safe=True)
import os import ssl import urllib from urllib.request import Request from parsel import Selector from db import db, Igralec, PATH db.init(os.path.join(PATH, 'db.sqlite')) db.connect() db.drop_tables([Igralec]) db.create_tables([Igralec]) def pocohaj_url(url): context = ssl.SSLContext() context.verify_mode = ssl.CERT_OPTIONAL req = Request(url, headers={'User-Agent': 'Mozilla/5.0'}) response = urllib.request.urlopen(req, context=ssl._create_unverified_context()) return response.read() def pocohaj_igralce(stran): content = pocohaj_url(stran) num_sodniki = 0 selector = Selector(content.decode('utf-8')) # stevilo sodnikov
# mother_education = document.querySelector('#mother_edu:checked').value; # if mother_education == 'None': # mother_education=0; # elif mother_education == 'Primary': # mother_education=1; # elif mother_education == 'Matriculation': # mother_education=2; # elif mother_education == 'Secondary': # mother_education=3; # else: # mother_education=4; if request.method == 'POST': gender = request.form['father_edu'] return render_template('form.html', gender=gender) #GET method return render_template('form.html') @app.route('/logout') def logout(): session.pop('username') session.pop('id') return redirect(url_for('login')) if __name__ == '__main__': db.create_tables([User, Information, Grade], safe=True) app.secret_key = 'DG33KLLKN4525KLNKrwr23;24423*78' app.run(debug=True, port=5000)
def init_database(): models = [] for model in settings.MODELS: importlib.import_module(model[0]) models.append(getattr(sys.modules[model[0]], model[1])) db.create_tables(models, safe=True)
def create_tables(): with db: db.create_tables([User, Client, Purchase, Sale, Loan, Move, Path])