Beispiel #1
0
class RCScreenApp(App):
    """
    Responsible for the whole client's application.
    """
    screen_image_format = StringProperty(DEFAULT_SCREEN_IMAGE_FORMAT)
    username = StringProperty("")
    password = StringProperty("")
    # TODO: can connect_screen handle this?
    is_controller = BooleanProperty(True)
    # TODO: can connect_screen handle this?
    partner = StringProperty("")
    connection_manager = ObjectProperty(ConnectionManager())
    x_sensitivity = NumericProperty(10, min=0)
    y_sensitivity = NumericProperty(10, min=0)
    screen_size = ListProperty()
    other_screen_width = NumericProperty(0)
    other_screen_height = NumericProperty(0)

    def on_stop(self):
        """
        Close connection_manager
        """
        if self.connection_manager.running:
            self.connection_manager.close()

    def build(self):
        """
        when the app is created
        """
        try:
            self.icon = ICON_PATH
        except Exception as e:
            print(e)
        return super().build()
Beispiel #2
0
    def __init__(self):
        LOG.debug("JellyfinClient initializing...")

        self.config = Config()
        self.http = HTTP(self)
        self.wsc = WSClient(self)
        self.auth = ConnectionManager(self)
        self.jellyfin = api.API(self.http)
        self.callback_ws = callback
        self.callback = callback
Beispiel #3
0
def Initialize(port, functionMap={}, asyncHandler=None):
    '''
    
    Initializes BlackBoard with the corresponding parameters.
    
    :param int port: The port through which BlackBoard will communicate with this module.
    :param dictionary functionMap: A dictionary containing **key:value** pairs, where the *key* is the name of a command received (a string),
        and the *value* is either a tuple containing a function as a first element and a boolean as a second element, or a function.
        The function in both cases is the function that is going to execute the specified command and receives on object of type :class:`Command` (See :ref:`Creating a command handler <creating_a_command_handler>`).
        The boolean value indicates whether the execution of that command should be synchronous (on the same thread) or asynchronous,
        usually synchronous execution is preferred for fast commands that can answer almost immediately and asynchronous for commands that might take a little time.
        When the value is only a function, by default the execution is synchronous. *functionMap* can also contain an entry with a string containing only an asterisk,
        meaning that would be the handler in case no other handler is found for a specific command.
        
        .. note::

            Notice that although functionMap can include a wildcard handler and this might seem like the module could answer
            anything, BlackBoard will only send commands that are registered under this module's configuration.
        
    :param function asyncHandler: A function that would handle the response of commands when sent with the method :func:`Send`
        instead of using :func:`SendAndWait`. This means the execution of a program that sends a command could continue
        and an asynchronous handler would handle the response when one is received.

        .. note::
    
            Notice that the asyncHandler functionality could also be achieved using a :class:`ParallelSender` object,
            but it has other implications.
    
    '''
    global _executors, _connMan, _parser, _p, _initialized, _ready

    _executors = {
        'busy': (lambda x: Response('busy'), False),
        'ready': (_isReady, False),
        'alive': (lambda x: Response('alive', True), False)
    }

    for m in functionMap:
        if isinstance(functionMap[m], types.FunctionType):
            _executors[m] = (functionMap[m], False)
        elif isinstance(functionMap[m], tuple):
            _executors[m] = functionMap[m]
        else:
            print 'Element in function map is not a function nor a correct tuple: ' + repr(
                functionMap[m])

    _connMan = ConnectionManager(port)
    _parser = CommandParser(asyncHandler)

    _p = threading.Thread(target=_MainThread)
    _p.daemon = True

    _initialized = True
