Ejemplo n.º 1
0
def load():
    DB.initialize()
    loadFromXML()
    loadFromDB()

    util.DEBUG_LOG('Rating Systems:')
    for rs in RATINGS_SYSTEMS.values():
        util.DEBUG_LOG('  {0}'.format(repr(rs)))
Ejemplo n.º 2
0
def load():
    DB.initialize()
    loadFromXML()
    loadFromDB()

    util.DEBUG_LOG('Rating Systems:')
    for rs in RATINGS_SYSTEMS.values():
        util.DEBUG_LOG('  {0}'.format(repr(rs)))
Ejemplo n.º 3
0
    def DBChoices(self, attr):
        import database as DB
        DB.initialize()

        DB.connect()
        try:
            return [(x.path, os.path.basename(x.path)) for x in DB.VideoBumpers.select().where(DB.VideoBumpers.type == self.vtype)]
        finally:
            DB.close()
Ejemplo n.º 4
0
    def DBChoices(self, attr):
        import database as DB
        DB.initialize()

        DB.connect()
        try:
            return [(x.path, os.path.basename(x.path)) for x in DB.VideoBumpers.select().where(DB.VideoBumpers.type == self.vtype)]
        finally:
            DB.close()
Ejemplo n.º 5
0
def main(init_database, number_workers):
    if init_database:
        if click.confirm(
                'Are you sure to initialize the database? This will clear the database if exists!'
        ):
            initialize()
        else:
            print('Aborted.')
    else:
        run_pipeline(number_workers)
Ejemplo n.º 6
0
def test_bulk_operations(database_test_file, nodes, edges):
    db.initialize(database_test_file)
    ids = []
    bodies = []
    for id, body in nodes.items():
        ids.append(id)
        bodies.append(body)

    # bulk add and confirm
    db.atomic(database_test_file, db.add_nodes(bodies, ids))
    for id, node in nodes.items():
        assert db.atomic(database_test_file, db.find_node(id)) == node

    # bulk upsert and confirm
    db.atomic(database_test_file, db.upsert_nodes(bodies, ids))
    for id, node in nodes.items():
        assert db.atomic(database_test_file, db.find_node(id)) == node

    # bulk connect and confirm
    sources = []
    targets = []
    properties = []
    for src, tgts in edges.items():
        for target in tgts:
            tgt, label = target
            sources.append(src)
            targets.append(tgt)
            if label:
                properties.append(label)
            else:
                properties.append({})

    db.atomic(database_test_file,
              db.connect_many_nodes(sources, targets, properties))
    for src, tgts in edges.items():
        actual = [
            tuple(x)
            for x in [[edge[0], edge[1], json.loads(edge[2])]
                      for edge in db.atomic(database_test_file,
                                            db.get_connections_one_way(src))]
        ]
        for target in tgts:
            tgt, label = target
            if label:
                expected = (str(src), str(tgt), label)
            else:
                expected = (str(src), str(tgt), {})
            assert expected in actual

    # bulk remove and confirm
    db.atomic(database_test_file, db.remove_nodes(ids))
    for id in ids:
        assert db.atomic(database_test_file, db.find_node(id)) == {}
Ejemplo n.º 7
0
def main():
    database.initialize()
    bot = LulzBot()
    bot.connection.set_keepalive(300)
    connected = False
    while not connected:
        try:
            bot.start()
        except irc.client.ServerConnectionError:
            time.sleep(60)
        else:
            connected = True
Ejemplo n.º 8
0
def main():
    database.initialize()
    bot = LulzBot()
    bot.connection.set_keepalive(300)
    connected = False
    while not connected:
        try:
            bot.start()
        except irc.client.ServerConnectionError:
            time.sleep(60)
        else:
            connected = True
 def __init__(self, sequence_path, db_path=None, content_path=None):
     DB.initialize(db_path)
     self.pos = -1
     self.size = 0
     self.sequence = []
     self.featureQueue = []
     self.playables = []
     self.genres = []
     self.contentPath = content_path
     self.lastFeature = None
     self._lastAction = None
     self.loadSequence(sequence_path)
     self.createDefaultFeature()
Ejemplo n.º 10
0
    def DBChoices(attr):
        import database as DB
        DB.initialize()

        ratingSystem = util.getSettingDefault('rating.system.default')

        DB.connect()
        try:
            return [
                (x.style, x.style) for x in DB.RatingsBumpers.select(DB.fn.Distinct(DB.RatingsBumpers.style)).where(DB.RatingsBumpers.system == ratingSystem)
            ]
        finally:
            DB.close()
Ejemplo n.º 11
0
    def DBChoices(attr):
        import database as DB
        DB.initialize()

        ratingSystem = util.getSettingDefault('rating.system.default')

        DB.connect()
        try:
            return [(x.style, x.style) for x in DB.RatingsBumpers.select(
                DB.fn.Distinct(DB.RatingsBumpers.style)).where(
                    DB.RatingsBumpers.system == ratingSystem)]
        finally:
            DB.close()
Ejemplo n.º 12
0
 def __init__(self, sequence_path, db_path=None, content_path=None):
     DB.initialize(db_path)
     self.pos = -1
     self.size = 0
     self.sequence = []
     self.featureQueue = []
     self.playables = []
     self.genres = []
     self.contentPath = content_path
     self.lastFeature = None
     self._lastAction = None
     self.loadSequence(sequence_path)
     self.createDefaultFeature()
Ejemplo n.º 13
0
def apple(database_test_file, nodes, edges):
    db.initialize(database_test_file)
    [
        db.atomic(database_test_file, db.add_node(node, id))
        for id, node in nodes.items()
    ]
    for src, targets in edges.items():
        for target in targets:
            tgt, label = target
            if label:
                db.atomic(database_test_file,
                          db.connect_nodes(src, tgt, label))
            else:
                db.atomic(database_test_file, db.connect_nodes(src, tgt))
    yield
