def main(): # Get requests.session session = load_session_or_login() # Get database session for add and commit sql_item db_engine = db_connect() create_engine(db_engine) Session = sessionmaker(bind=db_engine) db_session = Session() # Run actual spider code non-blockingly # Generate ebooks and push to subscribers' kindle return True
def __init__(self, path, db=None, engine=None): self.path = path self.working = None if not os.path.exists(path): os.makedirs(path) self.db = db or 'sqlite:///%s/sqlite3.db' % path self.settings_write({'DB': self.db}) else: self.settings_read() self.db = db or self.settings['DB'] self.engine = engine or create_engine(self.db, echo=False) self.session = self.engine.create_session()
def __init__(self, **kwargs): self.backup = kwargs.get('backup', True) self.normalize = kwargs.get('normalize', True) self.dbpath = kwargs.get('dbpath') if not self.dbpath: self.dbpath = DEFAULT_DB_FILE logger.debug(_("Using database file '%s'") % self.dbpath) engine = kwargs.get('engine') if not engine: engine = create_engine('sqlite:///%s' % self.dbpath) metadata.bind = engine session.configure(bind=engine) self._photoset = None self._db_version = None
from flask import Flask, flash, redirect, render_template, request, session, abort import os from sqlalchemy.orm import sessionmaker from models import User, Post, create_engine, Category from datetime import datetime from flask_frozen import Freezer engine = create_engine('sqlite:///dbMyBlog.db', echo=True) freezer = Freezer(app) app = Flask(__name__, static_url_path='') @app.route('/') def home(): return render_template('index.html') @app.route('/static/<path:path>') def send_static(path): return send_from_directory('static', path) @app.route('/portfolio') def portfolio(): return render_template('portfolio.html') @app.route('/hire') def hire(): return render_template('hire.html') @app.route('/login', methods=['GET','POST'])
def _init_database(db_path): engine = models.create_engine(db_path) models.create_tables(engine) session = models.create_session(engine) return session
from flask import Flask, request, render_template, redirect, url_for, jsonify from models import User, Movie, engine, session, create_engine import webbrowser app = Flask(__name__) engine = create_engine('postgresql://*****:*****@localhost/movie_db') db_conn = engine.connect() # for the web # create a new row in the movie table @app.route('/main/createnewmovie', methods=['GET', 'POST']) def create_movie(): if request.method == 'POST': # check if the user already exists check_existing_user = session.query( User.id).filter(User.name == request.form['actor_name']).scalar() check_movie_exists = session.query(Movie).filter( Movie.movie_title == request.form['movie-name']).scalar() if check_existing_user and check_movie_exists: return "Movie and the role player already exists! Thanks for participation!" elif check_existing_user: # add new movie add_newmovie = Movie( movieimdbid=request.form['movie-imdb'], movie_title=request.form['movie-name'], movie_rating=request.form['ratings'], movie_releaseyear=request.form['release-year'], movie_votes=request.form['votes']) session.add(add_newmovie)
url = "https://web3api.io/api/v2/market/tokens/prices/" + tokenAddress + '/latest' headers = {"x-api-key": secrets.api_key} response = requests.get(url, headers=headers) query = json.loads(response.content) payload = query['payload'] tkADD = payload[0]['address'] tkNAME = payload[0]['name'] tkSYMBOL = payload[0]['symbol'] tkPRICE = payload[0]['priceUSD'] print(tkADD, tkPRICE, tkNAME, tkSYMBOL) db_string = 'postgresql://*****:*****@localhost/practiceDataDB' db = models.create_engine(db_string, echo=False) base = models.declarative_base() base.metadata.create_all(db) db_Session = sessionmaker(db) db_session = db_Session() result = Price(address=tkADD, name=tkNAME, symbol=tkSYMBOL, price=tkPRICE) db_session.add(result) db_session.commit() print('entry added') db_session.close() if choice2.lower() == 'historical': # https://docs.amberdata.io/reference#get-historical-token-price for questions on querystring
# -*- coding: utf8 -*- import os import unittest from fixture import DataSet, DataTestCase, SQLAlchemyFixture from models import create_engine, metadata, session, Photo, Tag, Meta from controller import FSpotController # Setup temporary database DB_PATH = ':memory:' engine = create_engine('sqlite:///' + DB_PATH) metadata.bind = engine session.configure(bind=engine) metadata.create_all() BASE_PATH=os.path.abspath(os.path.dirname(__file__)) """ Fixtures """ dbfixture = SQLAlchemyFixture(env={'PhotoData': Photo, 'TagData': Tag, 'MetaData': Meta}, engine=metadata.bind) class PhotoData(DataSet): class on_disk: base_uri = os.path.join('file://', BASE_PATH, 'tests') filename = 'bee.jpg'
from sqlalchemy.exc import IntegrityError from sqlalchemy.engine.url import URL import config import pandas as pd import binance_d from binance_d.model.constant import CandlestickInterval from binance_d.requestclient import FuncResponse import binance_f from binance_f.model.constant import CandlestickInterval from binance_f.requestclient import FuncResponse import datetime import time import click import constants engine = create_engine(URL(**config.Config.DATABASE)) create_table(engine) Base.metadata.bind = engine DBSession = sessionmaker() DBSession.bind = engine session = DBSession() @click.group() def cli(): """ A cli helper to update binance data for channel calculations Some useful information on times: BTCUSDT: M Futures contract start date: 2020-8-11 """