def user_notebook_exists(self, username, course_unit_name, resource, sifu_token, sifu_domain): """ Tests to see if user notebook exists """ headers = get_headers(sifu_token) url = 'http://%s:3334/v1/api/notebooks/users/courses/files' % sifu_domain payload = { "notey_notey": { "username": username, "course": course_unit_name, "file": resource } } try: resp = requests.request("GET", url, data=json.dumps(payload), headers=headers) resp.raise_for_status() resp = resp.json() return resp["result"] except (requests.exceptions.RequestException, requests.exceptions.HTTPError) as e: log.debug( u'[JupyterNotebook Xblock] : RequestException occured in user_notebook_exists: {}' .format(e)) return False
def create_base_file(self, course_unit_name, resource, sifu_token, sifu_domain, host): base_url = "http://%s:3334/%s" headers = get_headers(sifu_token) api_endpoint = "v1/api/notebooks/courses/files/" response = None url = base_url % (sifu_domain, api_endpoint) loaded_file = self.get_xblock_notebook(host) payload = { "notey_notey": { "course": course_unit_name, "file": resource, "data": loaded_file } } try: # TODO check for auth-403 alreadystarted-400 doesntexist-404 response = requests.request("POST", url, data=json.dumps(payload), headers=headers) return True except requests.exceptions.RequestException as e: print("[edx_xblock_jupyter] ERROR : %s " % e) return False
def create_user_notebook(self, username, course_unit_name, resource, sifu_token, sifu_domain): base_url = "http://%s:3334/%s" headers = get_headers(sifu_token) api_endpoint = "v1/api/notebooks/users/courses/files/" response = None url = base_url % (sifu_domain, api_endpoint) payload = { "notey_notey": { "username": username, "course": course_unit_name, "file": resource } } try: # TODO check for auth-403 alreadystarted-400 doesntexist-404 resp = requests.request("POST", url, data=json.dumps(payload), headers=headers) try: resp.raise_for_status() except requests.exceptions.HTTPError as e: print("HTTPError:", e.message) return False return True except requests.exceptions.RequestException as e: print("[edx_xblock_jupyter] ERROR : %s " % e) return False
def uploadImage(path): with open(path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) data = {'file': str(encoded_string)[2:-1], 'type': 'MMS'} headers = auth.get_headers(config.apiKey, config.apiSecret) return requests.post(config.getUrl('/storage/v1/files'), headers=headers, json=data)
def create_group(): group = { "description": "Dashboard group for JDD presentation", "name": "Observability demo", } result = requests.post(group_url, headers=auth.get_headers(), json=group).json() return { "groupId": result['id'], "dashboardId": result['dashboardConfigs'][0]['dashboardId'] }
def create_chart(metric): chart = { "description": "Requests/s", "name": metric, "programText": "A = data('" + metric + "').publish(label='A')", "tags": ["observability_demo"] } chart_response = requests.post(chart_url, headers=auth.get_headers(), json=chart).json() print(chart_response) return chart_response['id']
def update_default_dashboard(charts, groupId, dashboardId): dashboard = { "description": "JDD", "name": "Observability demo", "charts": charts, "groupId": groupId } result = requests.put(dashboard_url + "/" + dashboardId, headers=auth.get_headers(), json=dashboard).json() print(result) return result['id']
def create_base_file(self, course_unit_name, resource, sifu_token, sifu_domain, host): base_url = "http://%s:3334/%s" headers = get_headers(sifu_token) api_endpoint = "v1/api/notebooks/courses/files/" response = None url = base_url % (sifu_domain, api_endpoint) loaded_file = self.get_xblock_notebook(host) payload = {"notey_notey":{"course":course_unit_name,"file":resource,"data":loaded_file}} try: # TODO check for auth-403 alreadystarted-400 doesntexist-404 response = requests.request("POST", url, data=json.dumps(payload), headers=headers) return True except requests.exceptions.RequestException as e: print("[edx_xblock_jupyter] ERROR : %s " % e) return False
def user_notebook_exists(self, username, course_unit_name, resource, sifu_token, sifu_domain): """ Tests to see if user notebook exists """ headers = get_headers(sifu_token) url = 'http://%s:3334/v1/api/notebooks/users/courses/files' % sifu_domain payload = {"notey_notey":{"username":username,"course":course_unit_name,"file":resource}} try: resp = requests.request("GET", url, data=json.dumps(payload), headers=headers) resp.raise_for_status() resp = resp.json() return resp["result"] except (requests.exceptions.RequestException, requests.exceptions.HTTPError) as e: log.debug(u'[JupyterNotebook Xblock] : RequestException occured in user_notebook_exists: {}'.format(e)) return False
def create_user_notebook(self, username, course_unit_name, resource, sifu_token, sifu_domain): base_url = "http://%s:3334/%s" headers = get_headers(sifu_token) api_endpoint = "v1/api/notebooks/users/courses/files/" response = None url = base_url % (sifu_domain, api_endpoint) payload = {"notey_notey":{"username":username,"course":course_unit_name,"file":resource}} try: # TODO check for auth-403 alreadystarted-400 doesntexist-404 resp = requests.request("POST", url, data=json.dumps(payload), headers=headers) try: resp.raise_for_status() except requests.exceptions.HTTPError as e: print("HTTPError:", e.message) return False return True except requests.exceptions.RequestException as e: print("[edx_xblock_jupyter] ERROR : %s " % e) return False
def sendMany(data): return requests.post(config.getUrl('/messages/v4/send-many'), headers=auth.get_headers(config.apiKey, config.apiSecret), json=data)
import requests import configparser import json import sys import os.path sys.path.append('../../lib') import auth import config if __name__ == '__main__': # [INPUT_GROUP_ID] 에 그룹 아이디를 넣어주세요 # ex) G4V20181005122748TESTTESTTESTTES res = requests.delete(config.getUrl('/messages/v4/groups/[INPUT_GROUP_ID]', headers=auth.get_headers(config.apiKey, config.apiSecret)) print(json.dumps(json.loads(res.text), indent=2, ensure_ascii=False))
def put(path, data, headers={}): headers.update(auth.get_headers(config.apiKey, config.apiSecret)) return requests.put(config.getUrl(path), headers=headers, json=data)
def post(path, data): return requests.post(config.getUrl(path), headers=auth.get_headers(config.apiKey, config.apiSecret), json=data)
import requests import configparser import auth import json config = configparser.ConfigParser() config.read('../config.ini') apiKey = config['AUTH']['ApiKey'] apiSecret = config['AUTH']['ApiSecret'] if __name__ == '__main__': data = { 'message': { 'to': config['VALUE']['to'], 'from': config['VALUE']['from'], 'text': 'test' } } res = requests.post(config['SERVER']['URI'] + 'send', headers=auth.get_headers(apiKey, apiSecret), json=data) print(json.loads(res.text))
import requests import configparser import auth import json config = configparser.ConfigParser() config.read('../config.ini') apiKey = config['AUTH']['ApiKey'] apiSecret = config['AUTH']['ApiSecret'] if __name__ == '__main__': # [INPUT_GROUP_ID] 에 그룹 아이디를 넣어주세요 # ex) G4V20181005122748TESTTESTTESTTES res = requests.delete(config['SERVER']['URI'] + 'groups/[INPUT_GROUP_ID]', headers=auth.get_headers(apiKey, apiSecret)) print(json.loads(res.text))
def get(path, headers={}): headers.update(auth.get_headers(config.apiKey, config.apiSecret)) return requests.get(config.getUrl(path), headers=headers)
import requests import json import sys import os.path sys.path.append('../../lib') import auth import config # LMS 단건 발송 # 제목(subject)을 지정하지 않으면 메시지 내용(text) 앞 부분을 제목으로 사용합니다. if __name__ == '__main__': data = { 'message': { 'to': '수신번호 입력', 'from': '발신번호 입력', 'text': '한글 45자, 영자 90자 이상 입력되면 자동으로 LMS타입의 문자메시자가 발송됩니다. type 옵션을 주어 명시적으로 타입을 지정할 수도 있습니다.' } } res = requests.post(config.getUrl('/messages/v4/send'), headers=auth.get_headers(config.apiKey, config.apiSecret), json=data) print(json.dumps(json.loads(res.text), indent=2, ensure_ascii=False))
def delete(path): return requests.delete(config.getUrl(path), headers=auth.get_headers(config.apiKey, config.apiSecret))