Ejemplo n.º 14
0
def update():
	print('Initializing database...')
	database.initialize()

	print('Getting available terms...')
	terms = scrape.getTerms()

	print('Terms retrieved. Updating table...')
	database.insert('terms', terms)

	print('Getting faculty information and dates for available terms...')
	termsInfo = {
		'faculties' : [],
		'dates' : []
	}
	for term in terms:
		termInfo = scrape.getFacultiesAndDates(term['id'])
		termsInfo['faculties'].extend(termInfo['faculties'])
		termsInfo['dates'].extend(termInfo['dates'])

	print('Faculties and dates retrieved. Updating tables...')
	database.insert('faculties', termsInfo['faculties'])
	database.insert('dates', termsInfo['dates'])

	print('Checking the database for new stats to retrieve...')
	missingStats = database.getMissingEmploymentStats()
	count = len(missingStats)

	print('{count} records to retrieve. Starting retrieval...'.format(count=count))
	employment = []
	termsMap = processTerms(database.getTerms())
	facultiesMap = {}
	for termKey in termsMap:
		facultiesMap[termKey] = processFaculties(database.getFaculties(termKey))
	current = 1
	for entry in missingStats:
		delay = random.random()*.5
		time.sleep(delay)
		print('({percent:5.2f}%):{current}/{count} - Fetching info on {faculty} from {date} in {term}...'.format(percent=float(current)/count * 100, current=current, count=count, faculty=facultiesMap[entry[0]][entry[2]], date=str(entry[1]), term=termsMap[entry[0]]))
		employment.extend(scrape.getEmploymentStats(*entry))
		if current % 25 == 0:
			print('Saving new entries...')
			database.insert('employment', employment)
			employment = []
		current+=1
	database.insert('employment', employment)
	
	print('Update complete.')
Ejemplo n.º 15
0
def execute():
    warnings.filterwarnings("ignore")
    initialize_logging("../logs/merge.log", "a+")

    logger = logging.getLogger()
    engine, session = database.initialize("sqlite:///../data/isrid-master.db")

    with open("../data/mappings.yaml") as mappings_file:
        mappings = yaml.load(mappings_file.read())

    for filename in os.listdir("../data/"):
        if filename.endswith(".xlsx"):
            for title, rows in read_excel(os.path.join("../data/", filename)):
                procedure = Registry.retrieve(filename, title)
                procedure = procedure or Registry.retrieve(filename)
                mapping = mappings.get(filename, {}).get(title, {})

                if procedure:
                    message = "Merging '{}' from '{}' ... "
                    logger.info(message.format(title, filename))
                    labels = list(next(rows))

                    if labels.count("Equipment4") > 1:
                        index = labels[::-1].index("Equipment4")
                        labels[-index - 1] = "Equipment5"

                    for index, row in enumerate(rows):
                        labeled_row = dict(zip(labels, row))
                        for model in procedure(index, labeled_row, mapping):
                            session.add(model)

                    session.commit()

    logging.shutdown()
    database.terminate(engine, session)
Ejemplo n.º 16
0
def read_time_data(url):
    """
    Read the time of day each incident occurred at.

    Arguments:
        url: A string representing the path to the database.

    Returns:
        A `pandas` dataframe with two columns: `time` and `hour`. `time`
        contains Python `datetime.time` objects with times at midnight filtered
        out (most of these indicate a date was available, but not time). `hour`
        is `time` in hours (a float between 0 and 24, exclusive).

        `time` is derived from `Incident.datetime`.
    """
    engine, session = database.initialize(url)
    df = tabulate(session.query(Incident.datetime))
    database.terminate(engine, session)

    df = df.assign(time=[datetime.time() for datetime in df.datetime])
    df = df[df.time != datetime.time(0)]
    df = df.assign(hour=[time.hour + time.minute/60 + time.second/3600
                         for time in df.time])

    return df
Ejemplo n.º 17
0
def main():
    """
    Bootstrap the update process by wrapping the initialization and termination
    of logging and database access.

    Errors raised by tasks are caught here and logged, and the script is
    immediately killed.
    """
    initialize_logging('../logs/update.log')
    logger = logging.getLogger()
    engine, session = database.initialize('sqlite:///../data/isrid-master.db')

    tasks = [augment_weather_instances]

    for task in tasks:
        try:
            task_name = task.__name__.replace('_', ' ')
            logger.info('Starting task: {}'.format(task_name))
            task(session)

        except KeyboardInterrupt:
            print()
            logger.info('Terminating update ... ')
            break

        except Exception as error:
            logger.error('{}: {}'.format(type(error).__name__, error))
            break

    logging.shutdown()  # Flush files
    database.terminate(engine, session)
Ejemplo n.º 18
0
    def setUp(self):
        self.engine, self.session = database.initialize('sqlite:///:memory:')

        self.group = Group()
        self.subject = Subject(sex='female', weight=25, height=100,
                               group=self.group)

        self.location = Location()
        self.weather = Weather()

        self.operation = Operation()
        self.outcome = Outcome()
        self.search = Search()

        self.incident = Incident(source='US-CAm', group=self.group,
                                 location=self.location, weather=self.weather,
                                 operation=self.operation,
                                 outcome=self.outcome, search=self.search)

        instances = [self.group, self.subject, self.location, self.weather,
                  self.operation, self.outcome, self.search, self.incident]
        for instance in instances:
            self.session.add(instance)

        self.session.commit()
Ejemplo n.º 19
0
def load(data):
    ''' Insert or update data in the target database '''
    db_engine = database.initialize()
    db_session = sessionmaker(bind=db_engine)()
    generator_data = (database.models.Caged(**caged) for caged in data)
    for caged in tqdm(generator_data, total=len(data)):
        db_session.merge(caged)
    db_session.commit()
