def __init__(self, bot): self.bot = bot if not hasattr( bot, 'music' ): # This ensures the client isn't overwritten during cog reloads. self.bot.music = lavalink.Client(self.bot.user.id) self.bot.music.add_node(ge("lavalinkus"), 80, ge("password"), 'asia', 'au-music-node') self.bot.add_listener(self.bot.music.voice_update_handler, 'on_socket_response') self.bot.music.add_event_hook(self.track_hook)
def getenv(env: str, default: Any) -> str: """Return env var if set and not empty, otherwise default. Also convert 'true'/'false' to bool values.""" got_env = ge(env) got_env = False if got_env and got_env.lower() == "false" else got_env got_env = True if got_env and got_env.lower() == "true" else got_env return default if got_env is None or got_env == "" else got_env
def teams_session(): client_id = ge('client_id') authority_id = ge('authority_id') client_credential = ge('client_credential') BASE_URL = "https://graph.microsoft.com/beta/" ms_s = sessions.BaseUrlSession(base_url=BASE_URL) app = ConfidentialClientApplication( client_id=client_id, authority=f"https://login.microsoftonline.com/{authority_id}", client_credential=client_credential) result = app.acquire_token_for_client( scopes=["https://graph.microsoft.com/.default"]) token = result['access_token'] sessions.BaseUrlSession(base_url='https://graph.microsoft.com/beta/') ms_s.headers.update({"Authorization": f"Bearer {token}"}) return ms_s
def get_client(): from keystoneclient.auth.identity.v3 import Password from keystoneclient.session import Session from novaclient.client import Client from os import getenv as ge auth = Password( auth_url=ge('OS_AUTH_URL'), username=ge('OS_USERNAME'), password=ge('OS_PASSWORD'), user_domain_id=ge('OS_USER_DOMAIN_ID', 'default'), project_domain_id=ge('OS_PROJECT_DOMAIN_ID', 'default'), project_name=ge('OS_PROJECT_NAME', ge('OS_TENANT_NAME')), ) session = Session( auth=auth, verify=ge('OS_CACERT'), ) client = Client('2', session=session) return client
def get_client(): from keystoneclient.session import Session from novaclient.client import Client from os import getenv as ge from keystoneclient.auth.identity import Password OS_AUTH_URL = ge('OS_AUTH_URL') if OS_AUTH_URL.endswith('v2.0'): auth = Password( ge('OS_AUTH_URL'), username=ge('OS_USERNAME'), password=ge('OS_PASSWORD'), tenant_name=ge('OS_TENANT_NAME') ) elif OS_AUTH_URL.endswith('v3'): auth = Password( ge('OS_AUTH_URL'), username=ge('OS_USERNAME'), password=ge('OS_PASSWORD'), user_domain_id=ge('OS_USER_DOMAIN_ID', 'default'), project_domain_id=ge('OS_PROJECT_DOMAIN_ID', 'default'), project_name=ge('OS_PROJECT_NAME'), ) else: raise ValueError('Unable to discover version from {}'.format(OS_AUTH_URL)) session = Session( auth=auth, verify=ge('OS_CACERT'), ) client = Client('2', session=session) return client
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <style> table {border-collapse: collapse;} table, td, th { border: 1px solid black;} td {padding-left: 4px;padding-right: 4px;} </style> </head> <body> """ FOOTER = """ </body> </html> """ if __name__ == "__main__": vars = [ge('_WSURL', '-1'), ge('_SUBJECT', '-1'), ge('_EMAIL', '-1')] if '-1' not in vars: pattern = '<table align=\"CENTER\" width=\"99%\">((\n.*)*(</table>))' response = urlopen(vars[0]).read() #returns an entire page result = search(pattern, response, IGNORECASE).group(0) # grab only data from response context = HEADER + result + FOOTER msg = MIMEText(context, 'html') msg["To"] = vars[2] msg["Subject"] = vars[1] p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE) p.communicate(msg.as_string())
def bb_session(): bb = BbRest(url=ge('bburl'), key=ge('bbkey'), secret=ge('bbsecret')) bb_s = sessions.BaseUrlSession(base_url=f"{ge('bburl')}/learn/api/public/") bb_s.headers.update(bb.session.headers) return bb_s
import justpy as jp from os import getenv as ge from dotenv import load_dotenv import requests app = jp.app BACKEND_URL = ge('backend') APP_ID = ge('appid') load_dotenv() session_data={} @jp.SetRoute('/hello') async def hello(request): wp = jp.WebPage() wp.add(jp.P(text='Hello there!', classes='text-5xl m-2')) wp.add(jp.P(text=f"APP ID is {ge('appid')}")) return wp @jp.SetRoute('/launch') async def launch(request): wp = jp.WebPage() url = '' print(APP_ID) if len(request.query_params) > 0: login_hint = request.query_params['login_hint'] lti_message_hint = request.query_params['lti_message_hint'] target_link_uri = request.query_params['target_link_uri'] r = requests.get(f"{BACKEND_URL}launch", params=request.query_params) wp.add(jp.P(text=f"{r.text}"))
def login(driver): driver.find_element_by_id("UserUsername").send_keys(ge("MB_USERNAME")) driver.find_element_by_id("UserPassword").send_keys(ge("MB_PASSWORD")) driver.find_element_by_class_name("submit").find_element_by_tag_name("input").click()