Beispiel #1
0
def main():
    s3_client = S3Client(
        os.environ.get('s3_url'),
        os.environ.get('s3_access_key'),
        os.environ.get('s3_secret_key'),
        os.environ.get('s3_bucket'),
    )

    pg_client = PgClient(host=os.environ.get('pg_host'),
                         port=os.environ.get('pg_port'),
                         user=os.environ.get('pg_user'),
                         passwd=os.environ.get('pg_pass'),
                         db=os.environ.get('pg_db'))
    admin_users = os.environ.get('admin_users').split(',')
    processor = Processor(s3_client, pg_client, admin_users)
    """Start the bot."""
    # Create the Updater and pass it your bot's token.
    updater = Updater(
        os.environ.get('bot_key'),
        use_context=True,
    )

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler(Filters.sticker, processor.filter))

    # Start the Bot
    updater.start_polling()

    # Run the bot until you press Ctrl-C or the process receives SIGINT,
    # SIGTERM or SIGABRT. This should be used most of the time, since
    # start_polling() is non-blocking and will stop the bot gracefully.
    updater.idle()
Beispiel #2
0
    def post(cls, mp3_key):
        validator = Validator()
        validation_schema = {
            'wav_target_key': {
                'type': 'string',
                'required': True
            }
        }

        if not validator.validate(request.json or {}, validation_schema):
            return jsonify(validator.errors), 400

        client = S3Client()

        mp3_tmp = client.download_file(mp3_key)
        if not mp3_tmp:
            return jsonify({'error': 'File is missing.'}), 404

        mp3 = AudioSegment.from_mp3(mp3_tmp)

        wav_tmp = cls.storage_path % uuid4().hex
        mp3.export(wav_tmp, format="wav")
        wav = AudioSegment.from_wav(wav_tmp)

        client.upload_file(wav_tmp, request.json.get('wav_target_key'))

        return jsonify({
            'file_size': os.path.getsize(wav_tmp),
            'execution_time': wav.duration_seconds
        }), 201
 def tearDownClass(cls):
     s3_region = rospy.get_param(
         '/s3_file_uploader/aws_client_configuration/region')
     s3 = S3Client(s3_region)
     s3_bucket_name = rospy.get_param('/s3_file_uploader/s3_bucket')
     s3.delete_all_objects(s3_bucket_name)
     s3.delete_bucket(s3_bucket_name)
 def setUpClass(cls):
     rospy.init_node(TEST_NODE_NAME, log_level=rospy.DEBUG)
     s3_region = rospy.get_param(
         '/s3_file_uploader/aws_client_configuration/region')
     s3 = S3Client(s3_region)
     s3_bucket_name = rospy.get_param('/s3_file_uploader/s3_bucket')
     s3.create_bucket(s3_bucket_name)
     s3.wait_for_bucket_create(s3_bucket_name)
Beispiel #5
0
 def setUp(self):
     self.action_client = None
     self.s3_bucket = rospy.get_param('/s3_file_uploader/s3_bucket')
     self.s3_region = S3FileUploaderTestBase.extract_s3_region()
     self.s3_client = S3Client(self.s3_region)
     self.s3_key_prefix = 'foo/bar'
     self.objects_to_delete = []
     self.files_to_delete = []
Beispiel #6
0
    def test_record_specific_topic(self):
        start_time = time.time()
        topic_name = '/my_random_topic_' + create_random_word(8) 
        duration = 5
        interval = 0.1
        total_test_messages = 10

        # Publish some data to the topic before recording is not started.
        # This data SHOULD NOT be recorded into the rosbag
        self.publish_periodic_data_to_topic(topic_name, interval, total_test_messages)

        # Start the duration recorder for `duration` seconds
        goal = DurationRecorderGoal(
            duration=rospy.Duration.from_sec(duration),
            topics_to_record=[topic_name]
        )
        self.action_client.send_goal(goal)

        # Wait for duration recorder to start recording
        time.sleep(0.5)

        # Publish some data to that topic
        self.publish_periodic_data_to_topic(topic_name, interval, total_test_messages)

        # Wait for the duration recorder to finish
        self.action_client.wait_for_result(rospy.Duration.from_sec(10.0))
        action_result = self.action_client.get_result()

        # Publish some data to the topic after recording has finished
        # This data SHOULD NOT be recorded into the rosbag
        self.publish_periodic_data_to_topic(topic_name, interval, total_test_messages)

        # Ensure the duration recorder created the bag correctly
        self.assertEquals(action_result.result.result, RESULT_CODE_SUCCESS)
        self.check_rosbags_were_recorded(start_time, 1)

        # Ensure that the rosbag contains all the test messages
        latest_bag = self.get_latest_bag_by_regex("*.bag")
        total_topic_messages = 0
        bag = rosbag.Bag(latest_bag)
        for topic, msg, _ in bag.read_messages():
            if topic == topic_name:
                total_topic_messages += 1
        self.assertEquals(total_topic_messages, total_test_messages)

        # Ensure that the rosbag uploaded to S3 contains all the test messages
        s3_region = rospy.get_param('/s3_file_uploader/aws_client_configuration/region')
        s3_client = S3Client(s3_region)
        s3_bucket_name = rospy.get_param('/s3_file_uploader/s3_bucket')
        s3_key = os.path.basename(latest_bag)
        with tempfile.NamedTemporaryFile() as f:
            s3_client.download_file(s3_bucket_name, s3_key, f.name)
            total_topic_messages = 0
            bag = rosbag.Bag(f.name)
            for topic, msg, _ in bag.read_messages():
                if topic == topic_name:
                    total_topic_messages += 1
            self.assertEquals(total_topic_messages, total_test_messages)