Ejemplo n.º 20
0
def main():
    # Initialize Selenium
    driver = Chrome()
    driver.implicitly_wait(15)

    # Initialize database
    session = Db.initialize()

    # Login to LinkedIn
    login.to_linkedin(driver)
    login.to_Salesforce(driver)

    # Get list of persons
    persons = get_persons_linkedin(driver, os.getenv('ACCOUNT_PAGE'))

    # Scrape persons
    for i in range(len(persons)):
        url = persons[i]['url']
        try:
            person = get_profile_linkedin(driver, url)
            Db.add_person(session, person)
        except Exception:
            pass

    Db.update_first_and_last(session)

    # Fetch all rows from database
    rows = Db.fetch_all(session, Db.Person)

    # Iterate over records and update title
    for row in rows:
        title = get_title(driver, row.linkedin_url)
        stmt = (update(
            Db.Person).where(Db.Person.id == row.id).values(job_title=title))
        stmt.execute()

    # Read duplicates, LinkedIn URLs as csv
    dupes = Db.read_csv_file_as_list('./dupes.csv')

    # Create contacts in Salesoforce
    for c in rows:
        if [c['linkedin_url']] not in dupes:
            sf.create_contact(driver,
                              account_id=os.getenv('ACCOUNT_ID'),
                              first=c['first'],
                              last=c['last'],
                              title=c['job_title'],
                              url=c['linkedin_url'],
                              city=c['location'],
                              about=c['about'],
                              phone='123')
            sf.log_a_call(driver, None, 'LinkedIn connect',
                          'Requested to connect', 'L')
    # Connect on LinkedIn
    for c in rows:
        # Connect on LinkedIn
        linkedin.connect_on_linkedin(driver, c['linkedin_url'])
Ejemplo n.º 21
0
def read_data(url):
    engine, session = database.initialize(url)

    query = session.query(Incident.total_hours, Subject.survived,
                          Group.category).join(Group, Subject)
    df = tabulate(query)

    database.terminate(engine, session)

    return df
Ejemplo n.º 22
0
def read_time_data(url):
    engine, session = database.initialize(url)
    df = tabulate(session.query(Incident.datetime))
    database.terminate(engine, session)

    df = df.assign(time=[datetime.time() for datetime in df.datetime])
    df = df[df.time != datetime.time(0)]
    df = df.assign(hour=[time.hour + time.minute/60 + time.second/3600
                         for time in df.time])

    return df
Ejemplo n.º 23
0
    def setUp(self):
        self.engine, self.session = database.initialize('sqlite:///:memory:')

        for age in range(1, 11):
            status = 'DOA' if random.random() < 0.5 else 'Well'
            subject = Subject(age=age, status=status)
            if age < 6:
                subject.weight = 20
            self.session.add(subject)

        self.session.commit()
Ejemplo n.º 24
0
def start_gui():
    import wx
    import gui.mainBoard as mainWindow
    #---------------------------------------------------------------------------
    class MyApp(wx.App):
        def OnInit(self):
            self.SetAppName('MALODOS')
            #if len(sys.argv)>1 and os.path.exists(sys.argv[1]): database.theBase.use_base(sys.argv[1])
            self.frame = mainWindow.MainFrame(None, 'MALODOS')
            self.frame.Show(True)
            self.SetTopWindow(self.frame)
            #if str_to_bool(database.theConfig.get_param('encryption', 'encryptData','False',True)): get_current_password()
            #if not database.theBase.buildDB():
            #    return False
            return True
    app = MyApp(False)
    
    database.initialize()
    app.frame.initialize()
    #if not database.theBase.buildDB(): raise 'Unable to load the database'
    app.MainLoop()
Ejemplo n.º 25
0
    def setUp(self):
        self.engine, self.session = database.initialize('sqlite:///:memory:')

        self.subjects = [Subject() for number in range(10)]
        self.ipp = Point(latitude=0, longitude=0)
        self.group = Group(subjects=self.subjects)
        self.operation = Operation(ipp=self.ipp)
        self.incident = Incident(group=self.group, operation=self.operation)

        instances = [self.ipp, self.group, self.operation, self.incident]
        for instance in self.subjects + instances:
            self.session.add(instance)
        self.session.commit()
Ejemplo n.º 26
0
def read_simple_data(url, exclude_singles=False, exclude_groups=False):
    """
    Read incident duration, survival, and category data. A useful shorthand.

    Arguments:
        url: A string representing the database URL to connect to.
        exclude_singles: A boolean indicating whether the query should exclude
                         subjects from groups with exactly one member.
        exclude_groups: A boolean indicating whether the query should exclude
                        subjects from groups with more than one members.

    Returns:
        A pandas dataframe containing the lost person data. The columns include
        `total_hours`, `survived`, `category`, `days` (the incident duration in
        days, as taken from `total_hours`), and `doa` (a boolean that is `True`
        is the subject did not survive). Cases with a negative timedelta
        `Incident.total_hours` are filtered out.

    Warning:
        If `exclude_singles` is `True` or `exclude_groups` is `True`, the
        function also needs to query the size of each `Group`, which may take
        a while (perhaps a minute).
    """
    engine, session = database.initialize(url)

    columns = Incident.total_hours, Subject.survived, Group.category, Group.id
    query = session.query(*columns).join(Group, Subject)
    df = tabulate(query)

    database.terminate(engine, session)

    if exclude_singles or exclude_groups:
        df['size'] = [Group.query.get(int(id_)).size for id_ in df.id]  # Hack
    if exclude_singles:
        df = df[df['size'] > 1]
    if exclude_groups:
        df = df[df['size'] == 1]

    if 'size' in df:
        df.drop('size', 1, inplace=True)
    df.drop('id', 1, inplace=True)

    df = df.assign(days=[total_hours.total_seconds()/3600/24
                         for total_hours in df.total_hours],
                   doa=[not survived for survived in df.survived])
    df = df[0 <= df.days]

    return df
