def edit(token, album_id, webhook_id, data, status_code=200): print() request_url = env.env_var.get("URL") + "/albums/" + str(album_id) + "/webhooks/" + str(webhook_id) headers = {"Authorization": "Bearer "+ token, "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded"} data_tmp = data.copy() if "event" in data_tmp: del data_tmp["event"] if "add_event" in data_tmp: del data_tmp["add_event"] if "remove_event" in data_tmp: del data_tmp["remove_event"] encoded_data = util.urlencode(data_tmp) if "event" in data: events = data["event"] encoded_events = "".join(map(lambda e:"&event=" + str(e), events)) encoded_data = encoded_data + encoded_events if "add_event" in data: add_events = data["add_event"] encoded_add_events = "".join(map(lambda e:"&add_event=" + e, add_events)) encoded_data = encoded_data + encoded_add_events if "remove_event" in data: remove_events = data["remove_event"] encoded_remove_events = "".join(map(lambda e:"&remove_event=" + e, remove_events)) encoded_data = encoded_data + encoded_remove_events if encoded_data.startswith("&"): encoded_data = encoded_data[1:] response = requests.patch(request_url, headers=headers, data=encoded_data) util.print_request("PATCH", response, request_url) assert response.status_code == status_code if status_code == 200: webhook = json.loads(response.content) return webhook
def createPost(self, username, password): inputids = self.soup.findAll('input', {'name':('user_id', 'userid')}) form = None useridParam = None for inputid in inputids: useridParam = inputid['name'] form = inputid.findPrevious("form") if useridParam == None: raise util.NavStateException("unable to find login form, html=" + self.html) inputpin = form.find('input', {'name': ('password','pin')}) if inputpin == None: raise util.NavStateException("unable to find login form, html=" + self.html) passwordParam = inputpin['name'] logging.debug("form name=%s, useridParam=%s, passwordParam=%s" % (form["name"], useridParam, passwordParam)) action = form['action'] params = util.makePostData(form) # Fill the visible fields params[useridParam] = username params[passwordParam] = password data = util.urlencode(params) return action,data
def write_html_link_index(out_dir, link): check_link_structure(link) with open(os.path.join(TEMPLATES_DIR, 'link_index.html'), 'r', encoding='utf-8') as f: link_html = f.read() path = os.path.join(out_dir, 'index.html') link = derived_link_info(link) with open(path, 'w', encoding='utf-8') as f: f.write(Template(link_html).substitute({ **link, 'title': ( link['title'] or (link['base_url'] if link['is_archived'] else TITLE_LOADING_MSG) ), 'archive_url': urlencode( wget_output_path(link) or (link['domain'] if link['is_archived'] else 'about:blank') ), 'extension': link['extension'] or 'html', 'tags': link['tags'].strip() or 'untagged', 'status': 'Archived' if link['is_archived'] else 'Not yet archived', 'status_color': 'success' if link['is_archived'] else 'danger', })) chmod_file(path)
def trigger_user(token, album_id, webhook_id, user_id, status_code=202): print() request_url = env.env_var.get("URL") + "/albums/" + str(album_id) + "/webhooks/" + str(webhook_id) + "/trigger" headers = {"Authorization": "Bearer "+ token, "Content-Type": "application/x-www-form-urlencoded"} data = {"event":"new_user", "user":user_id} response = requests.post(request_url, headers=headers, data=util.urlencode(data)) util.print_request("POST", response, request_url) assert response.status_code == status_code
def post(klass, action, options = {}, headers = {}): url = util.join_url(endpoint(), action) body = util.urlencode(options) headers = util.merge_dict({ 'User-Agent': klass.user_agent, 'Content-Type': 'application/x-www-form-urlencoded'}, headers) data = api.default().http_call(url, 'POST', body= body, headers= headers) return klass(data)
def makeRenewalPost(self, titles): params = {} params = util.makePostData(self.form) params['selection_type'] = 'selected' data = util.urlencode(params) renewals = [] #keep track of items we actually tried to renew for title in titles: #print title if self.renewalitems.has_key(title) == False: continue renewals.append(title) renewalParam = {} item = self.renewalitems[title] renewalParam[item.renewitemkey] = 'on' data += "&" + util.urlencode(renewalParam) return self.form['action'], data
def create(self, url, name=None, start_time=None, format=None): appurl = self.base_url + "/schedule/" if not start_time: start_time = datetime.datetime.now() + datetime.timedelta( seconds=60) else: if format: start_time = datetime.datetime.strptime(start_time, format) time_tuple = util.to_tuplelist(start_time) if name: data = util.urlencode(time_tuple, name=name, url=url) else: data = util.urlencode(time_tuple, url=url) return weblib.post(appurl, data)
def ok_form(self): form = self.soup.find('form', {'name':'formMain'}) params = util.makePostData(form) del params['buttonCancel'] data = util.urlencode(params) action = form['action'] logging.warning("pending fine action: " + action) logging.warning("pending fine data: " + data) return action, data
def create(self, url, name=None, start_time=None, format=None): appurl = self.base_url + "/schedule/" if not start_time: start_time = datetime.datetime.now() + datetime.timedelta(seconds=60) else: if format: start_time = datetime.datetime.strptime(start_time, format) time_tuple = util.to_tuplelist(start_time) if name: data = util.urlencode(time_tuple, name=name, url=url) else: data = util.urlencode(time_tuple, url=url) return weblib.post(appurl, data)
def post(cls, action, options=None, headers=None, api=None): api = api or default_api() url = util.join_url(endpoint(api), action) body = util.urlencode(options or {}) headers = util.merge_dict({ 'User-Agent': cls.user_agent, 'Content-Type': 'application/x-www-form-urlencoded'}, headers or {}) data = api.http_call(url, 'POST', data=body, headers=headers) return cls(data, api=api)
def makeRenewalPost(self, titles): params = {} params = util.makePostData(self.form) data = util.urlencode(params) renewals = [] # keep track of items we actually tried to renew for title in titles: if self.itemsOut.has_key(title) == False: continue renewals.append(title) renewalParam = {} item = self.itemsOut[title] # see for example seattle3.htm test case - not all items have a renewal checkbox if item.renewitemkeys != None: renewalParam["renewitemkeys"] = item.renewitemkeys data += "&" + util.urlencode(renewalParam) action = self.form["action"] return action, data
def write_html_links_index(out_dir, links, finished=False): """write the html link index to a given path""" check_links_structure(links) path = os.path.join(out_dir, 'index.html') copy_tree(os.path.join(TEMPLATES_DIR, 'static'), os.path.join(out_dir, 'static')) with open(os.path.join(out_dir, 'robots.txt'), 'w+') as f: f.write('User-agent: *\nDisallow: /') with open(os.path.join(TEMPLATES_DIR, 'index.html'), 'r', encoding='utf-8') as f: index_html = f.read() with open(os.path.join(TEMPLATES_DIR, 'index_row.html'), 'r', encoding='utf-8') as f: link_row_html = f.read() full_links_info = (derived_link_info(link) for link in links) link_rows = '\n'.join( Template(link_row_html).substitute( **{ **link, 'title': ( link['title'] or (link['base_url'] if link['is_archived'] else TITLE_LOADING_MSG)), 'favicon_url': ( os.path.join('archive', link['timestamp'], 'favicon.ico') # if link['is_archived'] else 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' ), 'archive_url': urlencode(wget_output_path(link) or 'index.html'), }) for link in full_links_info) template_vars = { 'num_links': len(links), 'date_updated': datetime.now().strftime('%Y-%m-%d'), 'time_updated': datetime.now().strftime('%Y-%m-%d %H:%M'), 'footer_info': FOOTER_INFO, 'git_sha': GIT_SHA, 'short_git_sha': GIT_SHA[:8], 'rows': link_rows, 'status': 'finished' if finished else 'running', } with open(path, 'w', encoding='utf-8') as f: f.write(Template(index_html).substitute(**template_vars)) chmod_file(path)
def login(self, username, password): idinput = self.soup.find("input", {"name": "sec1"}) form = idinput.findPrevious("form") action = form["action"] params = util.makePostData(form) # Fill the visible fields params["sec1"] = username params["sec2"] = password data = util.urlencode(params) logging.debug(data) html = self.http.post(action, data, {"Content-Type": "application/x-www-form-urlencoded"}) util.check_login_error(html) logging.debug(html) return html
def create(token, data, status_code=201): print() request_url = env.env_var.get("URL") + "/capabilities" headers = { "Authorization": "Bearer " + token, "Content-Type": "application/x-www-form-urlencoded" } response = requests.post(request_url, headers=headers, data=util.urlencode(data)) util.print_request("POST", response, request_url) assert response.status_code == status_code if status_code == 201: capability_token = json.loads(response.content) return capability_token
def introspect(token, status_code=200): print() request_url = env.env_var.get("URL") + "/token/introspect" headers = { "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded" } data = {"token": token} response = requests.post(request_url, headers=headers, data=util.urlencode(data)) util.print_request("POST", response, request_url) assert response.status_code == status_code if status_code == 200: introspect = json.loads(response.content) return introspect
def createPost(self, username, password): form = self.soup.find("form", {"name" : "formMain"}) inputid = self.soup.find('input', {'name':('textboxOBarcode','textboxBarcode','textboxBarcodeUsername')}) useridParam = inputid['name'] inputpin = self.soup.find('input', {'name': ('textboxOPassword','textboxPassword')}) passwordParam = inputpin['name'] params = {} params = util.makePostData(form) params[useridParam] = username params[passwordParam] = password data = util.urlencode(params) action = form['action'] logging.debug('action=' + action) logging.debug('data=' + data) return action, data
def edit(token, album_id, data, status_code=200): print() request_url = env.env_var.get("URL") + "/albums/" + album_id headers = { "Authorization": "Bearer " + token, "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded" } response = requests.patch(request_url, headers=headers, data=util.urlencode(data)) util.print_request("PATCH", response, request_url) assert response.status_code == status_code if status_code == 200: album = json.loads(response.content) return album
def makeRenewalPost(self, titles): params = util.makePostData(self.form) renewals = [] #keep track of items we actually tried to renew for title in titles: if self.itemsOut.has_key(title) == False: continue item = self.itemsOut[title] if item.renewitemkeys != None: # not all items have a renewal checkbox, currently our gadget UI doesn't ever suppress it though params[item.renewitemkeys] = 'checked' params['__EVENTTARGET'] = 'linkbuttonRenew' params['__EVENTARGUMENT'] = '' data = util.urlencode(params) action = self.form['action'] #logging.warning("renew action: " + action) #logging.warning("renew data: " + data) return action, data
def post_comment(token, album_id, data={"comment": "default comment"}, status_code=204): print() request_url = env.env_var.get("URL") + "/albums/" + album_id + "/comments" headers = { "Authorization": "Bearer " + token, "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded" } response = requests.post(request_url, headers=headers, data=util.urlencode(data)) util.print_request("POST", response, request_url) assert response.status_code == status_code if status_code == 201: album = json.loads(response.content) return album
cj = http.cookiejar.CookieJar() opener = request.build_opener(request.HTTPCookieProcessor(cj)) request.install_opener(opener) cfg=[] n,t=lg.getconfig() for i in range(n): cfg.append(t[i+1]) print(t[i+1]) file='out.html' # search #key1=key.encode(cfg[4]) #key2=urllib.parse.quote(key1) #print(key,key1,key2) key=util.urlencode(key,cfg[4]) key=key.replace('%5C','%') print(key) scfg=[] n,t=lg.getsearchparam(key) for i in range(n): scfg.append(t[i+1]) print(t[i+1]) # navigate res = request.urlopen(cfg[5]) print(res.status, res.reason) s = res.read() s = util.convert(s,cfg[1]) with open(file,'wb') as f:
def set_url(self, name, url): appurl = self.base_url + "/schedule/" + name data = util.urlencode(url=url) return weblib.put(appurl, data)