Beispiel #1
0
	def connection(ip = "0.0.0.0", port = 19132):
		s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		bind = s.bind(ip, port)
		    if not bind:
		    	logger.warning("Couldn't bind to "+ ip +":"+port)
		    	time.sleep(5)
		    	sys.exit(0)
Beispiel #2
0
def open_room(data):
    logger.warning(f'Open room: {data}')
    uids = data['userIds']
    uids.sort()
    logger.warning(f'uids: {uids}')
    room_name = ''.join(str(uid) for uid in uids)
    chat = dbChat.query.filter(dbChat.room_name == room_name).first()
    if not chat:
        chat = dbChat(room_name=room_name)
    db.session.add(chat)
    user_dicts, user_ips = [], []
    for id in uids:
        user = dbUser.query.filter(dbUser.id == id).first()
        user_dicts.append(user.resp_dict(follows=False))
        user.chats.append(chat)
        user_ips.append(user.last_ip)
        db.session.add(user)
    db.session.commit()
    join_room(room_name)
    ip = request.remote_addr
    user_ips.append(ip)
    ips = set(user_ips)
    for ip in ips:
        if ip:
            emit('room_opened',
                 {'chat': chat.resp_dict(exceptID=data['fromId'])},
                 room=ip)
Beispiel #3
0
def message(data):
    logger.warning(f'new message data! {data}')
    message = dbMessage(body=data['body'],
                        timestamp=datetime.datetime.fromtimestamp(
                            data['timestamp'] / 1e3),
                        author_id=data['authorId'])
    db.session.add(message)
    chat = dbChat.query.filter(dbChat.room_name == data['roomName']).first()
    if chat:
        chat.messages.append(message)
        db.session.add(chat)
    db.session.commit()
    emit('message', data, room=data['roomName'])
Beispiel #4
0
 def get(self):
     query = dict(request.args)['searchQuery']
     split_query = query.split()
     tags = [w.replace('#', '') for w in split_query if w.startswith('#')]
     usernames = [
         w.replace('@', '') for w in split_query if w.startswith('@')
     ]
     terms = [
         r.strip() for r in ' '.join([
             w for w in split_query
             if not (w.startswith('@') or w.startswith('#'))
         ]).split(',') if r.strip()
     ]
     posts = []
     for term in terms:
         logger.warning(f'term: {term}')
         term_posts = dbPost.query.filter(
             or_(dbPost.title.like(f'%{term}%'),
                 dbPost.desc.like(f'%{term}%'))).all()
         posts += [post.resp_dict() for post in term_posts]
     for tag in tags:
         logger.warning(f'tag: {tag}')
         tag_posts = dbPost.query.filter(
             dbPost.tags.any(dbTag.name == tag)).all()
         posts += [post.resp_dict() for post in tag_posts]
     for username in usernames:
         logger.warning(f'username: {username}')
         user_posts = dbPost.query.join(
             dbUser, dbPost.author_id == dbUser.id).add_columns(
                 dbUser.username).filter(dbUser.username == username).all()
         posts += [post.resp_dict() for post, _ in user_posts]
     return {'status': 'success', 'posts': posts}, 200
Beispiel #5
0
def user_auth(data):
    logger.warning(f'User {data["userId"]} attempting auth')
    decode_response = dbUser.decode_auth_token(data["authToken"])
    ip = request.remote_addr
    join_room(ip)
    if data["userId"] == decode_response:
        logger.warning('AUTHENTICATED :D')
        user = dbUser.query.filter(dbUser.id == decode_response).first()
        if user:
            for chat in user.chats:
                join_room(chat.room_name)
            user.last_ip = ip
            db.session.add(user)
            db.session.commit()
        emit('user_connected', {
            'message':
            'connected',
            'chats':
            [chat.resp_dict(exceptID=decode_response) for chat in user.chats],
        },
             room=ip)
    else:
        emit('reject', {'message': 'Please log back in!'}, room=ip)
        logger.warning('NOT AUTHENTICATED >:(')
        return False
Beispiel #6
0
def start_scrape():
    if config['use_proxy']:
        proxies.update_proxies()

    file_name = 'Template.csv'
    file_path = path.join(path.dirname(__file__),
                          f'{project_path}/results/{file_name}')

    try:
        store = pd.read_csv(file_path)
    except Exception as e:
        logger.warning(f'Could not load store, {e}')
        store = pd.DataFrame()
    process = CrawlerProcess(custom_settings)
    kwargs = {
        'file_name': 'template.csv',
        'file_path': file_path,
        'store': store,
        'use_selenium': False
    }
    process.crawl(TemplateSelSpider, **kwargs)
    process.start()
Beispiel #7
0
	def get(self):
		authenticated = check_auth(request)
		try:
			data = dict(request.args)
			logger.info(f"User get data[{type(data)}]: {data}")
			user = dbUser.query.filter_by(**data).first()
			logger.warning(f'authenticated: {authenticated}')
			if isinstance(authenticated, int):
				same_user = authenticated == user.id
				return {
					'status': 'success',
					'user': user.resp_dict(include_private=same_user),
				}, 200
			else:
				return {
					'status': 'success',
					'user': user.resp_dict()
				}, 200
		except Exception as e:
			logger.error(e)
			return {
				'status': 'fail',
				'message': 'An error has occurred',
			}, 401
Beispiel #8
0
 def closed(reason):
     logger.warning(f'{TemplateSelSpider.name} spider closed:{reason}')