Ejemplo n.º 27
0
def read_data(url, *columns, not_null=True):
    engine, session = database.initialize(url)

    query = session.query(*columns).join(Group, Incident)
    query = query.filter(*map(lambda column: column != None, columns))

    database.terminate(engine, session)

    data = pd.DataFrame()

    for column in columns:
        name, datatype = str(column).split(".")[-1], column.type.python_type
        values = (value for value, *empty in query.from_self(column))

        if datatype == datetime.timedelta:
            datatype = float
            values = map(lambda value: value.total_seconds() / 3600, values)

        data[name] = np.fromiter(values, np.dtype(datatype))

    return data
Ejemplo n.º 28
0
def loop():
    """
    Read and evaluate expressions provided by the user.
    """
    engine, session = database.initialize('sqlite:///../data/isrid-master.db')
    print('Shell initialized at: {}'.format(datetime.datetime.now()))

    cmd = 1  # You can change your prompt to include the command number
    while True:
        try:
            expression = input('[!] ').strip()
            if len(expression) == 0:
                continue
            print(' =>', eval(expression))
        except (KeyboardInterrupt, EOFError):
            print()
            break
        except Exception as error:
            print(' => {}: {}'.format(type(error).__name__, error))
        finally:
            cmd += 1

    database.terminate(engine, session)  # Cleanly shut down SQLAlchemy
Ejemplo n.º 29
0
def execute():
    initialize_logging('../logs/update.log')
    logger = logging.getLogger()
    engine, session = database.initialize('sqlite:///../data/isrid-master.db')

    tasks = [augment_weather_instances]

    for task in tasks:
        try:
            task_name = task.__name__.replace('_', ' ')
            logger.info('Starting task: {}'.format(task_name))
            task(session)

        except KeyboardInterrupt:
            print()
            logger.info('Terminating update ... ')
            break

        except Exception as error:
            logger.error('{}: {}'.format(type(error).__name__, error))
            break

    logging.shutdown()
    database.terminate(engine, session)
Ejemplo n.º 30
0
def initialize_session(url='sqlite:///../data/isrid-master.db'):
    if not database_initialized():
        app.logger.info('Database initialized')
        g.engine, g.session = database.initialize(url)
