Beispiel #1
0
 def make_request(self):
     response = requests.post(
         "https://www.skyscanner.es/g/conductor/v1/fps3/search/",
         params=get_params(),
         headers=get_headers(),
         data=get_request_data(self.day, self.iata))
     self.data, self.status = response.content, response.status_code
     print(self.status)
Beispiel #2
0
def rotate_key_pair(event):
    log.debug(json.dumps(event, indent=2))
    params = get_params(event)
    key_name = get_parameter(params, 'Keyname', None)

    # Keyname is required.
    if key_name == None:
        return create_failure(event)
    
    delete_key_pair(event)
    return create_and_store_key_pair(event)
Beispiel #3
0
 def list_peer_info(self):  # 对端信息
     try:
         peer_data = common.get_params(
             dict(appversion=config.APP_VERSION, v="1", ct="1"),
             self.user_info.get("sessionid"), True)
         result = self.request_handler.get(config.LIST_PEER_URL + peer_data)
         if result.status_code == 200:
             temp = result.json()
             if temp.get("rtn") == 0:
                 self.user_info["all_peer_info"] = temp.get("result")
                 return True
     except Exception as error:
         logging.error("list_peer_info:{0}".format(error))
     return False
Beispiel #4
0
 def account_info(self):  # 账户信息
     try:
         account_data = common.get_params(
             {"appversion": config.APP_VERSION},
             self.user_info.get("sessionid"))
         result = self.request_handler.post(config.ACCOUNT_INFO_URL,
                                            data=account_data)
         if result.status_code == 200:
             temp = result.json()
             if temp.get("iRet") == 0:
                 self.user_info["account_info"] = temp.get("data")
                 return True
     except Exception as error:
         logging.error("account_info:{0}".format(error))
     return False
Beispiel #5
0
def delete_key_pair(event):
    log.debug(json.dumps(event, indent=2))

    params = get_params(event)
    s3_bucket = get_parameter(params, 'S3Bucket', None)
    s3_key = get_parameter(params, 'S3Key', None)
    key_name = get_parameter(params, 'Keyname', None)

    log.debug('Delete EC2 key pair:')
    response = ec2_client.delete_key_pair(KeyName=key_name)
    log.debug(json.dumps(response, indent=2))

    log.debug('Delete S3 pem file')
    response = s3_client.delete_object(Bucket=s3_bucket, Key=s3_key)
    log.debug(json.dumps(response, indent=2))
Beispiel #6
0
def handler(event, context):
    log.debug(json.dumps(event, indent=2))

    params = get_params(event)
    operation = get_parameter(params, 'Operation', None)
    s3_bucket = get_parameter(params, 'S3Bucket', None)
    s3_key = get_parameter(params, 'S3Key', None)

    # Operation, S3Bucket and S3Key are always required!
    if operation == None or s3_bucket == None or s3_key == None:
        return create_failure(event)

    if operation == 'CREATE':
        return create_and_store_key_pair(event)
    elif operation == 'ROTATE':
        return rotate_key_pair(event)

    return create_failure(event)
Beispiel #7
0
 def usb_info(self, deviceid=False):  # 获取任一对端挂载硬盘信息
     try:
         if not deviceid:
             deviceid = self.get_peer_device_id()
         peer_data = common.get_params(
             dict(appversion=config.APP_VERSION,
                  v="1",
                  ct="1",
                  deviceid=deviceid), self.user_info.get("sessionid"), True)
         result = self.request_handler.get(config.PEER_USB_INFO_URL +
                                           peer_data)
         if result.status_code == 200:
             temp = result.json()
             if temp.get("rtn") == 0:
                 self.user_info["usb_info"] = temp.get("result")
                 return True
     except Exception as error:
         logging.error("account_info:{0}".format(error))
     return False