Beispiel #4
0
    def __init__(self, main_window, port, service_id):
        super().__init__()
        self.main_window = main_window
        #ConnectionManager (create Slots)
        self.connection_manager = ConnectionManager(port, service_id)
        self.message_manager = MessageManager(self.connection_manager,
                                              service_id)
        self.message_manager.signal_message_received.connect(self.print_string)
        self.message_manager.signal_election_responded.connect(
            self.set_election)
        self.message_manager.signal_leader_responded.connect(
            self.leader_has_been_found)
        self.message_manager.signal_has_message_to_send.connect(
            self.send_udp_message)
        self.message_manager.signal_leader_alive.connect(self.set_alive)

        data = {"port": str(port), "leader": "Null"}
        jdata = json.dumps(data)
        self.main_window.set_details(jdata)
        self.main_window.signal_has_message_to_send.connect(
            self.send_udp_message)
        self.main_window.signal_has_multicast_to_send.connect(
            self.send_multicast_message)
        self.main_window.signal_start_checking.connect(self.close)

        self.own_port = port
        self.service_id = service_id
        self.leader_ip = None
        self.leader_port = 0
        self.leader_id = " "
        self.election = True
        self.leader_alive = False
        self.iam_leader = False

        self.control_boolean = False
        self.alive_checker_thread = AliveChecker(self, self.leader_ip,
                                                 self.leader_port,
                                                 self.connection_manager)
        self.alive_checker_thread.signal_election_is_due.connect(
            self.do_election)
        self.message_manager.signal_received_ok.connect(self.receive_ok)
        self.message_manager.signal_critical_request.connect(
            self.receive_request)

        self.worker_controller = WorkerController(1)
        self.worker_controller.signal_request_critical.connect(
            self.request_critical)
        self.worker_controller.signal_send_free_message.connect(
            self.send_free_message)
        #do first multicast
        self.th = th.Thread(target=self.request_group)
        self.th.start()
Beispiel #5
0
    def __init__(self, port):
        super(AWSIOTDeviceAdapter, self).__init__()

        self.set_config('default_timeout', 5.0)

        reg = ComponentRegistry()
        endpoint = reg.get_config('awsiot-endpoint')
        rootcert = reg.get_config('awsiot-rootcert')
        iamuser = reg.get_config('awsiot-iamkey')
        iamsecret = reg.get_config('awsiot-iamtoken')
        iamsession = reg.get_config('awsiot-session', default=None)

        args = {}
        args['endpoint'] = endpoint
        args['root_certificate'] = rootcert
        args['use_websockets'] = True
        args['iam_key'] = iamuser
        args['iam_secret'] = iamsecret
        args['iam_session'] = iamsession

        self._logger = logging.getLogger(__name__)

        # Port should be a topic prefix that allows us to connect
        # only to subset of IOTile devices managed by a gateway
        # rather than to directly accessible iotile devices.
        if port is None:
            port = ""

        if len(port) > 0 and port[-1] != '/':
            port = port + '/'

        self.client = OrderedAWSIOTClient(args)
        self.name = str(uuid.uuid4())
        self.client.connect(self.name)
        self.prefix = port

        self.conns = ConnectionManager(self.id)
        self.conns.start()

        self.client.subscribe(self.prefix + 'devices/+/data/advertisement',
                              self._on_advertisement,
                              ordered=False)

        self._deferred = queue.Queue()

        self.set_config('minimum_scan_time', 5.0)
        self.set_config('probe_supported', True)
        self.set_config('probe_required', True)
        self.mtu = self.get_config(
            'mtu', 60 * 1024)  # Split script payloads larger than this
Beispiel #6
0
 def __init__(self):
     self.logger = logging.getLogger('backdoor')
     self.logger.setLevel(logging.DEBUG)
     ch = logging.StreamHandler()
     ch.setLevel(logging.DEBUG)
     formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
     ch.setFormatter(formatter)
     self.logger.addHandler(ch)
     self.logger.info('Starting backdoor.')
     signal.signal(signal.SIGINT, self.stop)
     self.running = True
     self.connection_manager = ConnectionManager(config.api_host, config.api_port)
     self.connection_manager.start()
     self.methods = {}
     self.services = []
     self.load_services()