Ejemplo n.º 31
0
def execute():
    matplotlib.rc("font", size=20)

    engine, session = database.initialize("sqlite:///../data/isrid-master.db")

    # Query with Group.size may take awhile, at least for Charles
    # Not sure why
    query = session.query(Incident.total_hours, Subject.survived, Group.category, Group.size).join(Group, Subject)
    print("Tabulating query... may take awhile for unknown reasons.")
    df = tabulate(query)
    print("Done tabulating.")
    print(df.describe())
    database.terminate(engine, session)

    df = df.assign(
        days=[total_hours.total_seconds() / 3600 / 24 for total_hours in df.total_hours],
        doa=[not survived for survived in df.survived],
    )
    df = df[0 <= df.days]

    rows, columns = 2, 2
    grid, axes = plt.subplots(rows, columns, figsize=(15, 10))

    categories = Counter(df.category)
    plot = 0
    kmfs = []
    options = {"show_censors": True, "censor_styles": {"marker": "|", "ms": 6}, "censor_ci_force_lines": False}

    for category, count in categories.most_common()[: rows * columns]:
        print("Category:", category)
        ax = axes[plot // columns, plot % columns]
        df_ = df[df.category == category]
        N, Ndoa = len(df_), sum(df_.doa)
        Srate = 100 * (1 - Ndoa / N)
        grp = df_[df_.size > 1]
        sng = df_[df_.size == 1]
        kmf = KaplanMeierFitter()
        # kmf.fit(df_.days, event_observed=df_.doa, label=category)
        # kmf.plot(ax=ax, ci_force_lines=True)
        kmf.fit(grp.days, event_observed=grp.doa, label=category + " Groups")
        kmf.plot(ax=ax, **options)
        kmf.fit(sng.days, event_observed=sng.doa, label=category + " Singles")
        kmf.plot(ax=ax, **options)
        kmfs.append(kmf)

        ax.set_xlim(0, min(30, 1.05 * ax.get_xlim()[1]))
        ax.set_ylim(0, 1)
        ax.set_title("{}, N = {}, DOA = {}, {:.0f}% surv".format(category, N, Ndoa, Srate))
        ax.set_xlabel("Total Incident Time (days)")
        ax.set_ylabel("Probability of Survival")

        # ax.legend_.remove()
        # ax.grid(True)

        plot += 1

    grid.suptitle("Kaplan-Meier Survival Curves", fontsize=25)
    grid.tight_layout()
    grid.subplots_adjust(top=0.9)
    grid.savefig("../doc/figures/kaplan-meier/km-grid-large.svg", transparent=True)

    combined = plt.figure(figsize=(15, 10))
    ax = combined.add_subplot(1, 1, 1)
    for kmf in kmfs[: rows * columns]:
        kmf.plot(ci_show=False, show_censors=True, censor_styles={"marker": "|", "ms": 6}, ax=ax)

    ax.set_xlim(0, 15)
    ax.set_ylim(0, 1)
    ax.set_xlabel("Total Incident Time (days)")
    ax.set_ylabel("Probability of Survival")
    ax.set_title("Kaplan-Meier Survival Curves", fontsize=25)
    ax.grid(True)
    combined.savefig("../doc/figures/kaplan-meier/km-combined-large.svg", transparent=True)

    plt.show()
Ejemplo n.º 32
0
from flask import Flask, request, jsonify
from flask_cors import CORS
from database import initialize, Question, User, Response, Config

from typing import Dict, List

DATABASE_URI = "sqlite:///quiz.db"

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URI
CORS(app)
db = initialize(app)


class APIError(Exception):
    status_code = 400

    def __init__(self, message, status_code=None, payload=None):
        Exception.__init__(self)
        self.message = message
        if status_code is not None:
            self.status_code = status_code
        self.payload = payload

    def to_dict(self):
        rv = dict(self.payload or ())
        rv["message"] = self.message
        return rv


@app.errorhandler(APIError)
Ejemplo n.º 33
0
import os
from flask import Flask, request, redirect, jsonify
from dotenv import load_dotenv
from spotify import get_spotify_url, save_user, get_all_user_playing
from database import initialize, retrieve_last_songs
from scheduler import start_scheduler

load_dotenv()

app = Flask(__name__)
initialize()


@app.route("/")
def home():
    return "Maronn!"


@app.route("/authorize")
def authorize():
    return redirect(get_spotify_url("test"))


@app.route("/callback")
def callback():
    user_code = request.args.get("code")
    save_user(user_code)
    return redirect("/")


@app.route("/playing")
Ejemplo n.º 34
0
 def setUp(self):
     url = 'sqlite:///../data/isrid-master.db'
     self.engine, self.session = database.initialize(url)
Ejemplo n.º 35
0
def main():
    """ Zarp entry point
    """

    # set up configuration
    config.initialize()

    # set up database
    database.initialize()

    # load modules
    loader = LoadedModules()
    loader.load()
    util.Msg('Loaded %d modules.' % loader.total)

    # handle command line options first
    if len(argv) > 1:
        parse_cmd.parse(argv, loader)

    # menus
    main_menu = [
        'Poisoners', 'DoS Attacks', 'Sniffers', 'Scanners', 'Parameter',
        'Services', 'Attacks', 'Sessions'
    ]

    running = True
    choice = -1
    while running:
        util.header()
        choice = util.print_menu(main_menu)
        if choice == 0:
            # check if they've got running sessions!
            cnt = stream.get_session_count()
            if cnt > 0:
                display = color.B_YELLOW + 'You have %d sessions running. ' + \
                          'Are you sure? ' + color.B_GREEN + '[' + color.B_YELLOW + \
                          'Y' + color.B_GREEN + '/' + color.B_YELLOW + 'n' + \
                          color.B_GREEN + '] ' + color.END
                choice = raw_input(display % cnt)
                if 'y' in choice.lower() or choice == '':
                    util.Msg('Shutting all sessions down...')
                    stream.stop_session('all', -1)
                    running = False

            else:
                util.debug("Exiting with session count: %d" % (cnt))
                util.Msg("Exiting...")
                running = False

            # remove zarp temporary directory
            util.init_app('rm -fr /tmp/.zarp/')

            # recheck that all sessions are down
            cnt = stream.get_session_count()
            if cnt <= 0:
                # some libs dont clean up their own threads, so
                # we need to hard quit those to avoid hanging; FIXME
                _exit(1)
        elif choice == 1:
            while True:
                choice = util.print_menu([x().which for x in loader.poison])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.poison):
                    continue
                else:
                    stream.initialize(loader.poison[choice - 1])
        elif choice == 2:
            while True:
                choice = util.print_menu([x().which for x in loader.dos])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.dos):
                    continue
                else:
                    stream.initialize(loader.dos[choice - 1])
        elif choice == 3:
            while True:
                choice = util.print_menu([x().which for x in loader.sniffers])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.sniffers):
                    continue
                else:
                    stream.initialize(loader.sniffers[choice - 1])
        elif choice == 4:
            while True:
                choice = util.print_menu([x().which for x in loader.scanner])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.scanner):
                    continue
                else:
                    stream.initialize(loader.scanner[choice - 1])
        elif choice == 5:
            while True:
                choice = util.print_menu([x().which for x in loader.parameter])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.parameter):
                    continue
                else:
                    stream.initialize(loader.parameter[choice - 1])
        elif choice == 6:
            while True:
                choice = util.print_menu([x().which for x in loader.services])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.services):
                    continue
                else:
                    stream.initialize(loader.services[choice - 1])
        elif choice == 7:
            while True:
                choice = util.print_menu([x().which for x in loader.attacks])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.attacks):
                    continue
                else:
                    stream.initialize(loader.attacks[choice - 1])
        elif choice == 8:
            session_manager.menu()
        elif choice == -1:
            pass
# -*- coding: UTF-8 -*-
from flask import Flask, request, url_for, render_template, session, redirect
from urllib import quote_plus, unquote_plus

# app starts here
app = Flask(__name__)
app.config.from_object('settings.DevelopmentConfig')

# database module depends on app.config['DATABASE_URL']
from database import initialize
initialize(app.config['DATABASE_URL'])


# To use SQLAlchemy in a declarative way with your app, you just have to put the following code into your app module. Flask will automatically remove database sessions at the end of the request for you:
@app.teardown_request
def shutdown_session(exception=None):
    from database import db_session
    db_session.remove()