Beispiel #8
0
    def remote_download_login(self, peerid=False):  # 远端下载登陆
        try:
            if not peerid:
                peerid = self.get_peer_id()

            remote_dl_data = common.get_params(
                dict(pid=peerid, appversion=config.APP_VERSION, v="1",
                     ct="32"), self.user_info.get("sessionid"), True)
            print(config.LOGIN_REMOTE_DOWNLOAD_URL + remote_dl_data)
            result = self.request_handler.get(
                config.LOGIN_REMOTE_DOWNLOAD_URL + remote_dl_data)
            if result.status_code == 200:
                temp = result.json()
                if temp.get("rtn") == 0:
                    del temp["rtn"]
                    self.user_info["remote_download_login"] = temp
                    return True
        except Exception as error:
            logging.error("list_remote_download:{0}".format(error))
        return False
def create_and_store_key_pair(event):
    log.debug(json.dumps(event, indent=2))

    fragment = event['fragment']
    params = get_params(event)
    s3_bucket = get_parameter(params, 'S3Bucket', None)
    s3_key = get_parameter(params, 'S3Key', None)
    key_name = get_parameter(params, 'Keyname', None)

    if key_name == None:
        key_name = generate_name(20)

    if not does_key_pair_exists(key_name):
        response = ec2_client.create_key_pair(KeyName=key_name)
        store_key_material(response, s3_bucket, s3_key)

    fragment = key_name

    return {
        'requestId': event['requestId'],
        'status': 'success',
        'fragment': fragment
    }
    extra_global_params=[("stimTimes", "scalar*")],
    injection_code=
        """
        scalar current = ($(gennrand_uniform) * $(n) * 2.0) - $(n);
        if($(startStim) != $(endStim) && $(t) >= $(stimTimes)[$(startStim)]) {
           current += $(stimMagnitude);
           $(startStim)++;
        }
        $(injectCurrent, current);
        """)

# ----------------------------------------------------------------------------
# Stimuli generation
# ----------------------------------------------------------------------------
# Get standard model parameters
params = get_params(build_model=True, measure_timing=False, use_genn_recording=True)
params["seed"] = 1234
if "seed" in params:
    np.random.seed(params["seed"])

# Generate stimuli sets of neuron IDs
num_cells = params["num_excitatory"] + params["num_inhibitory"]
stim_gen_start_time =  perf_counter()
input_sets = [np.random.choice(num_cells, params["stimuli_set_size"], replace=False)
              for _ in range(params["num_stimuli_sets"])]

# Lists of stimulus and reward times for use when plotting
start_stimulus_times = []
end_stimulus_times = []
start_reward_times = []
end_reward_times = []
Beispiel #11
0
 def save_model(self, iter):
     common.save_params(fName=self.sn_dir +
                        time.strftime("%Y-%m-%d-%H-%M-") +
                        ('%0.6d.sn' % iter),
                        obj=common.get_params(self.model.params))
Beispiel #12
0
import gym
from common import get_params
from brain import Agent
import psutil
from torch.utils.tensorboard import SummaryWriter
import time
import mujoco_py
from mujoco_py.generated import const
from mujoco_py import GlfwContext
import cv2

GlfwContext(offscreen=True)

if __name__ == "__main__":
    params = get_params()
    env = gym.make(params["env_name"])
    params.update({"n_states": env.observation_space.shape[0]})
    params.update({"n_actions": env.action_space.shape[0]})
    params.update({"action_bounds": [env.action_space.low[0], env.action_space.high[0]]})
    params.update({"max_episode_steps": env.spec.max_episode_steps})
    params.update({"max_episodes": params["max_steps"] // params["max_episode_steps"]})
    print("params:", params)

    agent = Agent(**params)
    to_gb = lambda in_bytes: in_bytes / 1024 / 1024 / 1024

    explore_steps = 0
    running_reward = 0
    if params["do_train"]:
        for episode in range(1, 1 + params["max_episodes"]):
            state = env.reset()
Beispiel #13
0
 def save_model(self, itr):
     common.save_params(fName=self.sn_dir + time.strftime("%Y-%m-%d-%H-%M-") +('%0.6d.sn'%itr), obj = common.get_params(self.model.param_struct[0].params + self.model.param_struct[1].params))
Beispiel #14
0
def main(argv):
    del argv
    params = common.get_params()
    run_model(params)