def list(config, app_id, id, type): """List available application policies. Examples: List all group policies that belong to application 50: $ jaguar policy list 50 --type group List instance policy 101 that belongs to application 50: $ jaguar policy list 50 --type instance --id 101 """ try: url = config.server_url + '/v1/applications/' \ + str(app_id) + '/policies/' if type: url += type + '/' if id > 0: url += str(id) rest = Rest(url, {'username': config.user}) display(rest.get()) except RestError as error: quit(error.message)
def fill_holes(self): ''' Fills empty beats with rests.''' for measure in range(self.length): shortest = 1 for note in self.notes: # e.g. if shortest note is 1/8, measure contains 8 columns if measure == note.measure: # if note.duration < shortest: # shortest = note.duration # for rest in self.rests: if measure == rest.measure: # if rest.duration < shortest: # shortest = rest.duration # for i in range(1, int(1 / shortest) + 1): a = 0 for note in self.notes: if measure == note.measure: if note.start == i * shortest: a += 1 elif note.start < (i * shortest) and ( note.start + note.duration) > (i * shortest): a += 1 for rest in self.rests: if measure == rest.measure: if rest.start == i * shortest: a += 1 elif rest.start < (i * shortest) and ( rest.start + rest.duration) > (i * shortest): a += 1 if a == 0: rest = Rest( measure, i * shortest, shortest ) # (item_type, pitch, measure, start, duration) self.add_rest(rest)
def unregister(config, id): """Unregister an application.""" try: url = config.server_url + '/v1/applications/' + str(id) headers = {'username': config.user} rest = Rest(url, headers) display(rest.delete()) except RestError as error: quit(error.message)
def update(config, id, enable): """Update an application""" try: url = config.server_url + '/v1/applications/' + str(id) headers = {'username': config.user, 'Content-Type': 'application/json'} rest = Rest(url, headers) # check if the application exists response = rest.get() if response.status_code != requests.codes.ok: quit('Error: Application ' + str(id) + ' does not exist.') result = response.json() # update the field result['enabled'] = enable # post the data back data = json.dumps(result) rest = Rest(url, headers, data) display(rest.put()) except RestError as error: quit(error.message)
def delete(config, app_id, type, id): """Delete an application policy. """ try: url = config.server_url + '/v1/applications/' + str(app_id) \ + '/policies/' + type + '/' + str(id) headers = {'username': config.user, 'Content-Type': 'application/json'} rest = Rest(url, headers) display(rest.delete()) except RestError as error: quit(error.message)
def register(config, name, provider, enable): """Register an application for monitor and evaluation.""" try: url = config.server_url + '/v1/applications' headers = {'username': config.user, 'Content-Type': 'application/json'} data = json.dumps({ 'name': name, 'provider': provider, 'enabled': enable }) rest = Rest(url, headers, data) display(rest.post()) except RestError as error: quit(error.message)
def __init__(self, key=None, url=None): self.testnet_base_url = "https://live.coinpit.me/api/v1" self.livenet_base_url = "https://live.coinpit.io/api/v1" self.base_url_map = {0: self.livenet_base_url, 111: self.testnet_base_url} self.private_key = key self.account = None self.rest = None self.all = None self.contract = None if self.private_key is None: return self.network_code = crypto.get_network_code(self.private_key) self.base_url = url if url is not None else self.base_url_map[self.network_code] self.rest = Rest(self.base_url)
def update(config, app_id, type, id, file): """Update an application policy. """ try: data = '' while True: chunk = file.read(1024) if not chunk: break data += chunk if not is_json(data): raise click.BadParameter('The policy file ' + file.name \ + ' is not a valid json file.') url = config.server_url + '/v1/applications/' + str(app_id) \ + '/policies/' + type + '/' + str(id) headers = {'username': config.user, 'Content-Type': 'application/json'} rest = Rest(url, headers, data) display(rest.put()) except RestError as error: quit(error.message)
def list(config, id): """List registered applications. Examples: $ jaguar application list $ jaguar application list --id 50 """ try: if id > 0: url = config.server_url + '/v1/applications/' + str(id) else: url = config.server_url + '/v1/applications' headers = {'username': config.user} rest = Rest(url, headers) display(rest.get()) except RestError as error: quit(error.message)
def parse_tauot(self, line): try: if line.strip() != "": parts = line.split(",") measure = int(parts[0].strip()) # measure start = parts[1].split("/") start = float(int(start[0].strip()) / int(start[1].strip())) # start duration = parts[2].split("/") if len(duration) == 1: duration = float(duration[0].strip()) elif len(duration) == 2: duration = float( int(duration[0].strip()) / int(duration[1].strip())) else: raise CorruptedCompositionFileError("Huono kesto") rest = Rest(measure, start, duration) Composition.add_rest(self.comp, rest) return True except: print("Huono tauko.")
load_dotenv() log.basicConfig(filename='main.log', level=log.INFO, format='%(asctime)s - %(levelname)s - %(message)s') TOKEN = os.getenv('DISCORD_TOKEN') GUILD = os.getenv('DISCORD_GUILD_ID') WORK_CH_ID = os.getenv('WORK_CH_ID') ROLE_CH_ID = os.getenv('ROLE_CH_ID') EMOJI: dict = {"Spielleiter": '🖊️', 'Spieler': '📜'} ROLE_DICT: dict = {} REACT_MSG_ID: int intents = discord.Intents.default() intents.members = True bot = commands.Bot(command_prefix="!", intents=intents) rest = Rest() @bot.event async def on_ready(): guild: discord.Guild = discord.utils.get(bot.guilds, id=int(GUILD)) await getChHistory(discord.utils.get(guild.channels, id=int(WORK_CH_ID))) await checkRoleCh(discord.utils.get(guild.channels, id=int(ROLE_CH_ID))) global ROLE_DICT for role in guild.roles: ROLE_DICT[role.name] = role log.info(f'{bot.user.name} has connected to Discord!') @bot.event async def on_member_join(member: discord.member):
#!/usr/bin/env python3 import os from pathlib import Path from typing import Dict, Any, List import bcrypt # type: ignore import jwt from rest import Rest, Method # type: ignore from models import Session, User # type: ignore from response import response, Status # type: ignore from util import create_jwt, send_verification_email # type: ignore CONFIG_PATH = f"{Path(__file__).parent.absolute()}{os.sep}config.json" rest: Rest = Rest(CONFIG_PATH) secret = rest.get_secret() @rest.route("/create/user", Method.POST) def create_user(payload: Dict[Any, Any]) -> Dict[Any, Any]: """ Creates a User from POST payload Parameters ---------- payload: Dict[Any, Any] Payload of the form {
import sys from rest import Rest client = Rest() method = str(sys.argv[1]) parameter = sys.argv[2] if len(sys.argv) > 2 else None call = getattr(client, method) try: response = call(parameter) if parameter is not None else call() print(response) except Exception as e: print(e)
def connect(self): server_pub_key = self.get_server_pubkey() self.account = Account(self.private_key, server_pub_key) self.rest = Rest(self.base_url, self.account)
logger.info('Done') #req = citysense.get_endpoint('weatherstation', id='davis-013d4d',start='2021-02-16T13:56:56.994Z') #print(req) #req = citysense.get_endpoint('hochwasser', id=['ultrasonic1', 'ultrasonic2'], start='2021-02-16T13:56:56.994Z') #print(req) #citysense.register_sensor('weather_station', 'davis-013d4d') #citysense.register_sensor('co2', 'elsysco2-045184') #citysense.register_sensor('co2', 'elsysco2-048e67') logger.info('Registering sensors') for sensor in sensors.get_domains(): for domain in sensor['domains']: citysense.register_sensor(domain, sensor['id']) logger.info('Done') logger.info('Pulling initial citysense...') citysense.pull_registered_sensors() logger.info('Done') logger.info('Starting rest API...') rest = Rest(config['rest'], sensors, rules) rest.run(host='0.0.0.0') logger.info('Shutting down...') citysense.disable_token_timer() citysense.disable_sensor_timer() logger.info('Done')
def do_config_call(ip, admin_port, mcd_port): rest = Rest(ip, admin_port, mcd_port) dcp_client = rest.vbDCPClient(0) for i in xrange(0, CALL_COUNT_PER_CHILD): dcp_client.get_cluster_config(0)
def __init__(self, domain): # type: (str) -> None self.__rest = Rest(domain)
def user_login(username, password, rest_url=common_data.stg_url): load = {"username": username, "password": password} response = Rest(rest_url).send(restful_uri_data.user_login, data=load) print(response)
from constants import HEADERS from constants import URL from rest import Rest api = Rest(URL, HEADERS) def list_zones(): resp = api.get('/zones') return { x['name']: { 'status': x['status'], 'id': x['id'] } for x in resp['result'] } def list_records(zone_id, typ=None, name=None): params = {} if typ is not None: params['type'] = typ if name is not None: params['name'] = name resp = api.get( '/zones/{0}/dns_records'.format(zone_id), params if params else None, ) return sorted([{ 'id': x['id'],