Beispiel #7
0
    def setUp(self):
        httpretty.enable()
        create_environment()
        make_fake_dir()
        with open(CONFIG_FILEPATH, 'r') as fo:
            self.cfg = json.load(fo)

        self.auth = (self.cfg['user'], self.cfg['pass'])
        self.base_url = ''.join(
            [self.cfg['server_address'], self.cfg['api_suffix']])
        self.files_url = ''.join([self.base_url, 'files/'])
        self.actions_url = ''.join([self.base_url, 'actions/'])
        self.shares_url = ''.join([self.base_url, 'shares/'])
        self.user_url = ''.join([self.base_url, 'users/'])

        self.cm = ConnectionManager(self.cfg)
Beispiel #8
0
    def __init__(self, my_port, node_host=None, node_port=None):
        self.my_ip = self.__get_myip()
        print('Server IP address is set to ... ', self.my_ip)
        self.my_port = my_port
        self.cm = ConnectionManager(self.my_ip, self.my_port, self.__handle_message)
        self.node_host = node_host
        self.node_port = node_port
        self.bm = BlockchainManager()
        self.tp = TransactionPool()

        self.clock = 0
        self.status = STATUS_IDLE
        self.next_status = STATUS_IDLE
        self.new_txs = []
        self.end_mining_clock = None
        self.new_block = None
        self.to_port = None
def main():
    config = ConfigParser()
    config.read("config.ini")

    cm_config = {
        "host": config.get("SQL", "host_address"),
        "port": config.getint("SQL", "port"),
        "user": "",
        "passwd": "",
        "database": config.get("SQL", "database"),
    }

    cm = ConnectionManager(cm_config)
    ui = UserInterface(cm)
    try:
        ui.start()
    except Exception as e:
        print(e)
def main():
    main_app = FastAPI()

    manager = ConnectionManager()

    @main_app.websocket("/ws/{client_id}")
    async def websocket_endpoint(websocket: WebSocket, client_id: UUID4):
        await manager.connect(websocket, client_id)
        try:
            while True:
                ws_data = await websocket.receive_text()
                message = Message(sender_id=client_id, **json.loads(ws_data))
                print(f'User {message.sender_id} sends to user {message.receiver_id} the message {message.text}')
                await manager.send_personal_message(message)
                await manager.send_message_to_target(message)
        except WebSocketDisconnect:
            manager.disconnect(websocket, client_id)

    return main_app
#!/usr/bin/env python
import rospy
from connection_manager import ConnectionManager

rospy.init_node('server_connector')
rospy.loginfo('Starting!')

server_ip = rospy.get_param('server_ip', '54.161.15.175')
server_port = 9090
connection_manager = ConnectionManager(server_ip, server_port, 'hexacopter')
connection_manager.attempt_connection()

r = rospy.Rate(20)
while not rospy.is_shutdown():
    r.sleep()

connection_manager.stop_connection()
Beispiel #12
0
 def __init__(self, connectionStr):
     self.connMgr = ConnectionManager()
     self.conn = self.connMgr.connectToDatabase(connectionStr)
     self.cur = self.conn.cursor()
     self.fdm = ForeignDataManager()
     self.cur.execute("set work_mem to %s", (self.WORK_MEM, ))
Beispiel #13
0
 def __init__(self, connection_manager=ConnectionManager()):
     self.connection_manager = connection_manager
     self.exchange_initialize()
     self.channel_initialize()
