Ejemplo n.º 1
0
    def wrapper(ctx, **kwargs):
        """Gather required data and pass them to a CLI function."""
        db = DatabaseConnection.connect()
        c = HistoricalCollector(db, ctx.obj['coin'], ctx.obj['start_date'],
                                ctx.obj['end_date'])
        data, error = c.get_data()

        if error is not None:
            sys.exit(error_message.safe_substitute({'error': error}))

        if len(data) == 0:
            sys.exit(no_data_message.safe_substitute(
                {'start': to_string(ctx.obj['start_date']),
                 'end': to_string(ctx.obj['end_date']),
                 'coin': ctx.obj['coin']}))

        h = HistoricalFunctions(data, ctx.obj['ohlc'])

        cli_function(h, ctx, data, **kwargs)
Ejemplo n.º 2
0
from db_connection import DatabaseConnection

connection = DatabaseConnection.create()
connection.connect()

other_method_connection = DatabaseConnection.create()

if other_method_connection == connection:
    print("They are the same")
Ejemplo n.º 3
0
from peewee import *

from db_connection import DatabaseConnection

db = DatabaseConnection.connect()


class BaseModel(Model):
    """Base model class that specifies the database."""
    class Meta:
        database = db

    @classmethod
    def get_data_in_range(cls, column, lower, upper, condition=None):
        """Return data within the given range."""
        attr = getattr(cls, column)
        if condition:
            cond_attr = getattr(cls, condition['column'])
            return cls.select().where((cond_attr == condition['value']) & (
                attr.between(lower, upper))).order_by(attr)
        return cls.select().where(attr.between(lower, upper)).order_by(attr)


class Cryptocurrency(BaseModel):
    """Represent a single cryptocurrency."""
    currency_name = TextField(unique=True)


class HistoricalValue(BaseModel):
    """Represent currency OHLC values for one day."""
    date = DateField()
Ejemplo n.º 4
0
import tqdm

import profile, rides

if __name__ == '__main__':
    files = []
    for r, d, f in os.walk(IMPORT_DIRECTORY, followlinks=True):
        for file in f:
            if '.' not in file:
                files.append(os.path.join(r, file))
    for file in tqdm.tqdm(files):
        if "Profiles" in file:
            continue
        filename = file.split("/")[-1]
        region = file.split("/")[-3]
        with DatabaseConnection() as cur:
            cur.execute(
                """
                SELECT * FROM public."SimRaAPI_parsedfiles" WHERE "fileName" LIKE %s
            """, (f'%{filename}%', ))
            if cur.fetchone() is not None:
                continue
        try:
            with DatabaseConnection(
            ) as cur:  # new database connection for the whole transaction
                if "Profiles" in file:
                    profile.handle_profile(file, cur)
                    continue
                else:
                    print(file)
                    rides.handle_ride_file(file, cur)
Ejemplo n.º 5
0
        raise (e)
    try:
        cur.execute("""
            INSERT INTO public."SimRaAPI_ride" (geom, timestamps, legs, filename, "start", "end") VALUES (%s, %s, %s, %s, %s, %s) RETURNING id;
        """, [ls, timestamps, [i[0] for i in legs], filename, start, end])
        ride_id = cur.fetchone()[0]
        incidents.update_ride_ids([i[2] for i in incident_locs], ride_id, cur)

    except:
        print(f"Problem parsing {filename}")
        raise Exception("Can not parse ride!")


if __name__ == '__main__':
    filepath = "../csvdata/Berlin/Rides/VM2_-351907452"
    with DatabaseConnection() as cur:
        handle_ride_file(filepath, cur)


def is_teleportation(timestamps):
    for i, t in enumerate(timestamps):
        if i + 1 < len(timestamps):
            if (timestamps[i + 1] - timestamps[i]).seconds > 20:
                return True
    return False


class Ride:
    def __init__(self, raw_coords, accuracies, timestamps):
        self.raw_coords = raw_coords
        self.raw_coords_filtered = None
Ejemplo n.º 6
0
import argparse
import re
import time

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

from db_connection import DatabaseConnection
from model import Match, TableEntry, Season, TeamStats, League

main_url = 'https://www.flashscore.com'
db = DatabaseConnection('test.db')

countries_leagues = {'England': 'Premier League', 'Spain': 'LaLiga', 'Italy': 'Serie A', 'Germany': 'Bundesliga',
                     'France': 'Ligue 1', 'Portugal': 'Primeira Liga', 'Russia': 'Premier League',
                     'Netherlands': 'Eredivisie', 'Turkey': 'Super Lig'}


def execute_script_click(button):
    browser.execute_script('arguments[0].click();', button)


def click_league(country, league_name):
    left_panel = browser.find_element_by_id('lc')
    countries_menus = left_panel.find_elements_by_class_name('mbox0px')
    countries_lists = [menu.find_element_by_class_name('menu') for menu in countries_menus]
    countries_lists = [countries_list for countries_list in countries_lists]