def setUp(self): super(ProjectMemberTests, self).setUp() # Client used during tests self.client = utils.create_client(self.p1member.name, 'p1member', self.p1.name, self.d1.name, 'http://localhost:5000/v3')
def setUp(self): super(ProjectAdminTests, self).setUp() # Client used during tests self.client = utils.create_client( self.p1admin.name, "p1admin", self.p1.name, self.d1.name, "http://10.1.0.22:5000/v3" )
def main(server,port): allLaumio = Laumio.init_all(servername=server, port=port) for l in allLaumio: l.fill([25,25,112]) client = utils.create_client(server,port) laumios = randomLaumio(client) for z in range(10): for i in range(0,10): laumios.laumio1.fill('white') time.sleep(0.02) laumios.laumio1.fill('black') for i in range(0,10): laumios.laumio2.fill('white') time.sleep(0.02) laumios.laumio2.fill('black') for i in range(0,10): laumios.laumio3.fill('white') time.sleep(0.02) laumios.laumio3.fill('black') for i in range(0,10): laumios.laumio4.fill('white') time.sleep(0.02) laumios.laumio4.fill('black')
def __init__(self, space_id, name: str, host, port): self.name = str(name) self.client = create_client(servername=host, port=port, id_prefix=f'{space_id}-') print('CLIENT:', self.client) self.client.on_message = self.on_message self.client.subscribe('#')
def main(): cmd = sys.argv[1] client = utils.create_client(servername='mpd.lan', port=1883) if cmd == 'setval': music.music_control(client, cmd, sys.argv[2]) else: music.music_control(client, cmd)
def setUp(self): super(ProjectAdminTests, self).setUp() # Client used during tests self.client = utils.create_client(self.p1admin.name, 'p1admin', self.p1.name, self.d1.name, 'http://localhost:5000/v3')
def setUp(self): super(ProjectAdminTests, self).setUp() # Client used during tests self.client = utils.create_client(self.p1member.name, 'p1member', self.p1.name, self.d1.name, 'http://10.1.0.22:5000/v3')
def run_one_region(region_number, number_of_instances, fout, fout2): client = utils.create_client(utils.CONFIG, region_number) instance_type_list = ['t2.micro', 't2.small', 'm3.medium'] # node_name_tag = request_spot_fleet_with_on_demand( # client, region_number, int(number_of_instances), 1, instance_type_list) request_id = request_spot_fleet(client, region_number, int(number_of_instances), instance_type_list) instance_ids = get_instance_ids(client, request_id) print(instance_ids ) # TODO@ricl, no data here since the request is not fulfilled.
def what_guido_says(since, until, keyword, account='gvanrossum'): """ 2 points. Return a list of tweets originating from the Twitter account 'gvanrossum' that were posted between `since` and `until` and contain `keyword`. Each entry in the list should be a tuple (tweet_text, is_retweet). tweet_text should be the text of the tweet is_retweet is a boolean stating whether the tweet is a retweet or not Use the provided `CLIENT` variable. Don't forget to urlencode the URL parameters. Example: what_guido_says('2018-10-20', '2018-10-25', 'Python') # [('blabla', False), ('RT: blablabla', True)] """ client = create_client() url = API_URL + 'statuses/user_timeline.json?' + urlencode( {'screen_name': account}) res, data = client.request(url, method="GET", headers={"content-type": "application/json"}) assert res['status'] == '200' tweets = json.loads(data) ret = [] for tweet in tweets: created_at = tweet.get('created_at') since_timestamp = datetime.strptime(since, '%Y-%m-%d').timestamp() until_timestamp = datetime.strptime(until, '%Y-%m-%d').timestamp() created_at_timestamp = datetime.strptime( created_at, '%a %b %d %H:%M:%S %z %Y').timestamp() text = text_for_search = tweet.get('text') is_retweet = None is not tweet.get('retweeted_status') for i in tweet.get('entities'): if i == 'urls': for j in tweet.get('entities')[i]: text_for_search = text.replace(j['url'], j['expanded_url']) if (since_timestamp <= created_at_timestamp) and \ (created_at_timestamp <= until_timestamp) and \ (keyword.lower() in text_for_search.lower()): ret.append((text, is_retweet)) return ret
def main(server, port): laumios = Laumio.init_all(servername=server, port=port) client = utils.create_client('mpd.lan', 1883) dictColor = { 'red': sensors.get_bp_button_status(client, 1), 'blue': sensors.get_bp_button_status(client, 2), 'yellow': sensors.get_bp_button_status(client, 3), 'green': sensors.get_bp_button_status(client, 4) } while True: for k, v in dictColor.values(): if v: for l in laumios: l.fill(k)
def pytest_runtest_logreport(report): if report.failed: client = create_client() test_containers = client.containers.list( all=True, filters={"name": "flask_functional"}) for container in test_containers: # XXX magical number! get the last 10 log lines log_lines = [ ("Container ID: {!r}:".format(container.attrs['Id'])), ] + container.logs().decode('utf-8').split('\n')[-10:] try: report.longrepr.addsection('docker logs', os.linesep.join(log_lines)) except AttributeError: pass
def send_tweet(status): """ 1 point. Send a tweet with the given `status`. Return the response from client.request call. Use the provided `CLIENT` variable. Don't forget to urlencode the URL parameters. Example: res = send_tweet('Hello!') assert int(res['status']) == 2OO """ client = create_client() url = API_URL + 'statuses/update.json?' + urlencode({'status': status}) res, data = client.request(url, method="POST", headers={"content-type": "application/json"}) assert res['status'] == '200' return res
def pytest_report_header(config): logger = get_logger('report_header') msg = [] try: client = create_client() metadata = client.api.inspect_container('flask_functional') except docker.errors.NotFound: logger.info("No running container was found, can't add info to report header") metadata = {'Config': {}} msg = ['Docker: container not running yet'] except DockerException as e: logger.exception('Unable to connect to a docker socket') msg = ['Docker: Unable to connect to a docker socket'] msg.append('Error: %s' % str(e)) return msg config = metadata['Config'] #labels = config.get('Labels', {}) msg.extend([ #' %s: %s' % (k, v) for k, v in labels.items() ' DOCKER>> %s: %s' % (k, v) for k, v in config.items() ]) return msg
if cmd != 'setvol' : music.music_control(client, cmd, value=None) else: if nb_vol < len(volume): music.music_control(client, cmd, value=str(volume[nb_vol])) nb_vol+=1 time.sleep(2) def toggle_manip(client): music.music_control(client, 'setvol', value='90') music.music_control(client, 'toggle', value=None) time.sleep(2) music.music_control(client, 'toggle', value=None) time.sleep(2) if __name__ == "__main__": if len(sys.argv) == 1: servername = 'localhost' port = 1883 elif len(sys.argv) == 2: servername = sys.argv[1] port = 1883 elif len(sys.argv) == 3: servername = sys.argv[1] port = sys.argv[2] else: print(__doc__) complete_manipulation(utils.create_client(servername, int(port))) # toggle_manip(utils.create_client(servername, int(port)))
import utils """ In the case of using cloud_admin rule using a specific domain: "admin_required": "(role:admin or is_admin:1) and domain_id:cloud_admin_domain_id", """ # Regular admin login admin_client = utils.create_client("admin", "admin", "admin", "Default", "Default", "http://10.1.0.22:5000/v3") # Create cloud_admin_domain admin_domain = utils.create_domain(admin_client, "cloud_admin_domain") # Create cloud_admin_project admin_project = utils.create_project(admin_client, "cloud_admin_project", admin_domain) # Craete cloud_admin user cloud_admin = utils.create_user( admin_client, "cloud_admin", "cloud_admin", "*****@*****.**", admin_project.id, admin_domain.id ) # Create cloud_admin role (admin in this case) admin_role = utils.create_role(admin_client, "admin") # Grant roles at cloud_admin_domain and cloud_admin_project utils.grant_project_role(admin_client, admin_role.id, cloud_admin.id, admin_project.id) utils.grant_domain_role(admin_client, admin_role.id, cloud_admin.id, admin_domain.id) # Print cloud_admin_domain id to be used at domain_id rule
import utils """ In the case of using cloud_admin rule using a specific domain: "admin_required": "(role:admin or is_admin:1) and domain_id:cloud_admin_domain_id", """ # Regular admin login admin_client = utils.create_client('admin', 'admin', 'admin', 'Default', 'Default', 'http://*****:*****@example.com', admin_project.id, admin_domain.id) # Create cloud_admin role (admin in this case) admin_role = utils.create_role(admin_client, 'admin') # Grant roles at cloud_admin_domain and cloud_admin_project utils.grant_project_role(admin_client, admin_role.id, cloud_admin.id, admin_project.id) utils.grant_domain_role(admin_client, admin_role.id, cloud_admin.id,
import utils # LOGIN admin_client = utils.create_client('admin', 'admin', 'admin', 'Default', 'Default', 'http://10.1.0.22:5000/v3') # CREATE CLOUD ADMIN DOMAIN admin_domain = utils.create_domain(admin_client, 'cloud_admin_domain') # CREATE CLOUD ADMIN DEFAULT PROJECT admin_project = utils.create_project(admin_client, 'cloud_admin_project', admin_domain) # CREATE CLOUD ADMIN USER cloud_admin = utils.create_user(admin_client, 'cloud_admin', 'cloud_admin', '*****@*****.**', admin_project.id, admin_domain.id) # CREATE ROLE ADMIN admin_role = utils.create_role(admin_client, 'admin') # GRANT ADMIN ROLE AT DOMAIN utils.grant_domain_role(admin_client, admin_role.id, cloud_admin.id, admin_domain.id)
import os import re from urllib.parse import urlencode import requests """ TODO: paste tokens into utils TODO: $ pip install requests oauth2 """ from utils import create_client # Twitter API documentation: https://developer.twitter.com/en/docs.html API_URL = 'https://api.twitter.com/1.1/' # CLIENT is an instance of Http (https://httplib2.readthedocs.io/en/latest/libhttplib2.html#http-objects) CLIENT = create_client() def send_tweet(status): """ 1 point. Send a tweet with the given `status`. Return the response from client.request call. Use the provided `CLIENT` variable. Don't forget to urlencode the URL parameters. Example: res = send_tweet('Hello!') assert int(res['status']) == 2OO """
def init_all(servername='localhost', port=1883): client = utils.create_client(servername, int(port)) return LaumioGroup(client)
def client(): return create_client()
from telethon import TelegramClient, sync, events from glob import glob import os import importlib from modules import bot_forward from modules import bot_action_print from utils import create_client client = create_client() # chats = ( # 'gebeto', # 'podlodka', # 'gebeto_music', # 'simpsons_online', # -1001389649534, # ) chats = None for module_path in glob('modules/bot_*.py'): base = os.path.basename(module_path) module, ext = os.path.splitext(base) k = importlib.import_module("modules.{}".format(module)) k.__init__(client, chats) client.start() # client.connect()
import utils """ In the case of using cloud_admin rule using a specific domain: "admin_required": "(role:admin or is_admin:1) and domain_id:cloud_admin_domain_id", """ # Regular admin login admin_client = utils.create_client('admin', 'admin', 'admin', 'Default', 'Default', 'http://*****:*****@example.com', admin_project.id, admin_domain.id)