def sahibinden_scraper(num_page):
    """
    Web scraper for sahibinden.com
    param num_page: number of page that wanted to be scraped
    """
    cm = ConnectionManager()
    start_time = time.time()
    data_ids = []
    seller_names = []
    seller_links = []
    ad_titles = []
    ad_links = []
    prices = []
    counties = []
    districts = []
    other_items = [
    ]  # this is a container list for attirbutes like date, area, room, floor within building, etc.

    diff = num_page - 2
    last = ((diff * 20) + 20) + 1

    for t in range(0, last, 20):
        url = 'https://www.sahibinden.com/kiralik-daire/antalya?pagingOffset=' + str(
            t)
        r = cm.request(url)
        status_code = r.code if r != '' else -1  # Status code of request.
        if status_code == 200:
            so = bs4.BeautifulSoup(r.read(), 'lxml')
            table = so.find('table', id='searchResultsTable')

            tracker = 0
            requests = 0
            for i in table.findAll('tr'):

                if i.get(
                        'data-id'
                ) is None:  # means it is not a home ad. Maybe just a google ad.
                    continue  # ignore these data points

                else:  # if data points are home ads
                    ids = i.get('data-id')
                    names_seller = [
                        _.get('title') for _ in (i.find_all(
                            'a', attrs={'class': 'titleIcon store-icon'}))
                    ]
                    links_seller = [
                        _.get('href') for _ in (i.find_all(
                            'a', attrs={'class': 'titleIcon store-icon'}))
                    ]
                    titles_ad = [
                        ' '.join(_.text.split())
                        for _ in i.find_all('a',
                                            attrs={'class': 'classifiedTitle'})
                    ]
                    links_ad = [
                        'https://www.sahibinden.com' + _.get('href')
                        for _ in i.find_all('a',
                                            attrs={'class': 'classifiedTitle'})
                    ]

                    data_ids.append(ids)
                    seller_names.append(names_seller)
                    seller_links.append(links_seller)
                    ad_titles.append(titles_ad)
                    ad_links.append(links_ad)

                    #finding prices corresponding to ads
                    for z in i.find_all(
                            'td', attrs={'class': 'searchResultsPriceValue'}):
                        price = ' '.join(z.text.split())

                        if '.' in price:  # if price is like 7.100

                            # convert it to 7100 and keep it in 'prices' list
                            prices.append(price.replace('.', ''))

                        else:  # if it is not, just put it to the 'prices' list
                            prices.append(price)

                    # finding addresses corresponding to ads
                    for f in i.findAll(
                            'td',
                            attrs={'class': 'searchResultsLocationValue'}):
                        turkish_adress_name = ''.join(f.text.split(
                        ))  # name of county and district in Turkish

                        #converting Turkish charecters to English charecters
                        normalized = unicodedata.normalize(
                            'NFD', turkish_adress_name)
                        #converted_adress_name consists of county and district names.
                        converted_adress_name = u"".join([
                            c for c in normalized
                            if not unicodedata.combining(c)
                        ])

                        #first_letters is a list consists of first letters of county and district names. For example: ['M', 'F']
                        first_letters = re.findall('[A-Z]+',
                                                   converted_adress_name)

                        # if district name is not specified, then 'first_letters' will contain only one letter, like ['A']
                        try:
                            # first_letters[1] is a district name
                            # first_letters[0] is a county name
                            districts.append(converted_adress_name[
                                converted_adress_name.
                                find(first_letters[1], 1):])
                            counties.append(converted_adress_name[
                                converted_adress_name.
                                find(first_letters[0], 0):converted_adress_name
                                .find(first_letters[1], 1)])

                        except:  # index error
                            # it will occur, if first_letters includes only one letter.
                            # if district is not specified, put county name both district and county containers.
                            counties.append(
                                converted_adress_name[converted_adress_name.
                                                      find(first_letters[0]):])
                            districts.append(
                                converted_adress_name[converted_adress_name.
                                                      find(first_letters[0]):])

                    # finding other data points like date of ad, number of rooms, total area, floor within building etc.
                    # to do this, i will iterate through all of advertisement links
                    for y in links_ad:
                        start_time = time.time()
                        ur = cm.request(y)
                        tracker += 1
                        time.sleep(random.randint(2, 6))
                        requests += 1
                        elapsed_time = time.time() - start_time
                        print(
                            'Request:{}; Frequency: {} requests/s; elapsed time:{}'
                            .format(requests, requests / elapsed_time,
                                    elapsed_time))

                        soup = bs4.BeautifulSoup(ur.read(), 'lxml')
                        info = soup.find('div',
                                         attrs={'class': 'classifiedInfo'
                                                })  # attributes of ads

                        dct = {
                        }  # this will contain column names as keys, and data points as values.
                        for v in info.findAll('ul'):
                            head = v.find_all(
                                'strong'
                            )  # name of columns. i.e. 'number_of_rooms' column.
                            attribute = v.find_all(
                                'span'
                            )  # value corresponds to above particular column. i.e. (3+1)

                            for a, b in zip(head, attribute):
                                columns = ' '.join(a.text.split())
                                data = ' '.join(b.text.split())
                                dct[columns] = data

                        print(tracker)
                        if tracker % 5 == 0:
                            cm.new_identity(
                            )  # After sending 5 requests, change identity in order to avoid being blocked.

                        other_items.append(pd.DataFrame(data=dct, index=[0]))
            print('done')

        else:  # If status code of request is not 200.
            break

    print("--- %s seconds ---" % (time.time() - strt))
    return other_items, data_ids, ad_titles, ad_links, seller_names, seller_links, prices, counties, districts
