Пример #1
0
    def _join_game(self):

        token_validator_sock = WSock(8766)
        sock = WSock()

        settings = UserSettings(**get_config())

        priv_topic = settings.private_topic

        sock.subscribe(priv_topic)

        settings = UserSettingsSchema().dumps(settings)

        print(
            'In order to join a match, you need to get an alphanumeric token. Ex: a56n1d'
        )

        while (True):

            tkn = inquirer.text(
                message='Input token here:',
                validate=lambda text: len(text) == 6 and text.isalnum(),
                invalid_message=
                'Please enter a valid 6 character, alphanumeric token... '
            ).execute()

            message = json.dumps({
                'action': 'validate-token',
                'topic': tkn,
                'private_token': priv_topic
            })

            token_validator_sock.send_json(message)

            topic_exist = ''

            while (True):

                topic_exist = token_validator_sock.recv_json(priv_topic)

                if (topic_exist.private_token == priv_topic):

                    topic_exist = topic_exist.response
                    break

            if (topic_exist == 'topic-non-existent'):
                print(
                    f'The token "{tkn}" does not have a server attached to it. Please enter a valid token!'
                )
            else:
                break

        sock.send_json(settings, tkn)

        verification = sock.recv_str(priv_topic)

        if (verification == 'declined'):
            print('Request to join was declined by host ...')
            return 'declined'

        else:

            return 'accepted'
Пример #2
0
import init

config = init.get_config("al")


def parse(op_file, d, index_line):
    student_info = ",".join(index_line.split(init.input_sep)[0:8])
    if 'errMsge' in d:
        init.write_to_file(student_info + " - Student Not Found \n", op_file)
        return
    s = ""
    for s_info in [
            'Name', 'Subject Stream', 'Syllabus', 'District Rank',
            'Island Rank', 'Z-Score'
    ]:
        s = s + "," + init.find(d['studentInfo'], s_info)

    init.write_to_file(
        student_info + "," + s[1:] + "," + ",".join(
            init.fill_marks(config[4], d['subjectResults'],
                            index_line.split(init.input_sep)[7], 5)) + "\n",
        op_file)


init.start(config[1], config[2], config[3] + ",".join(config[4]) + "\n",
           config[0], init.input_sep, parse, 7)
Пример #3
0
from init import get_config
from energy import get_energy
from molecule import Molecule
from grad import gradient_descent
from hessian import Hessian
from frequencies import Frequencies
from pbc import pbc_sep
import numpy as np
if __name__ == '__main__':
    print("Starting to make initial configuration.")
    get_config()  # Q1
    init_mol = None
    with open("molecule.xyz") as f:
        print("Initial Configuration Generated for Arg LJ Model")
        print("Initial COnfiguration for Q1 will the saved to molecule.xyz")
        init_mol = Molecule(f, "Angstrom")
        print("Starting to do Q2 and Q3...")
        e = get_energy(np.array(init_mol.geom))  # Q2
        # print(e)
        # Q3 Steapest Descend is a heuristic.. Needs tuning of parameters...
        print("Starting Steepest Descent Algoithm to minimise Energy...")
        g = gradient_descent(0.135, 100, init_mol.geom)
        print("Steepest Descent Algoithm Ended.. Results below\n")
        print("Original Energy: ", e)
        print("New Energy:", np.min(np.array(g[1])))
        print()
        i = np.argmin(np.array(g[1]))
        print("New Configuration will be saved in new_molecule.xyz")
        with open("new_molecule.xyz", "w") as f2:
            print(len(g[0][i]), file=f2)
            print(file=f2)
Пример #4
0
(If you see a logger error loading it - this is the fix)