# register all blueprints
import index
import langs
from admin import admin, uploads, login, photos, users, settings, monitor
app.register_blueprint(index.bp, url_prefix='/')
app.register_blueprint(langs.bp, url_prefix='/lang')
app.register_blueprint(admin.bp, url_prefix='/admin')
app.register_blueprint(photos.bp, url_prefix='/admin/photos')
app.register_blueprint(users.bp, url_prefix='/admin/users')
app.register_blueprint(settings.bp, url_prefix='/admin/settings')
app.register_blueprint(uploads.bp, url_prefix='/admin/uploads')
Ejemplo n.º 37
0
Archivo: zarp.py Proyecto: 0x0mar/zarp
def main():
    """ Zarp entry point
    """

    # set up configuration
    config.initialize()

    # set up database
    database.initialize()

    # load modules
    loader = LoadedModules()
    loader.load()
    util.Msg('Loaded %d modules.' % loader.total)

    # handle command line options first
    if len(argv) > 1:
        parse_cmd.parse(argv, loader)

    # menus
    main_menu = ['Poisoners', 'DoS Attacks', 'Sniffers', 'Scanners',
                     'Parameter', 'Services', 'Attacks', 'Sessions']

    running = True
    choice = -1
    while running:
        util.header()
        choice = util.print_menu(main_menu)
        if choice == 0:
            # check if they've got running sessions!
            cnt = stream.get_session_count()
            if cnt > 0:
                display = color.B_YELLOW + 'You have %d sessions running. ' + \
                          'Are you sure? ' + color.B_GREEN + '[' + color.B_YELLOW + \
                          'Y' + color.B_GREEN + '/' + color.B_YELLOW + 'n' + \
                          color.B_GREEN + '] ' + color.END
                choice = raw_input(display % cnt)
                if 'y' in choice.lower() or choice == '':
                    util.Msg('Shutting all sessions down...')
                    stream.stop_session('all', -1)
                    running = False

            else:
                util.debug("Exiting with session count: %d" % (cnt))
                util.Msg("Exiting...")
                running = False

            # remove zarp temporary directory
            util.init_app('rm -fr /tmp/.zarp/')
             
            # recheck that all sessions are down
            cnt = stream.get_session_count()
            if cnt <= 0:
               # some libs dont clean up their own threads, so
               # we need to hard quit those to avoid hanging; FIXME
               _exit(1)
        elif choice == 1:
            while True:
                choice = util.print_menu([x().which for x in loader.poison])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.poison):
                    continue
                else:
                    stream.initialize(loader.poison[choice - 1])
        elif choice == 2:
            while True:
                choice = util.print_menu([x().which for x in loader.dos])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.dos):
                    continue
                else:
                    stream.initialize(loader.dos[choice - 1])
        elif choice == 3:
            while True:
                choice = util.print_menu([x().which for x in loader.sniffers])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.sniffers):
                    continue
                else:
                    stream.initialize(loader.sniffers[choice - 1])
        elif choice == 4:
            while True:
                choice = util.print_menu([x().which for x in loader.scanner])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.scanner):
                    continue
                else:
                    stream.initialize(loader.scanner[choice - 1])
        elif choice == 5:
            while True:
                choice = util.print_menu([x().which for x in loader.parameter])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.parameter):
                    continue
                else:
                    stream.initialize(loader.parameter[choice - 1])
        elif choice == 6:
            while True:
                choice = util.print_menu([x().which for x in loader.services])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.services):
                    continue
                else:
                    stream.initialize(loader.services[choice - 1])
        elif choice == 7:
            while True:
                choice = util.print_menu([x().which for x in loader.attacks])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.attacks):
                    continue
                else:
                    stream.initialize(loader.attacks[choice - 1])
        elif choice == 8:
            session_manager.menu()
        elif choice == -1:
            pass
Ejemplo n.º 38
0
    def get_distance(self):
        for i in range(0, len(self.echoList)):
            send_trig_pulse(self.trig)
            wait_for_echo(self.echoList[i], True, 10000)
            start = time.time()
            wait_for_echo(self.echoList[i], False, 10000)
            finish = time.time()
            pulse_len = finish - start
            distance_cm = pulse_len / 0.000058
            self.dis[i] = distance_cm
        return (self.dis)


cs_block = parkingLot(36, [40, 38], [31, 32], "SIT_CS_Block")
p = [0, 0]
firebase = database.initialize()
vehicle_CS = ["No", "No"]
prev_t = [0, 0]
vehicle_back = ['No', 'No']
while True:
    disList = cs_block.get_distance()
    print(disList)
    time.sleep(2)
    for i in range(0, len(disList)):
        dis = disList[i]
        if (dis > 4):
            print("Parking slot" + str(i) + " is empty ", dis)
            vehicle_CS[i] = database.retrieve_db(firebase, cs_block.lotName, i,
                                                 "vehicle")
            if vehicle_CS[i] != "No":
                vehicle_back[i] = vehicle_CS[i]
Ejemplo n.º 39
0
def update_cards(verbose=True):
    session = Session()
    bulk_data_uri = scryfall.get_bulk_data()
    bulk_data = scryfall.bulk_data_generator(bulk_data_uri)
    printings = (Printing.from_scryfall(p) for p in bulk_data)
    session.add_all(printings)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', category=exc.SAWarning)
        session.commit()
    session.close()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("action", help="Action you want to perform")
    parser.add_argument("-n", "--name", type=str, help="")
    parser.add_argument("-d", "--deck", type=str)
    args = parser.parse_args()
    if args.action == "initialize":
        database.initialize(verbose=True)
    elif args.action == "update":
        update_sets()
        update_cards()
    elif args.action == "card":
        if args.name:
            result = Card.named(args.name)
        print(result)
    elif args.action == "add":
        pass
# -*- coding: UTF-8 -*-
from flask import Flask, request, url_for, render_template, session, redirect
from urllib import quote_plus, unquote_plus

# app starts here
app = Flask(__name__)
app.config.from_object('settings.DevelopmentConfig')


# database module depends on app.config['DATABASE_URL']
from database import initialize
initialize(app.config['DATABASE_URL'])


# To use SQLAlchemy in a declarative way with your app, you just have to put the following code into your app module. Flask will automatically remove database sessions at the end of the request for you:
@app.teardown_request
def shutdown_session(exception=None):
    from database import db_session
    db_session.remove()


# register all blueprints
import index
import langs
from admin import admin, uploads, login, photos, users, settings, monitor
app.register_blueprint(index.bp, url_prefix='/')
app.register_blueprint(langs.bp, url_prefix='/lang')
app.register_blueprint(admin.bp, url_prefix='/admin')
app.register_blueprint(photos.bp, url_prefix='/admin/photos')
app.register_blueprint(users.bp, url_prefix='/admin/users')
app.register_blueprint(settings.bp, url_prefix='/admin/settings')
Ejemplo n.º 41
0
def setup():
    from database import initialize
    initialize()
Ejemplo n.º 42
0
      pass
      #print "Your turn:"
   else:
      pass
      #print "Waiting for " + whosTurn

def generateDeck():
   for suit in range(3,7):
      for card in range(1,14):
         deck.append((suit,card))