def hurriyetemlak_scraper(page_num):
    cm = ConnectionManager(
    )  # instance of connection manager object. This will be used for changing identity
    start_time = time.time()
    data = [
    ]  # list that contains all of the home attirbutes like numbe of rooms, building age, net area etc.
    last = page_num + 1
    page_tracker = 0

    for t in range(0, last):

        url = 'https://www.hurriyetemlak.com/antalya-kiralik/daire?page={}'.format(
            t)
        rr = cm.request(url)
        # status code of request.
        status_code = rr.code if rr != '' else -1

        if status_code == 200:
            soup = bs4.BeautifulSoup(rr.read(), 'lxml')
            page_tracker += 1
            #         links = []
            #         for i in soup.findAll('div', attrs={'class':'list-item timeshare clearfix'}):
            #             attrs = i.find('a')
            #             links.append('https://www.hurriyetemlak.com'+attrs.get('href'))

            # above commented code is first verison of script for getting home advertisement links
            # this code is a map verison of that for speed issiue.
            links = list(
                map(
                    lambda x: 'https://www.hurriyetemlak.com' + x.find('a').
                    get('href'),
                    soup.findAll(
                        'div', attrs={'class':
                                      'list-item timeshare clearfix'})))

        else:
            print('Request failed.')
            break

        tracker = 0
        requests = 0  # to track number of requesets that has been successfully sent to website.
        for _ in links:
            start_time = time.time()
            r = cm.request(_)
            tracker += 1
            # in order to avoid overloading website, wait between 2 and 7 seconds for each iteration.
            time.sleep(random.randint(2, 7))
            requests += 1
            elapsed_time = time.time() - start_time
            print(
                'Request:{}; Frequency: {} requests/s; elapsed time:{}'.format(
                    requests, requests / elapsed_time, elapsed_time))

            stat_code = r.code if r != '' else -1  # status code of request.
            if stat_code == 200:
                so = bs4.BeautifulSoup(r.read(), 'lxml')
                #lists of attributes of home ads that also includes html tags.
                raw_items = [
                    b.find_all('span')
                    for f in so.findAll('li', attrs={'class': 'info-line'})
                    for b in f.findAll('li')
                ]
            else:
                print('Request failed')
                break

            print(tracker)
            if tracker % 5 == 0:
                cm.new_identity()

            revised_items = []
            for r in raw_items:
                revised_items.append(r)
                # if this particular element is just empty list.
                if str(r) == '[]':
                    break

            dct = {
            }  # dictionary contains column names as keys and values of that columns as values.

            for i in revised_items[:
                                   -1]:  # last element of revised_items list is just empty list. ignore it.
                try:
                    # names of attributes corresponds to particular home ad.
                    col = str(i[0]).split('>')[1].split('<')[0]
                    # values of above attirbutes.
                    row = str(i[1]).split('>')[1].split('<')[0]
                    dct[col] = row

                    # id_col and id_row are id of particular home ad.
                    id_col = so.find('li', attrs={
                        'class': 'realty-numb'
                    }).text.replace('\n', '', 3).split(':')[0]
                    id_row = so.find('li', attrs={
                        'class': 'realty-numb'
                    }).text.replace('\n', '', 3).split(':')[1]
                    dct[id_col] = id_row
                    # title of particular home ad.
                    title = so.find('h1', attrs={
                        'class': 'details-header'
                    }).text
                    dct['Title'] = title
                    # price of particular home ad.
                    price = so.find('li',
                                    attrs={
                                        'class': 'price-line clearfix'
                                    }).text.replace('\n', '', 3)
                    dct['price'] = price
                except:
                    continue
            # list of pandas dataframes.
            data.append(pd.DataFrame(dct, index=[0]))

            delays = [0.5, 1, 1.5, 2, 2.5, 3]
            time.sleep(
                np.random.choice(delays))  # to avoid overloading website.

        print("page {} is done".format(page_tracker))

    print(time.time() - strt_time)
    return data