"""

import os, time, json, datetime, sys
import linecache
import init
from db_models import db, ApiKey, Role, UserRoles, Member, Resource, MemberTag, AccessByMember, Blacklist, Waiver
from slackclient import SlackClient
from flask_user import current_user, login_required, roles_required, UserManager, UserMixin, current_app
from flask import Flask, request, session, g, redirect, url_for, \
 abort, render_template, flash, Response, Markup

from templateCommon import *

Config = init.get_config()
slack_token = Config.get('Slack', 'BOT_API_TOKEN')
slack_disabled = Config.has_option('Slack', 'Disabled')


def get_users():
    sc = SlackClient(slack_token)
    #if sc.rtm_connect():
    #  sc.server.websocket.sock.setblocking(1)
    #print json.dumps(get_users(sc),indent=2)
    #if sc.server.connected:
    return sc.api_call("users.list")
    #else:
    #  logger.error("get_users slack connection fail")

Пример #5
0
from init import UserSettings, UserSettingsSchema, get_config
from wsock.wsock import WSock, Server
from threading import Thread
from InquirerPy import inquirer

sock = WSock()

settings = UserSettings(**get_config())

priv_topic = settings.private_topic

settings = UserSettingsSchema().dumps(settings)

tkn = input('tkn: ')

sock.send_json(settings, tkn)
print('sent')

verification = sock.recv_str(priv_topic)

if (verification == 'declined'):
    print('Request to join was declined by host ...')
Пример #6
0
import hashlib
import os
import pickle
from concurrent.futures import ThreadPoolExecutor, as_completed
from os.path import join
from threading import Lock
from time import sleep
import bot
import init
from log import *

logger = get_logger('bot')
_config_instance = init.get_config()
sync_interval = _config_instance['sync_interval']
sync_paths = _config_instance['sync_paths']
SYNC_CACHE = []
pool = ThreadPoolExecutor(max_workers=4)
synced_files_md5 = set()
try:
    with open('synced', 'rb') as synced:
        synced_files_md5 = pickle.load(synced)
except FileNotFoundError:
    pass


def _pickle() -> None:
    with open('synced', 'wb') as fp:
        pickle.dump(synced_files_md5, fp)


def update() -> None:
Пример #7
0
import init
config = init.get_config("ol")


def parse(op_file, d, index_line):
    if 'errMsge' in d:
        init.write_to_file(
            ",".join(index_line.split(init.input_sep)[0:7]) +
            " - Student Not Found \n", op_file)
    else:
        init.write_to_file(
            ",".join(index_line.split(init.input_sep)[0:7]) + "," + d['name'] +
            "," + ",".join(
                init.fill_marks(config[4], d['subjectResults'],
                                index_line.split(init.input_sep)[6], 9)) +
            "\n", op_file)


init.start(config[1], config[2], config[3] + ",".join(config[4]) + "\n",
           config[0], init.input_sep, parse)
Пример #8
0
import re
import init
import xml.dom.minidom

config = init.get_config("gv")
url = config[0]
input_file = config[1]
output_file = config[2]
input_sep = "\t"


def parse(content, index_line, f):
    doc = xml.dom.minidom.parseString(content)
    lines = content.split("\n")
    matching_lines = []
    for line in lines:
        m = re.search("(.*rightre\">)(.*)", line)
        if m:
            matching_lines.append(m.group(2))
    init.write_to_file(
        ",".join(index_line.split(input_sep)[0:4]) + "," + matching_lines[2] +
        "," + matching_lines[4] + "," + matching_lines[5] + "\n", f)


init.start(input_file, output_file,
           "CensusNo,School,Gender,IndexNo,Name,Mark,Qualification" + "\n",
           url, input_sep, parse)
Пример #9
0
#!/usr/bin/env python
from selenium import webdriver
import unittest
import time

# Local modules
from init import get_config
from chromedriver_video import Video

# Get configuration options
CFG = get_config()


class AmIndVideoPlay(unittest.TestCase):
    """Test the video playback on the American Indian exhibit kiosks

    Extends the unittest class. Any methods starting with test_ will better
    run as tests.
    """

    def setUp(self):
        """Setup the Chome browser for testing """
        options = webdriver.ChromeOptions()

        # Define a custom User Agent
        user_agent = '--user-agent="' + CFG['user_agent'] + '"'
        options.add_argument(user_agent)

        # Setup the full screen kiosk
        if CFG['kiosk']:
            options.add_argument('--kiosk')