#= MainCode
start_new_thread(processSocket, ())

#read from database
database.initialize(traffic.getIP())
userList = database.getGlobalList()
#greet users in database
traffic.sendText(GREET, userList)
print "my IP is " + myIP
while True:
   if gameStarted:
      if players[turn] == myIP:
         state = MY_TURN
      else:
         state = WAITING_FOR_TURN
   if state == WAITING_FOR_GAME:
      print "Waiting for players to join..."
      #print "I think server is " + server
      action = raw_input()
      processAction(action)
Ejemplo n.º 43
0
Archivo: zarp.py Proyecto: zyan03/zarp
def main():
    """ Zarp entry point
    """

    # set up configuration
    config.initialize()

    # set up database
    database.initialize()

    # load modules
    loader = LoadedModules()
    loader.load()
    Msg('Loaded %d modules.' % loader.total)

    # handle command line options first
    if len(argv) > 1:
        parse_cmd.parse(argv, loader)

    # menus
    main_menu = ['Poisoners', 'DoS Attacks', 'Sniffers', 'Scanners',
                     'Parameter', 'Services', 'Attacks', 'Sessions']

    running = True
    choice = -1
    while running:
        header()
        choice = print_menu(main_menu)
        if choice == 0:
            # check if they've got running sessions!
            cnt = stream.get_session_count()
            if cnt > 0:
                choice = raw_input(color.YELLOW +
                'You have %d sessions running.  Are you sure? [Y/n] ' % cnt
                 + color.END)
                if 'y' in choice.lower() or choice == '':
                    Msg('Shutting all sessions down...')
                    stream.stop_session('all', -1)
                    running = False
            else:
                debug("Exiting with session count: %d" % (cnt))
                Msg("Exiting...")
                running = False
        elif choice == 1:
            while True:
                choice = print_menu([x().which for x in loader.poison])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.poison):
                    continue
                else:
                    stream.initialize(loader.poison[choice - 1])
        elif choice == 2:
            while True:
                choice = print_menu([x().which for x in loader.dos])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.dos):
                    continue
                else:
                    stream.initialize(loader.dos[choice - 1])
        elif choice == 3:
            while True:
                choice = print_menu([x().which for x in loader.sniffers])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.sniffers):
                    continue
                else:
                    stream.initialize(loader.sniffers[choice - 1])
        elif choice == 4:
            while True:
                choice = print_menu([x().which for x in loader.scanner])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.scanner):
                    continue
                else:
                    stream.initialize(loader.scanner[choice - 1])
        elif choice == 5:
            while True:
                choice = print_menu([x().which for x in loader.parameter])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.parameter):
                    continue
                else:
                    stream.initialize(loader.parameter[choice - 1])
        elif choice == 6:
            while True:
                choice = print_menu([x().which for x in loader.services])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.services):
                    continue
                else:
                    stream.initialize(loader.services[choice - 1])
        elif choice == 7:
            while True:
                choice = print_menu([x().which for x in loader.attacks])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.attacks):
                    continue
                else:
                    stream.initialize(loader.attacks[choice - 1])
        elif choice == 8:
            session_manager.menu()
        elif choice == -1:
            pass
Ejemplo n.º 44
0
import database as db
import variables as vr

db.initialize('mytest')

# usage
ws_name1 = 'ws'

print('variable load..............')
variable = vr.get_variable('ws', 'newVar')
print(variable)

print('variable value data load..............')
print variable.value()

print('')
print('---------------------------------')
print('')

print('all variable load..............')
variables = vr.get_all_variables(workspace='ws')
print(variables)

for v in variables:
    print v.value()

#repo.get_variable('ws', 'newVar')

#print( variabless)
Ejemplo n.º 45
0
 def setupDB(self, db_path):
     DB.initialize(db_path, self.dbCallback)
Ejemplo n.º 46
0
            (r"/logout", login.login.Logout),
            (r"/admin/overview", admin.overview.Handler),
            (r"/admin/blacklist", admin.blacklist.Handler),
            (r"/admin/bans", admin.bans.Handler),
            (r"/admin/user_management", admin.user_management.Handler),
            (r"/admin/server_list", admin.server_list.Handler),
        ],
        cookie_secret=os.urandom(32),
        xsrf_cookies=True,
        static_path=os.path.join(os.path.dirname(__file__), "static"),
    )


if __name__ == "__main__":
    parse_command_line()
    if not database.initialize():
        exit(1)

    if options.add_sysop is not None:
        RANDOM_PW = util.generate_secret()
        database.add_login(options.add_sysop, RANDOM_PW, True)
        print("Password for {}: {}".format(options.add_sysop, RANDOM_PW))
        exit(0)

    if options.reset_pw is not None:
        RANDOM_PW = util.generate_secret()
        database.update_login(options.reset_pw, RANDOM_PW)
        print("New password for {}: {}".format(options.reset_pw, RANDOM_PW))
        exit(0)

    APP = make_app()
Ejemplo n.º 47
0
 def __init__(self):
     database.initialize()
Ejemplo n.º 48
0
#!/usr/bin/env python3

import matplotlib.pyplot as plt
import numpy as np
import Orange
from pomegranate import *

import database
from database.models import Subject, Group, Incident, Weather
from database.processing import survival_rate, tabulate, export_as_orange


engine, session = database.initialize('sqlite:///../data/isrid-master.db')

query = session.query(Subject.survived, Group.size, Weather.avg_temp)
query = query.join(Group, Incident, Weather)
df = tabulate(query, [True, True, True])

database.terminate(engine, session)


print(sum(df.survived)/len(df))
Ejemplo n.º 49
0
        log(f"Removing Client {clientId} from room {roomId}")
        sockets[roomId].remove((ws, clientId))
        db.removeUser(clientId, roomId)

        # notify other users about the leaver
        for peerWs in [x[0] for x in sockets[roomId]]:
            if peerWs is not ws:
                peerLeftNotice = {"peerLeft": {"id": clientId}}
                await peerWs.send(json.dumps(peerLeftNotice))