from background_monitor import BackgroundMonitor
from database import Database
from connection_manager import ConnectionManager
from config import SERVER_URL

if __name__ == '__main__':
    connection_manager = ConnectionManager(SERVER_URL)
    connection_manager.authorize()
    database = Database(connection_manager)

    background_monitor = BackgroundMonitor(database)
    background_monitor.run()
Beispiel #17
0
 def __init__(self):
     self.connection_manager = ConnectionManager()
     env_location = pkg_resources.resource_filename('resources', '.env')
     if os.environ.get('DOTENV_LOADED', '0') != '1':
         load_dotenv(env_location)
     self.personal = os.environ.get("BLAKE2D_KEY", "topsecretkey").encode()
Beispiel #18
0
import json
import os.path
import time
from sanic.log import logger
from connection_manager import ConnectionManager

log_params = sanic.log.LOGGING_CONFIG_DEFAULTS
fname = time.asctime().replace(' ', '_').replace(':', '') + '.log'
for h in log_params['handlers']:
    if 'stream' in log_params['handlers'][h]:
        del log_params['handlers'][h]['stream']
        log_params['handlers'][h]['class'] = 'logging.FileHandler'
    log_params['handlers'][h]['filename'] = os.path.join(
        '..', 'server_logs', fname)

CM = ConnectionManager()
kv_server = sanic.Sanic(log_config=log_params)


async def check_exist(kid):
    conn = await CM.get_connection()
    retval = (1, sanic.response.HTTPResponse(status=404))

    try:
        logger.info(f'Searching for pair, key: "{kid}"')
        res = await conn.select('kv', key=[kid], index='primary')
        if len(res) != 0:
            logger.info(
                f'Found pair, key: "{kid}", value: "{res[0]["value"]}"')
            retval = (0, sanic.response.json(res[0]['value']))
        else:
Beispiel #19
0
# Author hirata
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from db import database
from routes.users import router as userrouter
from routes.chats import router as chatrouter
from routes.invites import router as invitesrouter
from routes.timelines import router as timelinesrouter
from routes.chat_rooms import router as chat_room_router
from starlette.requests import Request
from starlette.middleware.cors import CORSMiddleware
from connection_manager import ConnectionManager
import json

app = FastAPI()
manager = ConnectionManager()

app.add_middleware(CORSMiddleware,
                   allow_origins=["*"],
                   allow_credentials=True,
                   allow_methods=["*"],
                   allow_headers=["*"])


# 起動時にDatabaseに接続する。
@app.on_event("startup")
async def startup():
    await database.connect()


# 終了時にDatabaseを切断する。
@app.on_event("shutdown")
Beispiel #20
0
	def __init__(self, connectionStr):
		self.connMgr = ConnectionManager()
		self.conn = self.connMgr.connectToDatabase(connectionStr)
		self.cur = self.conn.cursor()
		self.fdm = ForeignDataManager()