Beispiel #7
0
    def setUp(self):
        self.s3_bucket = Mock()
        self.hex = 'hex'

        self.client = S3Client()
        self.client.s3 = Mock()
        self.client.s3.Bucket.return_value = self.s3_bucket

        self.uuid_patch = patch('s3_client.uuid4')
        self.uuid_mock = self.uuid_patch.start()
        self.uuid_mock.return_value = Mock(hex=self.hex)
Beispiel #8
0
    def get(cls, wav_key):
        tmp_name = S3Client().download_file(wav_key)

        if not tmp_name:
            return jsonify({'error': 'File is missing.'}), 404

        wav = AudioSegment.from_wav(tmp_name)

        return jsonify({
            'channels_count': wav.channels,
            'sample_rate': wav.frame_rate,
            'execution_time': wav.duration_seconds
        })
Beispiel #9
0
 def __init__(self, logger, aws_key_id=None, aws_access_secret=None, region_name=None):
     self.aws_key_id = aws_key_id
     self.aws_access_secret = aws_access_secret
     self.iam_client = IamClient(aws_key_id, aws_access_secret, region_name, logger)
     self.ec2_client = EC2Client(aws_key_id, aws_access_secret, region_name, logger)
     self.s3_client = S3Client(aws_key_id, aws_access_secret, region_name, logger)
     self.elbv2_client = ELBV2Client(aws_key_id, aws_access_secret, region_name, logger)
     self.elb_client = ELBClient(aws_key_id, aws_access_secret, region_name, logger)
     self.rds_client = RDSClient(aws_key_id, aws_access_secret, region_name, logger)
     self.route53_client = Route53Client(aws_key_id, aws_access_secret, region_name, logger)
     self.policies = []
     self.ec2_instances = []
     self.s3_buckets = []
     self.load_balancers = []
     self.classic_load_balancers = []
     self.hosted_zones = []
     self.users = []
     self.databases = []
     self.security_groups = []
     self.target_groups = []
Beispiel #10
0
 def send(self):
     from collection.message import Message
     from flask import request
     if request.content_type.startswith("application/json"):
         message = Message(**request.get_json())
     else:
         message = Message(**request.form.to_dict())
     s3_client = S3Client(request=request)
     try:
         form_name = next(request.files.keys())
         s3_url = s3_client.upload_file(form_name)
         message.set("url", s3_url)
         message.set("type", request.files[form_name].content_type)
     except StopIteration as e:
         print(e)
     finally:
         object_id = MongoClient(collection="message").insert_one(message)
         user_query = MongoClient(collection="user").retrive(
             {"user_id": message.source})
         if len(user_query) > 0:
             user = user_query.pop(0)
             from collection.user import User
             user = User(**user)
             user.add_message(object_id)
             MongoClient(collection="user").update(
                 {"user_id": message.source},
                 {"$set": {
                     "messages": user.messages
                 }})
         else:
             from service.register import Register
             from collection.user import User
             user = User()
             user.set("user_id", message.source)
             user.add_message(object_id)
             Register().insert_after(user)
def upload_file(filename):
    s3 = S3Client()
    bucket_name = 'phucbb'
    s3.upload_file(bucket_name, filename, prefix='experiments/')
    print("Done")
Beispiel #12
0
 def tearDownClass(cls):
     s3 = S3Client(cls.extract_s3_region())
     s3_bucket_name = rospy.get_param('/s3_file_uploader/s3_bucket')
     s3.delete_bucket(s3_bucket_name)
Beispiel #13
0
 def setUpClass(cls):
     rospy.init_node(TEST_NODE_NAME, log_level=rospy.DEBUG)
     s3 = S3Client(cls.extract_s3_region())
     s3_bucket_name = rospy.get_param('/s3_file_uploader/s3_bucket')
     s3.create_bucket(s3_bucket_name)
     s3.wait_for_bucket_create(s3_bucket_name)