if __name__ == '__main__':

    log("Starting websocket server")
    db.cursor = db.initialize()

    if len(argv) > 1 and argv[1] == "--no-ssl":

        start_server = websockets.serve(handler, '', 8001)

    else:

        certs = db.cursor.execute("SELECT * FROM ssl_certificates").fetchone()
        certFile, keyFile = certs[0], certs[1]

        ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
        ssl_context.load_cert_chain(certFile, keyFile)

        start_server = websockets.serve(handler, '', 8001, ssl=ssl_context)
Ejemplo n.º 50
0
    import ipdb
    ipdb.set_trace()
    expired_user_challenges = database.get_expired_challenges()
    for user_challenge in expired_user_challenges:
        user_id = user_challenge.get('userIdentifier')
        user = database.get_user(user_id)
        fitbit_api = fitbit.Fitbit('227QRF', 'aacdb90aaaa175c50e0556e1a50f35ab',
                                   access_token=user.get('fitbit_access_token'))
        activity_stats = fitbit_api.activity_stats(user_id=user.get('fitbit_id'))
        steps = activity_stats['lifetime']['tracker']['steps']
        challenge_id = user_challenge.get('challengeIdentifier')
        uc = database.get_user_challenge(user_id, challenge_id)
        challenge = database.get_challenge(challenge_id)
        if (steps - uc.get('user_total_step_count_on_start')) >= challenge.get('steps_to_unlock'):
            database.user_challenge_complete(user_id, challenge_id, challenge.get('reward_points'))



    user = [{
        'challengeId': 777,
        'userId': 333
    }]
    return Response(json.dumps(user), status=httplib.CREATED, mimetype='application/json')


if __name__ == '__main__':
    logger.debug('Initializing database ...')
    database.initialize()
    database.seed_challenges()
    app.run(debug=True)
Ejemplo n.º 51
0
from timing_context import TimingContext
from utilities import json
from init_data import init_es_data, init_mongo_data

app = Flask(__name__, static_url_path="/static")
CORS(app, **config.get("apiserver.cors"))
Compress(app)

log = config.logger(__file__)

log.info("################ API Server initializing #####################")

app.config["SECRET_KEY"] = config.get("secure.http.session_secret.apiserver")
app.config["JSONIFY_PRETTYPRINT_REGULAR"] = config.get("apiserver.pretty_json")

database.initialize()

init_es_data()
init_mongo_data()

ServiceRepo.load("services")
log.info(f"Exposed Services: {' '.join(ServiceRepo.endpoint_names())}")


@app.before_first_request
def before_app_first_request():
    pass


@app.before_request
def before_request():
Ejemplo n.º 52
0
def main():
    """ Zarp entry point
    """

    # set up configuration
    config.initialize()

    # set up database
    database.initialize()

    # load modules
    loader = LoadedModules()
    loader.load()
    Msg("Loaded %d modules." % loader.total)

    # handle command line options first
    if len(argv) > 1:
        parse_cmd.parse(argv, loader)

    # menus
    main_menu = ["Poisoners", "DoS Attacks", "Sniffers", "Scanners", "Parameter", "Services", "Attacks", "Sessions"]

    running = True
    choice = -1
    while running:
        header()
        choice = print_menu(main_menu)
        if choice == 0:
            # check if they've got running sessions!
            cnt = stream.get_session_count()
            if cnt > 0:
                choice = raw_input(
                    color.YELLOW + "You have %d sessions running.  Are you sure? [Y/n] " % cnt + color.END
                )
                if "y" in choice.lower() or choice == "":
                    Msg("Shutting all sessions down...")
                    stream.stop_session("all", -1)
                    running = False

                    # recheck that all sessions are down
                    cnt = stream.get_session_count()
                    if cnt <= 0:
                        # some libs dont clean up their own threads, so
                        # we need to hard quit those to avoid hanging; FIXME
                        _exit(1)
            else:
                debug("Exiting with session count: %d" % (cnt))
                Msg("Exiting...")
                running = False
        elif choice == 1:
            while True:
                choice = print_menu([x().which for x in loader.poison])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.poison):
                    continue
                else:
                    stream.initialize(loader.poison[choice - 1])
        elif choice == 2:
            while True:
                choice = print_menu([x().which for x in loader.dos])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.dos):
                    continue
                else:
                    stream.initialize(loader.dos[choice - 1])
        elif choice == 3:
            while True:
                choice = print_menu([x().which for x in loader.sniffers])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.sniffers):
                    continue
                else:
                    stream.initialize(loader.sniffers[choice - 1])
        elif choice == 4:
            while True:
                choice = print_menu([x().which for x in loader.scanner])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.scanner):
                    continue
                else:
                    stream.initialize(loader.scanner[choice - 1])
        elif choice == 5:
            while True:
                choice = print_menu([x().which for x in loader.parameter])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.parameter):
                    continue
                else:
                    stream.initialize(loader.parameter[choice - 1])
        elif choice == 6:
            while True:
                choice = print_menu([x().which for x in loader.services])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.services):
                    continue
                else:
                    stream.initialize(loader.services[choice - 1])
        elif choice == 7:
            while True:
                choice = print_menu([x().which for x in loader.attacks])
                if choice == 0:
                    break
                elif choice == -1:
                    pass
                elif choice > len(loader.attacks):
                    continue
                else:
                    stream.initialize(loader.attacks[choice - 1])
        elif choice == 8:
            session_manager.menu()
        elif choice == -1:
            pass
Ejemplo n.º 53
0
 def setupDB(self, db_path):
     DB.initialize(db_path, self.dbCallback)
Ejemplo n.º 54
0
def initialize(server_name):
    global db
    db = server_name + '.db'
    conn = sqlite3.connect(db)
    database.initialize(conn)
    conn.close()