def login(self): if not self.username and not self.password: return True # fall back to free account elif self.username and self.password and len( self.username) > 0 and len(self.password) > 0: headers, req = self._create_request( '', {'username_or_email': self.username}) data = util.post(self._url('api/salt/'), req, headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': return False salt = xml.find('salt').text password = hashlib.sha1( md5crypt(self.password.encode('utf-8'), salt.encode('utf-8'))).hexdigest() digest = hashlib.md5(self.username + ':Webshare:' + self.password).hexdigest() headers, req = self._create_request( '', { 'username_or_email': self.username, 'password': password, 'digest': digest, 'keep_logged_in': 1 }) data = util.post(self._url('api/login/'), req, headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': return False self.token = xml.find('token').text return True return False
def login(self): if not self.username and not self.password: return True # fall back to free account elif self.username and self.password and len(self.username)>0 and len(self.password)>0: #util.info('Login user=%s, pass=*****' % self.username) #sclog.logDebug("Login start...") # get salt headers,req = self._create_request('',{'username_or_email':self.username}) sclog.logDebug("Webshare login try '%s' ..."%self._url('api/salt/')) data = util.post(self._url('api/salt/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': #sclog.logDebug("Login end salt...") #util.error('Server returned error status, response: %s' % data) return False salt = xml.find('salt').text if salt is None: salt = '' # create hashes password = hashlib.sha1(md5crypt(self.password.encode('utf-8'), salt.encode('utf-8'))).hexdigest() digest = hashlib.md5(self.username + ':Webshare:' + self.password).hexdigest() # login headers,req = self._create_request('',{'username_or_email':self.username,'password':password,'digest':digest,'keep_logged_in':1}) data = util.post(self._url('api/login/'),req,headers=headers) xml = ET.fromstring(data) #sclog.logDebug("Login end...") if not xml.find('status').text == 'OK': #util.error('Server returned error status, response: %s' % data) return False self.token = xml.find('token').text #util.info('Login successfull') return True return False
def login(self): if not self.username and not self.password: return True # fall back to free account elif self.username and self.password and len(self.username)>0 and len(self.password)>0: self.info('Login user=%s, pass=*****' % self.username) # get salt headers,req = self._create_request('',{'username_or_email':self.username}) data = util.post(self._url('api/salt/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': self.error('Server returned error status, response: %s' % data) return False salt = xml.find('salt').text # create hashes password = hashlib.sha1(md5crypt(self.password, salt)).hexdigest() digest = hashlib.md5(self.username + ':Webshare:' + self.password).hexdigest() # login headers,req = self._create_request('',{'username_or_email':self.username,'password':password,'digest':digest,'keep_logged_in':1}) data = util.post(self._url('api/login/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': self.error('Server returned error status, response: %s' % data) return False self.token = xml.find('token').text self.info('Login successfull') return True return False
def crawl(): PATIENCE = 15 MAX_RETRY = 3 SOURCE_NAME = "조선일보" MAIN_URL = "http://www.chosun.com/" driver = util.get_driver() driver.get(MAIN_URL) driver.set_page_load_timeout(PATIENCE) article_link_patterns = ["news.chosun.com/site/data/html_dir/"] link_list = [] timeout_cnt = 0 skipped_cnt = 0 # href_elms = driver.find_elements_by_class_name("sec_con")[1].find_elements_by_css_selector("[href]") href_elms = WebDriverWait(driver, PATIENCE) \ .until(EC.presence_of_all_elements_located((By.CLASS_NAME, "sec_con")))[1] \ .find_elements_by_css_selector("[href]") # live_elms = driver.find_elements_by_css_selector("#today_live_con_id [href]") live_elms = WebDriverWait(driver, PATIENCE) \ .until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "#today_live_con_id [href]"))) href_elms += live_elms for i in href_elms: href = i.get_attribute("href") for p in article_link_patterns: if p in href: try: link_list.index(href) except ValueError: link_list.append(href) break print("%d articles found" % len(link_list)) for i in link_list: # Retry loop for retry in range(0, 3): try: article = extract_news(driver, i) if article is not None: util.post(article, SOURCE_NAME) break else: continue except (TimeoutException, NoSuchElementException, StaleElementReferenceException): if retry == MAX_RETRY - 1: skipped_cnt += 1 else: driver.refresh() timeout_cnt += 1 driver.quit() print("Done with %d timeouts and %d skipped pages in %d links" % (timeout_cnt, skipped_cnt, len(link_list)))
def leave_from_event(bot, update): query = update.callback_query data = query.data[len('leave:'):] query.answer() try: util.post('/event/leave', {'event_id': int(data)}, get_auth(query.message.chat_id)) bot.edit_message_text(text="Событие покинуто", chat_id=query.message.chat_id, message_id=query.message.message_id) except Exception as e: bot.send_message(chat_id=query.message.chat_id, text=str(e))
def unsubscribe(bot, update): query = update.callback_query data = query.data[len('unsubscribe:'):] query.answer() try: util.post('/follow/remove', {'follow_id': int(data)}, get_auth(query.message.chat_id)) bot.edit_message_text(text="Подписка удалена", chat_id=query.message.chat_id, message_id=query.message.message_id) except Exception as e: bot.send_message(chat_id=query.message.chat_id, text=str(e))
def wrapper(bot, update, *args, **kwargs): if update.message.chat_id in registered_users: try: util.post('/register/check', registered_users[update.message.chat_id]) except Exception as e: update.message.reply_text('Неправильный логин/пароль!') return handler(bot, update, args, kwargs) else: update.message.reply_text( 'Для создания и просмотра событий необходимо авторизироваться!' ) return
def buyCar(numberOfCarBuyers): """Invokes an RPC REST call that does a car purchase by a person id <note> It is expected that the Car and Person entries are already created before invoking this method </note> """ for x in range(1, numberOfCarBuyers + 1): strId = str(x) payload = settings.buy_car_rpc_template.substitute(personId="user" + strId, carId=strId) # Send the POST request using RPC resp = util.post(settings.getBuyCarRpcUrl(), "admin", "admin", payload) print("payload formed after template substitution=") print(payload) print("the response of the POST to buycar=") print(resp) print("getting the car_persons for verification") resp = getCarPersonMappings(0)
def resolve(self,item,captcha_cb=None,wait_cb=None): item = item.copy() url = self._url(item['url']) item['surl'] = url data = util.request(url) link = re.search('<a class="stahnoutSoubor.+?href=\"([^\"]+)',data) if link: url = self._url(link.group(1)) data = util.request(url) m = re.search('<img src=\"(?P<img>[^\"]+)\" alt=\"Captcha\"',data) cap_id = re.search('<input type=\"hidden\" name=\"_uid_captcha.+?value=\"(?P<cid>[^\"]+)',data) if m and cap_id: cid = cap_id.group('cid') img_data = m.group('img')[m.group('img').find('base64,')+7:] if not os.path.exists(self.tmp_dir): os.makedirs(self.tmp_dir) tmp_image = os.path.join(self.tmp_dir,'captcha.png') util.save_data_to_file(base64.b64decode(img_data),tmp_image) code = captcha_cb({'id':cid,'img': tmp_image}) if not code: return data = util.post(url+'?do=stahnoutFreeForm-submit',{'_uid_captcha':cid,'captcha':code,'stahnoutSoubor':'Stáhnout'}) countdown = re.search('shortly\.getSeconds\(\) \+ (\d+)',data) last_url = re.search('<a class=\"stahnoutSoubor2.+?href=\"([^\"]+)',data) if countdown and last_url: wait = int(countdown.group(1)) url = self._url(last_url.group(1)) wait_cb(wait) req = urllib2.Request(url) req.add_header('User-Agent',util.UA) resp = urllib2.urlopen(req) item['url'] = resp.geturl() return item
def addCarPerson(numberOfCarPersons): """This method is not exposed via commands as only getCarPersons is of interest addCarPerson entry happens when buyCar is called <note> To enable RPC a non-user input car-person entry is created with personId=user0 </note> """ # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF if numberOfCarPersons == 0: payload = settings.add_car_person_template.substitute( Id=str(numberOfCarPersons), personId="user" + str(numberOfCarPersons)) # Send the POST request REST CONF resp = util.nonprintpost(settings.getAddCarPersonUrl(), "admin", "admin", payload) return for x in range(1, numberOfCarPersons + 1): strId = str(x) payload = settings.add_car_person_template.substitute(Id=strId, personId="user" + strId) # Send the POST request REST CONF resp = util.post(settings.getAddCarPersonUrl(), "admin", "admin", payload) print("payload formed after template substitution=") print(payload) print("the response of the POST to add car_person=") print(resp) print("getting the car_persons for verification") resp = getCarPersonMappings(0)
def deposit_safebox(mid, money, money_type): ''' @brief 存保险箱 @param mid: 用户mid @param money: 银币/金条数量 @param money_type: 0: 银币 1: 金条 @return: 存的金额 ''' url = util.AUTO_TEST_URL postdata = { "ssid": "", "ops": "updatesafebox", "mid": mid, "type": 1, "money": money, "money_type": money_type } response = util.post(url, postdata) result = 0 try: response = json.loads(response) if response.get('code', -1) == 200 and response.get('result'): result = response.get('result', {'money': '0'}).get('money') except: pass return result
def resolve(url): m = _regex(url) if m: vid = m.group('vid') headers= {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0', 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'} player_url = "http://hqq.tv/player/embed_player.php?vid=%s&autoplay=no" % vid try: req = urllib2.Request(player_url, headers=headers) data = urllib2.urlopen(req).read() except urllib2.HTTPError, e: if e.code == 404: data = e.fp.read() b64enc= re.search('base64([^\"]+)',data, re.DOTALL) b64dec = b64enc and base64.decodestring(b64enc.group(1)) hash = b64dec and re.search("\'([^']+)\'", b64dec).group(1) if hash: form = _decode(hash) data = re.compile('<input name="([^"]+?)" [^>]+? value="([^"]+?)">').findall(form) post_data = {} for idx in range(len(data)): post_data[ data[idx][0] ] = data[idx][1] data = util.post(player_url, post_data, headers) b64enc= re.search('base64([^\"]+)',data, re.DOTALL) b64dec = b64enc and base64.decodestring(b64enc.group(1)) hash = b64dec and re.search("\'([^']+)\'", b64dec).group(1) if hash: file_vars_script = _decode(hash) else: file_vars_script = data file_vars = re.compile('var.+?= "([^"]*?)"').findall(file_vars_script) for file_var in file_vars: file_url = _decode2(file_var) if 'http' in file_url: return [{'url':file_url,'quality':'???'}]
async def img_to_text(request): data = await request.post() image = data['image'].file.read() with open("test", "wb") as f: f.write(image) image = base64.b64encode(image) app_id = data['app_id'] app_key = data['app_key'] time_stamp = str(int(time.time())) nonce_str = get_rand_str(12) session_id = str(int(time.time())) upper_req_params = { "app_id": app_id, "time_stamp": time_stamp, "nonce_str": nonce_str, "sign": "", "image": image, "session_id": session_id } upper_req_params["sign"] = get_request_sign(upper_req_params, app_key) res = json.loads( post("https://api.ai.qq.com/fcgi-bin/vision/vision_imgtotext", upper_req_params)) print(res) return web.json_response(res)
def list(self,url): result = [] headers,req = self._create_request(url,{'what':'','offset':0,'limit':25,'category':'','sort':'','wst':self.token}) data = util.post(self._url('api/search/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': self.error('Server returned error status, response: %s' % data) return [] total = int(xml.find('total').text) for file in xml.findall('file'): item = self.video_item() item['title'] = file.find('name').text item['url'] = 'ident=%s' % file.find('ident').text size = int(file.find('size').text) item['size'] = '%d MB' % (int(size)/1024/1024) img = file.find('img').text if img: item['img'] = self._url(img) self._filter(result,item) listed = int(req['limit']) + int(req['offset']) if total > listed: req['offset'] = listed item = self.dir_item() item['type'] = 'next' item['url'] = urllib.urlencode(req) result.append(item) return result
def add_friend(mid, target_mid, message=''): ''' @brief 添加好友 @param mid: 用户mid @param target_mid: 目标用户mid @param message: 验证信息 @return: 1: 成功 0: 失败 ''' url = util.AUTO_TEST_URL postdata = { "ssid": "", "ops": "friendsadd", "mid": mid, "target_mid": target_mid, "message": message } result = 0 response = util.post(url, postdata) try: response = json.loads(response) if response.get('code', -1) == 200 and response.get('result', {'status': -1}).get('status') == 200: result = 1 else: print response.get('result', {'msg': ''}).get('msg') except: print 'error in add friend' return result
def resolve(self,item,captcha_cb=None,wait_cb=None): item = item.copy() url = self._url(item['url']) item['surl'] = url data = util.request(url) link = re.search('<a class="stahnoutSoubor.+?href=\"([^\"]+)',data) if link: url = self._url(link.group(1)) data = util.request(url) m = re.search('<img src=\"(?P<img>[^\"]+)\" alt=\"Captcha\"',data) cap_id = re.search('<input type=\"hidden\" name=\"_uid_captcha.+?value=\"(?P<cid>[^\"]+)',data) if m and cap_id: cid = cap_id.group('cid') img_data = m.group('img')[m.group('img').find('base64,')+7:] if not os.path.exists(self.tmp_dir): os.makedirs(self.tmp_dir) tmp_image = os.path.join(self.tmp_dir,'captcha.png') util.save_data_to_file(base64.b64decode(img_data),tmp_image) code = captcha_cb({'id':cid,'img': tmp_image}) if not code: return data = util.post(url+'?do=stahnoutFreeForm-submit',{'_uid_captcha':cid,'captcha':code,'stahnoutSoubor':'Stáhnout'}) countdown = re.search('shortly\.getSeconds\(\) \+ (\d+)',data) last_url = re.search('<a class=\"stahnoutSoubor2.+?href=\"([^\"]+)',data) if countdown and last_url: wait = int(countdown.group(1)) url = self._url(last_url.group(1)) wait_cb(wait) req = urllib2.Request(url) req.add_header('User-Agent',util.UA) resp = urllib2.urlopen(req) item['url'] = resp.geturl() resp.close() return item
def set_match_config(game, basechiptype, playmode, roomlevel, baseconfig="BASE_CHIPS-1000,LOW_LIMIT-30000,ROBOT_MAX_NUMBER-5", extraconfig="ROBOT_PLACE_BASE_TIMEOUT-30,PLAYEROUTCARDTIMEOUT-20"): ''' @brief 更新子游戏场次配置 @param game: 游戏id @param basechiptype: 底注类型 @param playmode: 玩法 @param roomlevel: 场次 @param baseconfig: 通用配置,key-value,key1-value1, key为要配置的参数,value为对应的值,多个参数用英文逗号分开 @param extraconfig: 额外配置, 有的游戏没有额外配置,默认即可 @return: 1:成功; 0:失败 ''' url = util.AUTO_TEST_URL postdata = { "ops": "setmatchconfig", "game": game, "basechiptype": basechiptype, "playmode": playmode, "roomlevel": roomlevel, "baseconfig": baseconfig, "extraconfig": extraconfig, } result = util.post(url, postdata) return util.check_response(result)
def send_message(mid, title, bodys, tool_id=None, num=3, havegot=0): ''' @brief 发送私信 @param mid: 用户mid @param title: 标题 @param bodys: 内容 @param tool_id: 道具id或者id数组 @param num: 数量 @param havegot: @return: 1:成功 ; 0:失败 ''' url = util.AUTO_TEST_URL if tool_id: if type(tool_id) == type(0): tool_id = [tool_id] assert type(tool_id) == type([]) else: tool_id = [] tool_id = tool_id if tool_id else [22] postdata = { "ops": "message", "title": title, "bodys": bodys, "mids": [mid], "rewards": json.dumps([{'type': tid, 'num': num, 'havegot': havegot} for tid in tool_id]) } result = util.post(url, postdata) return util.check_response(result, only_check_code=True)
def login(self): if self.username and self.password and len(self.username) > 0 and len( self.password) > 0: self.info('Login user=%s, pass=*****' % self.username) self.rh.throw = False page = util.request(self.base_url + 'login?key=logreg') if page.find('href="/?do=web-logout') > 0: self.info('Already logged in') return True data = util.substr(page, '<li class=\"menu-username', '</li') m = re.search('key=(?P<key>[^\"]+)\"', data, re.IGNORECASE | re.DOTALL) token = re.search( '<input type=\"hidden\" name=\"_token_\".+?value=\"([^\"]+)"', page, re.IGNORECASE | re.DOTALL) if m and token: login_url = self.base_url + 'login?key=' + m.group( 'key') + '&do=loginForm-submit' data = util.post( login_url, { 'username': self.username, 'password': self.password, 'remember': 'on', 'login': '******', '_token_': token.group(1) }) if data.find('href="/?do=web-logout') > 0: self.info('Login successfull') return True self.info('Login failed') return False
def set_robot_flag(gameid, basechiptype=0, playmode=1, roomlevel=1, robotflag=0): ''' @brief 设置场次配置机器人状态 @param gameid: 游戏id @param basechiptype: 底注 @param playmode: 玩法 @param roomlevel: 场次 @param robotflag: 机器人状态 0 关闭 1 开启 2 开启等待时间 @return: 1:成功; 0:失败 ''' url = util.AUTO_TEST_URL postdata = { "ops": "setrobotflag", "game": gameid, "basechiptype": basechiptype, "playmode": playmode, "roomlevel": roomlevel, "robotflag": robotflag } result = util.post(url, postdata) return util.check_response(result)
def list(self, url): result = [] headers, req = self._create_request( url, { 'what': '', 'offset': 0, 'limit': 25, 'category': '', 'sort': '', 'wst': self.token }) data = util.post(self._url('api/search/'), req, headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': self.error('Server returned error status, response: %s' % data) return [] total = int(xml.find('total').text) for file in xml.findall('file'): item = self.video_item() item['title'] = file.find('name').text item['url'] = 'ident=%s' % file.find('ident').text size = int(file.find('size').text) item['size'] = '%d MB' % (int(size) / 1024 / 1024) img = file.find('img').text if img: item['img'] = self._url(img) self._filter(result, item) listed = int(req['limit']) + int(req['offset']) if total > listed: req['offset'] = listed item = self.dir_item() item['type'] = 'next' item['url'] = urllib.urlencode(req) result.append(item) return result
def follow_create(id): data = util.post( '/follow/add', { 'sport_id': get_user_answer(id, 'follow_sport'), 'location': get_user_answer(id, 'follow_location') }, get_auth(id)) return data['event_ids']
def set_user_rank(mid, api, type, value): ''' @brief 获取或设置排行榜内 set_user_rank(2193478, 103000, 'exp', 1) @param mid: 用户mid @param api: 应用id @param type: 类型 @param value: 值 @return: 1:成功; 0:失败 ''' url = "http://192.168.200.21/dfqp/index.php?action=externals.autoTest" guid = uuid.uuid1() inner = OrderedDict([("tab", OrderedDict([("type", type), ("value", value)]))]) millions = str(int(time.time())) code = OrderedDict([("mid", mid), ("api", api), ("guid", str(guid)), ("cmds", inner)]) codestr = json.dumps(code, encoding="UTF-8", separators=(',', ':')) base64_codesrc = base64.b64encode(codestr) src = base64_codesrc + millions + "terfv%^&4826oo" md5 = hashlib.md5() md5.update(src) key = md5.hexdigest() postdata = { "action": 'externals.autoTest', "key": key, "time": millions, "code": base64_codesrc } postdata = json.dumps(postdata) result = util.post(url, postdata) return check_result(result)
def add_proxy(mid, pno, name, invitepno, region=1, isstore=1, sjname='test', sjarea=1, partner=1): ''' @brief 添加代理商 @param mid: 用户mid @param pno: 用户手机号 @param name: 用户姓名 @param invitepno: 上级代理商id @param region: 地区id @param isstore: 是否商家摊位 0:否 ; 1:是 @param sjname: 商家名称 @param sjarea: 商家区域 1:延吉市; 2:图们市; 3:敦化市; 4:龙井市 ; 5:珲春市; 6:和龙市 ; 7:汪清县; 8:安图县 @param partner: 是否推广员 0:否; 1:是 @return: 1:成功; 0:失败 ''' url = util.AUTO_TEST_URL postdata = { "ops": 'agent', "mid": mid, "pno": pno, "name": name, "isstore": isstore, "region": region, "invitepno": invitepno, # 2031899, "sjname": sjname, "sjarea": sjarea, "partner": partner } result = util.post(url, postdata) return util.check_response(result)
def addCarPerson(numberOfCarPersons): #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF if (numberOfCarPersons == 0): payload = settings.add_car_person_template.substitute( Id=str(numberOfCarPersons), personId="user" + str(numberOfCarPersons)) # Send the POST request REST CONF resp = util.nonprintpost(settings.getAddCarPersonUrl(), "admin", "admin", payload) return for x in range(1, numberOfCarPersons + 1): strId = str(x) payload = settings.add_car_person_template.substitute(Id=strId, personId="user" + strId) # Send the POST request REST CONF resp = util.post(settings.getAddCarPersonUrl(), "admin", "admin", payload) print("payload formed after template substitution=") print(payload) print("the response of the POST to add car_person=") print(resp) print("getting the car_persons for verification") resp = getCarPersonMappings(0)
def set_splash( region, start_time=int(time.time()), end_time=int(time.time() * 60 * 10), background="https://dfqppic.266.com/dfqp/pic/flashscreen/4e05xkrv.jpg", splashscreen="https://dfqppic.266.com/dfqp/pic/flashscreen/4e05xkrv.jpg" ): ''' @brief 设置闪屏图片 @param start_time: 开始时间:从1970开始的秒数(默认从当前时间开始) @param end_time: 结束时间:从1970开始的秒数(默认从当前开始时间+10分钟) @param backgroun: 背景图片url @param splashscreen: 闪屏图片url @return: 1:成功 ; 0:失败 ''' url = util.AUTO_TEST_URL postdata = { "ops": 'bg', "region": region, "stime": start_time, "etime": end_time, "background": background, "splashScreen": splashscreen } result = util.post(url, postdata) return util.check_response(result)
def delete_event(bot, update): query = update.callback_query data = query.data[len('delete:'):] query.answer() try: util.post('/event/close', { 'event_id': int(data), 'event_status': 'Canceled', 'results': {} }, get_auth(query.message.chat_id)) bot.edit_message_text(text="Событие удалено", chat_id=query.message.chat_id, message_id=query.message.message_id) except Exception as e: bot.send_message(chat_id=query.message.chat_id, text=str(e))
def show_location_event(bot, update): query = update.callback_query data = query.data[len('map:'):] query.answer() try: ans = util.post('/event/get', {'event_id': int(data)}, get_auth(query.message.chat_id)) location_id = ans['event_info']['location'] ans = util.post('/location/list', {}, get_auth(query.message.chat_id)) ans = ans[str(location_id)] bot.send_location(chat_id=query.message.chat_id, longitude=ans['longitude'], latitude=ans['latitude']) except Exception as e: bot.send_message(chat_id=query.message.chat_id, text=str(e))
def login(self): if self.username and self.password and len(self.username) > 0 and len(self.password) > 0: self.info("Login user=%s, pass=*****" % self.username) self.rh.throw = False page = util.request(self.base_url + "login?key=logreg") if page.find('href="/?do=web-logout') > 0: self.info("Already logged in") return True data = util.substr(page, '<li class="menu-username', "</li") m = re.search('key=(?P<key>[^"]+)"', data, re.IGNORECASE | re.DOTALL) token = re.search('<input type="hidden" name="_token_".+?value="([^"]+)"', page, re.IGNORECASE | re.DOTALL) if m and token: login_url = self.base_url + "login?key=" + m.group("key") + "&do=loginForm-submit" data = util.post( login_url, { "username": self.username, "password": self.password, "remember": "on", "login": "******", "_token_": token.group(1), }, ) if data.find('href="/?do=web-logout') > 0: self.info("Login successfull") return True self.info("Login failed") return False
def addPerson(numberOfPersons): #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF if(numberOfPersons==0): strId =str(numberOfPersons) payload = settings.add_person_payload_template.substitute(personId="user"+strId,gender="unknown",age=0, address=strId + "Way, Some Country, Some Zip "+strId, contactNo= "some number"+strId) # Send the POST request using RESTCONF resp = util.nonprintpost(settings.getAddPersonUrl(),"admin", "admin",payload) return genderToggle = "Male" for x in range(1, numberOfPersons+1): if(genderToggle == "Male"): genderToggle = "Female" else: genderToggle = "Male" strId = str(x) payload = settings.add_person_rpc_payload_template.substitute(personId="user"+strId,gender=genderToggle,age=(20+x%100), address=strId + "Way, Some Country, Some Zip "+str(x%1000), contactNo= "some number"+strId) # Send the POST request using RPC resp = util.post(settings.getAddPersonRpcUrl(),"admin", "admin",payload) print("payload formed after template substitution=") print(payload) print("the response of the POST to add person=") print(resp) print("getting the persons for verification") resp=getPersons(0)
def set_notice(title, content, id=1, app_id=103000, region=1, weight=1, start_time=int(time.time()), end_time=int(time.time() + 60 * 10), is_html=1, status=1, conditions={"min_version": "0", "max_version": "0", "stime": "08:4:38", "etime": "20:4:40", "week":[0,1,2,3,4,5,6],"sendtype":0,"poptype":0,"isLogined":0}): ''' @brief 公告设置 @param title: 标题 @param content: 内容 @param id:公告id @param app_id: 应用id @param region: 区域id @param weight: 排序权重 @param start_time: 开始时间:从1970开始的秒数(默认从当前时间开始) @param end_time: 结束时间:从1970开始的秒数(默认从当前开始时间+10分钟) @param is_html: 0:文本公告 ; 1:富文本公告 ; 2:图片公告 @param status: 状态 0:关闭 1:正常 @param conditions: 附加条件(min_version:最小版本,max_version:最大版本,stime:生效开始,etime:生效结束,poptype:弹出频次 0:只弹一次 1:每天一次 2:每次弹出) @return: 1:成功; 0:失败 ''' url = util.AUTO_TEST_URL postdata = { "ops": 'notice', "id" : id, "app_id": app_id, "title": title, "content": json.dumps(content) if is_html ==2 else content, "weight": weight, "region": region, "start_time": time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(start_time)), "end_time": time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(end_time)), "is_html": is_html, "status": status, "conditions": json.dumps(conditions) } result = util.post(url, postdata) return util.check_response(result)
def addCarPerson(numberOfCarPersons): #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF if(numberOfCarPersons==0): payload = settings.add_car_person_template.substitute(Id=str(numberOfCarPersons),personId="user"+str(numberOfCarPersons)) # Send the POST request REST CONF resp = util.nonprintpost(settings.getAddCarPersonUrl(),"admin", "admin",payload) return for x in range(1, numberOfCarPersons+1): strId = str(x) payload = settings.add_car_person_template.substitute(Id=strId,personId="user"+strId) # Send the POST request REST CONF resp = util.post(settings.getAddCarPersonUrl(),"admin", "admin",payload) print("payload formed after template substitution=") print(payload) print("the response of the POST to add car_person=") print(resp) print("getting the car_persons for verification") resp=getCarPersonMappings(0)
def withdraw_safebox(mid, money, money_type): ''' @brief 取保险箱 @param mid: 用户mid @param money: 银币/金条数量 @param money_type: 0: 银币 1: 金条 @return: 取出金额 ''' url = util.AUTO_TEST_URL postdata = { "ssid": "", "ops": "updatesafebox", "mid": mid, "type": 2, "money": money, "money_type": money_type } response = util.post(url, postdata) result = 0 try: response = json.loads(response) if response.get('code', -1) == 200 and response.get('result', None): result = response.get('result').get('money', 0) except: pass return -result
def register(bot, update, args): if len(args) != 2: bot.send_message(chat_id=update.message.chat_id, text='Логин и пароль необходимы!') return try: util.post('/register', {'username': args[0], 'password': args[1]}) registered_users[update.message.chat_id] = { 'username': args[0], 'password': args[1] } save_user_data() msg = 'Регистрация успешно выполнена!' except Exception as e: msg = 'Невозможно зарегестрироваться с таким логином/паролем!' bot.send_message(chat_id=update.message.chat_id, text=msg)
def post_list(l, url, api_token): logger.debug("list: %s url: %s" % (l, url,)) if l and url and api_token: d = json.loads(util.post(url, to_list_json(l), api_token)) return List(id=d['list']['id'], name=d['list']['name'], stringid=d['list']['stringid']) return dict()
def userData(self): if self.token: headers,req = self._create_request('/',{'wst':self.token}) data = util.post(self._url('api/user_data/'), req, headers=headers) xml = ET.fromstring(data) if xml.find('vip').text == '1': return xml.find('vip_days').text return False
def crawl(): PATIENCE = 15 MAX_RETRY = 3 SOURCE_NAME = "동아일보" MAIN_URL = "http://www.donga.com/" driver = util.get_driver() driver.set_page_load_timeout(PATIENCE) driver.get(MAIN_URL) INCLUDE_URLS = ["news.donga.com/Main", "news.donga.com/MainTop"] article_links = [] timeout_cnt = 0 skipped_cnt = 0 href_elms = driver.find_elements_by_css_selector("[href]") for e in href_elms: href = e.get_attribute("href") for i in INCLUDE_URLS: if i in href: article_links.append(href) break print("%d articles found" % len(article_links)) for i in article_links: for retry in range(0, MAX_RETRY): try: article = extract(driver, i) util.post(article, SOURCE_NAME) break except (TimeoutException, NoSuchElementException, StaleElementReferenceException): if retry == MAX_RETRY - 1: skipped_cnt += 1 else: driver.refresh() timeout_cnt += 1 driver.quit() print("Done with %d timeouts and %d skipped pages in %d links" % (timeout_cnt, skipped_cnt, len(article_links)))
def login(bot, update, args): if len(args) != 2: bot.send_message(chat_id=update.message.chat_id, text='Логин и пароль необходимы!') return try: util.post('/register/check', { 'username': args[0], 'password': args[1] }) registered_users[update.message.chat_id] = { 'username': args[0], 'password': args[1] } save_user_data() msg = 'Вход в систему успешно выполнен!' except Exception as e: msg = 'Неправильный логин/пароль!' bot.send_message(chat_id=update.message.chat_id, text=msg)
def url(url): m = _regex(url) if m: id = m.group('id') post = {'r':'["tVL0gjqo5",["preview/flv_image",{"uid":"'+id+'"}],["preview/flv_link",{"uid":"'+id+'"}]]'} data = util.post('http://api.letitbit.net',post) data = data.replace('\\','') print data link = re.search('link\"\:\"(?P<link>[^\"]+)',data) if link: return [{'url':link.group('link')}]
def resolve(self,item,captcha_cb=None,select_cb=None): item = item.copy() util.init_urllib() headers,req = self._create_request(item['url'],{'ident':'','wst':self.token}) data = util.post(self._url('api/file_link/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': self.error('Server returned error status, response: %s' % data) raise ResolveException(xml.find('message').text) item['url'] = xml.find('link').text return item
def login(self): if not self.username and not self.password: return True # fall back to free account elif self.username and self.password and len(self.username)>0 and len(self.password)>0: headers,req = self._create_request('',{'username_or_email':self.username}) data = util.post(self._url('api/salt/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': return False salt = xml.find('salt').text if salt is None: salt = '' password = hashlib.sha1(md5crypt(self.password.encode('utf-8'), salt.encode('utf-8'))).hexdigest() digest = hashlib.md5(self.username + ':Webshare:' + self.password).hexdigest() headers,req = self._create_request('',{'username_or_email':self.username,'password':password,'digest':digest,'keep_logged_in':1}) data = util.post(self._url('api/login/'),req,headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': return False self.token = xml.find('token').text return True return False
def userData(self): if self.token: headers,req = self._create_request('/',{'wst':self.token}) data = util.post(self._url('api/user_data/'), req, headers=headers) xml = ET.fromstring(data) xml.find('vip').text isVip = xml.find('vip').text vipDays = xml.find('vip_days').text ident = xml.find('ident').text if isVip != '1': isVip = '0' return wsUserData(isVip, vipDays, ident) return wsUserData('-1', '0', '')
def login(self): if self.username and self.password and len(self.username)>0 and len(self.password)>0: page = util.request(self.base_url+'?do=loginBox-loginpopup') if page.find('href="/?do=loginBox-logout') > 0: self.info('Already logged in') return True data = util.substr(page,'<td class=\"popup-lef','</form') m = re.search('<form action=\"(?P<url>[^\"]+)',data,re.IGNORECASE | re.DOTALL) if m: login_url = self._url(m.group('url')).replace('&','&') data = util.post(login_url,{'username':self.username,'password':self.password,'pernament_login':'******','login':'******','redir_url':self.base_url+'?do=loginBox-login'}) if data.find('href="/?do=loginBox-logout') > 0: return True return False
def resolve(self, ident, devid, dwnType='video_stream'): try: headers,req = self._create_request('/',{'ident':ident,'wst':self.token, 'download_type': dwnType, 'device_uuid': devid }) # @TODO add params, maybe later 'device_res_x': infoLabel('System.ScreenWidth'), 'device_res_y': infoLabel('System.ScreenHeight'), #util.info(headers) #util.info(req) data = util.post(self._url('api/file_link/'), req, headers=headers) xml = ET.fromstring(data) if not xml.find('status').text == 'OK': #util.error('Server returned error status, response: %s' % data) raise ResolveException(xml.find('message').text) return xml.find('link').text except: raise
def resolve(url): m = _regex(url) if m: vid = m.group("vid") headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Content-Type": "text/html; charset=utf-8", } player_url = "http://hqq.tv/player/embed_player.php?vid=%s&autoplay=no" % vid data = util.request(player_url, headers) b64enc = re.search('base64([^"]+)', data, re.DOTALL) b64dec = b64enc and base64.decodestring(b64enc.group(1)) enc = b64dec and re.search("'([^']+)'", b64dec).group(1) if enc: data = re.findall('<input name="([^"]+?)" [^>]+? value="([^"]+?)">', _decode(enc)) post_data = {} for idx in range(len(data)): post_data[data[idx][0]] = data[idx][1] data = util.post(player_url, post_data, headers) b64enc = re.search('base64([^"]+)', data, re.DOTALL) b64dec = b64enc and base64.decodestring(b64enc.group(1)) enc = b64dec and re.search("'([^']+)'", b64dec).group(1) if enc: data = re.findall('<input name="([^"]+?)" [^>]+? value="([^"]*)">', _decode(enc)) post_data = {} for idx in range(len(data)): post_data[data[idx][0]] = data[idx][1] data = urllib.unquote( util.request("http://hqq.tv/sec/player/embed_player.php?" + urllib.urlencode(post_data), headers) ) vid_server = re.search(r'var\s*vid_server\s*=\s*"([^"]*?)"', data) vid_link = re.search(r'var\s*vid_link\s*=\s*"([^"]*?)"', data) at = re.search(r'var\s*at\s*=\s*"([^"]*?)"', data) if vid_server and vid_link and at: get_data = { "server": vid_server.group(1), "link": re.sub(r"\?socket=?$", ".mp4.m3u8", vid_link.group(1)), "at": at.group(1), "adb": "0/", } data = json.load( StringIO( util.request("http://hqq.tv/player/get_md5.php?" + urllib.urlencode(get_data), headers) ) ) if "file" in data: return [{"url": _decode2(data["file"]), "quality": "360p"}] return None
def method(self, method_name, check_content=True, **kwargs): content = dict() content['data'] = dict() content['url'] = 'https://api.telegram.org/bot{}/{}'.format(self.misc['token'], method_name) if check_content: if self.message['chat']['type'] != 'private': content['data'].update({'reply_to_message_id': self.message['message_id']}) if 'chat_id' not in kwargs: content['data'].update({'chat_id': self.message['chat']['id']}) if 'file' in kwargs: content['files'] = kwargs.pop('file') content['data'].update(kwargs) response = util.post(content, self.misc['session']).json() if not response['ok']: print('Error with response\nResponse: {}\nSent: {}'.format(response, content)) return response
def addCar(numberOfCars): for x in range(1, numberOfCars+1): strId = str(x) payload = settings.add_car_payload_template.substitute(id=strId,category="category"+strId,model="model"+strId, manufacturer="manufacturer"+strId, year=(2000+x%100)) print("payload formed after template substitution=") print(payload) # Send the POST request resp = util.post(settings.getAddCarUrl(),"admin", "admin",payload) print("the response of the POST to add car=") print(resp) print("getting the cars in store ") resp = getCars(0)
def buyCar(numberOfCarBuyers): for x in range(1, numberOfCarBuyers+1): strId = str(x) payload = settings.buy_car_rpc_template.substitute(personId="user"+strId,carId=strId) # Send the POST request using RPC resp = util.post(settings.getBuyCarRpcUrl(),"admin", "admin",payload) print("payload formed after template substitution=") print(payload) print("the response of the POST to buycar=") print(resp) print("getting the car_persons for verification") resp=getCarPersonMappings(0)
def resolve(url): if not _regex(url) == None: util.init_urllib() web_url = get_host(url) data = util.substr(util.request(web_url),'<form method=\"post','</form>') # need to POST input called confirm to url, fields: hash, confirm found in request' m = re.search('<input(.+?)value=\"(?P<hash>[^\"]+)(.+?)name=\"hash\"(.+?)<input name=\"confirm\"(.+?)value=\"(?P<confirm>[^\"]+)',data,re.IGNORECASE | re.DOTALL) if not m == None: data = util.post(web_url,{'confirm':m.group('confirm'),'hash':m.group('hash')}) # now, we've got (flow)player data = util.substr(data,'flowplayer(','</script>') n = re.search('playlist\: \'(?P<pls>[^\']+)',data,re.IGNORECASE | re.DOTALL) if not n == None: # now download playlist xml = util.request('http://www.putlocker.com'+n.group('pls')) stream = re.search('url=\"([^\"]+)\" type=\"video',xml,re.IGNORECASE | re.DOTALL).group(1) return [{'url':stream}]
def login(self): if self.username and self.password and len(self.username)>0 and len(self.password)>0: self.info('Login user=%s, pass=*****' % self.username) self.rh.throw = False page = util.request(self.base_url+'?do=web-login') if page.find('href="/?do=web-logout') > 0: self.info('Already logged in') return True data = util.substr(page,'<li class=\"menu-username','</li') m = re.search('key=(?P<key>[^\"]+)\"',data,re.IGNORECASE | re.DOTALL) if m: login_url = self.base_url+'login?key='+m.group('key')+'&do=loginForm-submit' data = util.post(login_url,{'username':self.username,'password':self.password,'remember':'on','login':'******'}) if data.find('href="/?do=web-logout') > 0: self.info('Login successfull') return True self.info('Login failed') return False
def url(url): m = _regex(url) if not m == None: data = util.substr(util.request(url),'class=\"proform\"','</form>') #print data form_values = {} pattern = '<input.+?name="(?P<name>.*?)".+?value="(?P<value>.*?)"' for n in re.finditer(pattern,data,re.IGNORECASE | re.DOTALL ): form_values[n.group('name')] = n.group('value') #print form_values try: #time.sleep(10) resp = util.post(url,form_values) except: util.error('streamcloud: got http error fetching %s' % (url)) return False r = re.search('file: "(.+?)",', resp) if r: return [r.group(1)]
def url(url): if supports(url): ''' if self.get_setting('login') == 'true': if login_stale(): login() #self.net.set_cookies(cookie_file) ''' host,media_id=get_host_and_id(url) web_url = get_host(host,media_id) #find session_hash try: html = util.request(web_url) except urllib2.URLError, e: print ('putlocker: got http error %d fetching %s' % (e.code, web_url)) return False #Shortcut for logged in users pattern = '<a href="(/.+?)" class="download_file_link" style="margin:0px 0px;">Download File</a>' link = re.search(pattern, html) if link: print 'Direct link found: %s' %link.group(1) return 'http://www.putlocker.com%s' %link.group(1) r = re.search('value="([0-9a-f]+?)" name="hash"', html) if r: session_hash = r.group(1) else: print ('putlocker: session hash not found') return False #post session_hash try: html = util.post(web_url, {'hash': session_hash,'confirm': 'Continue as Free User'}) except urllib2.URLError, e: print ('putlocker: got http error %d posting %s' %(e.code, web_url)) return False
def login(url=BASE_URL): url = furl(url) username = __addon__.getSetting("csfd-user") if username == "": # TODO notify user to provide some user/pass xbmcgui.Dialog().ok(__scriptname__, __language__(30042)) return password = __addon__.getSetting("csfd-pass") cookiefile = os.path.join(xbmc.translatePath(__addon__.getAddonInfo("profile")), "cookies.txt") # install cookie handler cj = cookielib.LWPCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) # load cookies from file if os.path.exists(cookiefile): cj.load(cookiefile, ignore_discard=True, ignore_expires=True) data = util.request(url) if data.find("prihlaseni/odhlaseni") > 0: util.info("Logged in - continuing session") return data # let's try log in data = util.post( BASE_URL + "prihlaseni/prihlaseni/?do=form-submit", {"username": username, "password": password, "__REFERER__": url, "ok": "Prihlasit"}, ) if data.find("prihlaseni/odhlaseni") > 0: util.info("CSFD login successfull") # save correct cookies cj.save(cookiefile, True, True) return data else: util.info("CSFD login error, invalid user/pass?") xbmcgui.Dialog().ok(__scriptname__, __language__(30043)) return
def get_assets_by_ip(self, ip_list): timestamp = int(time.time()) app_key = self.gen_app_key(timestamp) data = { "version": "1.0", "app_key": app_key, "app_name": self.opts['app_name'], "operator": 'system', "method": "get_device_by_ip", "timestamp": timestamp, "data": { "ip_list": ip_list } } try: result = post(self.opts['zcmdb_url'], data) except: log.logger.error(traceback.format_exc()) raise Exception, u'zcmdb查询设备接口调用失败' if not result: raise Exception, u'zcmdb查询设备接口调用失败' if result['code'] != 0 and result['code'] != 1104: raise Exception, u'zcmdb查询设备接口调用失败,%s' % result['message'] return result['value']
# ), tree.body, lambda bs: bs.code.add(isa.mov(registers.rsp, registers.rbp)), lambda bs: bs.code.add(isa.pop(registers.rbp)), lambda bs: bs.code.add(isa.ret()), compiler.end, ]) def caller(): p = util.Program() code = p.get_stream() code += isa.mov(registers.rax, make_root()) code += isa.call(registers.rax) #util.add_redirection(code, lambda rdi: util.get_call(make_root())) p.add(code) p.cache_code() util.debug(p, "caller") return p caller = caller() processor = platform.Processor() if util.DEBUG: print "START" start = time.time() processor.execute(caller) if util.DEBUG: end = time.time() print "END", end - start util.post()
def search(self,keyword): data = util.post(self._url('search.php'),{'t':keyword,'submit':'Hledat'}) return self.film(data)
def parse_data(): # Stiahnutie udajov mesto = __addon__.getSetting('mesto') mestometeogram = __addon__.getSetting('mestometeogram') key = __addon__.getSetting('key') try: pages = int(__addon__.getSetting('pages')) except ValueError: pages = 6 if not key: xbmcgui.Dialog().ok('Chyba', 'Zadajte v nastaveniach kľúč k OpenWeather API!') return True data = {'mesto': mesto, 'page': '1', 'id': 'meteo_predpoved_sk'} url = 'http://www.shmu.sk/sk/?#tab' page = util.post(url, data) soup = bs4.BeautifulSoup(page, "html5lib") print('mesto: %s, den: %s' % (mesto, den)) cnt = 1 for x in soup.select('.w600')[0].tbody.findAll('td', 'center'): if x.has_attr('style'): if 'white-space' in x['style']: print('Daily.%s.LongDay' % cnt, skdays[den + cnt - 1]) set_property('Daily.%s.LongDay' % cnt, skdays[den + cnt - 1]) set_property('Daily.%s.ShortDay' % cnt, skdays[den + cnt - 1]) night, day = x.get_text(separator='|').split('|') set_property('Daily.%s.HighTemperature' % cnt, day) set_property('Daily.%s.LowTemperature' % cnt, night) elif 'background:#00660E' in x['style']: imgname = x.img['src'].split('/')[-1] set_property('Daily.%s.Outlook' % cnt, x.img['alt']) image_name = x.img['src'].split('/')[-1] set_property('Daily.%s.OutlookIcon' % cnt, WEATHER_CODES[ image_name.replace('.gif', '')] + '.png') cnt += 1 url = 'http://api.openweathermap.org/data/2.5/find?q=%s&type=like&mode=json&APPID=%s&units=metric' \ % (urllib2.quote(mesto), key) req = urllib2.urlopen(url) response = req.read() req.close() jsonresponse = demjson.decode(response)['list'][0] set_property('Current.Temperature', str(jsonresponse['main']['temp'])) set_property('Current.Wind', str(jsonresponse['wind']['speed'] * 3.6)) try: set_property('Current.WindDirection', degToCompass(jsonresponse['wind']['deg'])) except: pass set_property('Current.FeelsLike', feelslike(round(float(jsonresponse['main']['temp'])), int(round(float(jsonresponse['wind']['speed']) * 3.6) + 0.5))) set_property('Current.Humidity', str(jsonresponse['main']['humidity'])) set_property('Current.DewPoint', dewpoint(round(float(jsonresponse['main']['temp'])), int(jsonresponse['main']['humidity']))) set_property('Current.Pressure', str(jsonresponse['main']['pressure'])) set_property('Current.Condition', str(jsonresponse['weather'][0]['main'])) iconfilename = en2icon[jsonresponse['weather'][0]['main'].lower()] if not iconfilename: iconfilename = 'none' set_property('Current.OutlookIcon', xbmc.translatePath(os.path.join( __cwd__, 'resources/lib/icons', '%s.png' % iconfilename))) meteogrampage = util.parse_html('http://www.shmu.sk/sk/?page=1&id=meteo_num_mgram') cityid = meteogrampage.select('select#nwp_mesto')[0].find(text=mestometeogram).parent['value'] day, month, year, hour, text = re.split( '[. ]', meteogrampage.select('select[class=w150] option')[-1].text) meteogramdate = '%s%s%s-%s00' % (year, month, day, hour) query = 'http://www.shmu.sk/data/datanwp/v2/' +\ 'meteogram/al-meteogram_%s-%s-nwp-.png' \ % (cityid, meteogramdate) req = urllib2.Request(query) response = urllib2.urlopen(req, timeout=10) meteogramimage = Image.open(cStringIO.StringIO(response.read())) response.close() set_property('Map.IsFetched', '') print('Stahujem meteogram..') cut_picture(pages=pages, meteogramimage=meteogramimage, meteogramdate=meteogramdate)
def search(self, keyword): data = util.post(self.base_url + "vyhledavani", {"btnsearch": "OK", "txtsearch": keyword}) return self.show(data)
def list(self, url): self.info("list %s" % url) if url.find("#cat#") == 0: self.debug("listing subcategories...") return self.subcategories(url[5:]) p_url = urlparse.urlparse(url) url = unfragment(p_url) s_path = clean_path(p_url.path).split("/") if "joj.sk" not in p_url.netloc: self.error("%s is not a joj.sk url!" % (url)) return [] if p_url.path == "/ajax.json": self.debug("listing episodes data (ajax)") headers = { 'X-Requested-With': 'XMLHttpRequest', 'Referer': util.substr(url, url, url.split('/')[-1]) } data = util.request(url, headers) data = util.json.loads(data)['content'] return self.list_episodes_data(data, 1) elif "post=" in p_url.fragment: self.debug("listing episodes data (post)") headers = { 'X-Requested-With': 'XMLHttpRequest', 'Referer': util.substr(url, url, url.split('/')[-1]) } sid = p_url.fragment.split("post=")[1] data = {"do": "archive", "series": sid} data = util.post(url, data, headers) return self.list_episodes_data(data, 2) elif len(s_path) == 1 and s_path[0] == "": if p_url.fragment == "top": self.debug("listing base url - top part") return self.list_base_page(util.request(self.base_url), top=True) elif p_url.fragment == "new": self.debug("listing base url - new part") return self.list_base_page(util.request(self.base_url), new=True) else: self.debug("listing base url") return self.list_base_page(util.request(self.base_url), top=True, new=True) elif len(s_path) == 1: if s_path[0] not in ("archiv.html", "plus-archiv.html", "wau-archiv.html", "senzi-archiv.html"): self.error("unsupported listing for url - %s" % url) return [] if p_url.fragment == "showon": self.debug("listing show archive url - showon part") return self.list_archive_page(util.request(url), showoff=True) elif p_url.fragment == "showoff": self.debug("listing show archive url - showoff part") return self.list_archive_page(util.request(url), showon=True) else: self.debug("listing show archive url") return self.list_archive_page(util.request(url), showon=True, showoff=True) elif len(s_path) == 2 or len(s_path) == 3: req = urllib2.Request(url) req.add_header("User-Agent", util.UA) resp = urllib2.urlopen(req) p_url2 = urlparse.urlparse(resp.geturl()) page = resp.read() s_path = clean_path(p_url2.path).split("/") if len(s_path) == 2 and s_path[0] == "archiv": m = re.search(r'<li>[^<]+<a href="([^"]+)"\s+title="(Archív|Epizódy)".+?</li>', page, re.DOTALL) url = 'http://' + p_url2.netloc + m.group(1) self.debug("new url = %s" % url) page = util.request(url) if p_url.fragment == "episodes": self.debug("listing show url - episodes part") return self.list_show_page(url, page, episodes=True) elif p_url.fragment == "seasons": self.debug("listing show url - seasons part") return self.list_show_page(url, page, seasons=True) elif p_url.fragment == "season_episode": self.debug("listing show url - seasons/episodes") result = self.list_show_page(url, page, seasons=True) if len(result) == 0: result = self.list_show_page(url, page, episodes=True) return result else: self.debug("listing show url") return self.list_show_page(url, page, seasons=True, episodes=True) else: self.error("unsupported listing for url - %s" % url) return []