def quick_add_insert(text,crns): html = BeautifulSoup(text, html_parser) forms = html.body.find_all('form') reg = forms[1] inputs = reg.find_all(['input','select']) request = [] for input in inputs: if not input.has_attr('name'): if input.has_attr('id'): print("A problem occurred:") else: continue if input.has_attr('value'): #This should always fail for a select. val = input['value'] else: val = '' if val == 'Class Search': #We want to register and not search, continue if crns and input['name'] == 'CRN_IN' and val == '': # Shove our CRN in the first blank field val = crns.pop(0) try: request.append((input['name'], val)) except KeyError: sys.exit(quick_add_issue("Wrong McGill ID or password.")) return urllib.parse.urlencode(request)
def quick_add_wait(text): html = minerva_parser(text) forms = html.body.find_all('form') try: reg = forms[1] except IndexError: sys.exit(quick_add_issue("Registration not open yet.")) inputs = reg.find_all(['input', 'select']) request = [] actual_wait = False for input in inputs: if not input.has_attr('name'): if input.has_attr('id'): print("A problem occurred:") else: continue if input.has_attr('value'): #This should always fail for a select. val = input['value'] else: val = '' if input.has_attr('id') and input['id'].startswith('waitaction'): val = 'LW' actual_wait = True request.append((input['name'], val)) if actual_wait: return urllib.parse.urlencode(request) else: return False
async def proxy_connect(self, proxy_uri, uri, ssl=None, server_hostname=None, proxy_headers=None): request = ['CONNECT {uri.host}:{uri.port} HTTP/1.1'.format(uri=uri)] headers = [] if proxy_headers is not None: headers = [*headers, *proxy_headers] if uri.port == (443 if uri.secure else 80): # pragma: no cover headers.append(('Host', uri.host)) else: headers.append(('Host', '{uri.host}:{uri.port}'.format(uri=uri))) if proxy_uri.user_info: headers.append(( 'Proxy-Authorization', build_authorization_basic(*proxy_uri.user_info), )) request.extend('{}: {}'.format(k, v) for k, v in headers) request.append('\r\n') request = '\r\n'.join(request).encode() self.transport.write(request) status_code, reason, headers = await read_response(self.reader) if not 200 <= status_code < 300: # TODO improve error handling raise ValueError("proxy error: HTTP {}".format(status_code)) if ssl is not None: # Wrap socket with TLS. This ugly hack will be necessary until # https://bugs.python.org/issue23749 is resolved and websockets # drops support for all early Python versions. if hasattr(asyncio.sslproto, '_is_sslproto_available' ) and not asyncio.sslproto._is_sslproto_available(): raise ValueError( "connecting to a wss:// server through a proxy isn't " "supported on Python < 3.5") old_protocol = self old_transport = self.transport ssl2 = ssl if not isinstance(ssl, ssllib.SSLContext): ssl2 = ssllib.create_default_context() self.transport = await self.loop.start_tls(self.transport, self, ssl2)
def params_158(self,codes_nbr,multiselect): params = [] for c359 in ['10', '11']: if c359 == '10': codes3435 = ['10'] else: codes3435 = ['10', '11'] for c3435 in codes3435: increment = round(len(codes_nbr['358'])/4)+1 m1 = 0 m2 = increment for i in range(4): request = [('359', c359),('3435', c3435),(multiselect['3435'],'')] for j in range(m1,m2): request.append((358,codes_nbr['358'][j])) request.append((multiselect['358'],'')) params.append(self.build_request_params(request)) m1 += increment m2 = min(len(codes_nbr['358']),m2+increment) return(params)
def make_course_request(term, subjects): """Perform a request to the minerva site, no context included.""" request = [ ('rsts', 'dummy'), ('crn', 'dummy'), # This is the CRN ('term_in', term), # Term of search ('sel_day', 'dummy'), ('sel_schd', 'dummy'), ('sel_insm', 'dummy'), ('sel_camp', 'dummy'), ('sel_levl', 'dummy'), ('sel_sess', 'dummy'), ('sel_instr', 'dummy'), ('sel_ptrm', 'dummy'), ('sel_attr', 'dummy'), ('sel_subj', 'dummy') ] for subj in subjects: request.append(('sel_subj', subj)) request.extend([ ('sel_crse', ''), # Course code ('sel_title', ''), ('sel_schd', '%'), ('sel_from_cred', ''), ('sel_to_cred', ''), ('sel_levl', '%'), ('sel_ptrm', '%'), ('sel_instr', '%'), ('sel_attr', '%'), ('begin_hh', '0'), ('begin_mi', '0'), ('begin_ap', 'a'), ('end_hh', '0'), ('end_mi', '0'), ('end_ap', 'a'), ('SUB_BTN', 'Get Course Sections'), ('path', '1') ]) #This is seriously what Minerva shoves into a search form return urllib.parse.urlencode(request)
def params_158(self, codes_nbr, multiselect): params = [] for c359 in ['10', '11']: if c359 == '10': codes3435 = ['10'] else: codes3435 = ['10', '11'] for c3435 in codes3435: increment = round(len(codes_nbr['358']) / 4) + 1 m1 = 0 m2 = increment for i in range(4): request = [('359', c359), ('3435', c3435), (multiselect['3435'], '')] for j in range(m1, m2): request.append((358, codes_nbr['358'][j])) request.append((multiselect['358'], '')) params.append(self.build_request_params(request)) m1 += increment m2 = min(len(codes_nbr['358']), m2 + increment) return (params)
def buildTileRequest(self, layer=None, style=None, format=None, tilematrixset=None, tilematrix=None, row=None, column=None): request = {'version': self.version, 'request': 'GetTile'} if (layer is None): raise ValueError("layer is mandatory (cannot be None)") if style is None: style = list(self[layer].styles.keys())[0] if format is None: format = self[layer].formats[0] if tilematrixset is None: tilematrixset = self[layer].tilematrixsets[0] if tilematrix is None: raise ValueError("tilematrix (zoom level) is mandatory (cannot be None)") if row is None: raise ValueError("row is mandatory (cannot be None)") if column is None: raise ValueError("column is mandatory (cannot be None)") request = list() request.append(('SERVICE', 'WMTS')) request.append(('REQUEST', 'GetTile')) request.append(('VERSION', '1.0.0')) request.append(('LAYER', layer)) request.append(('STYLE', style)) request.append(('TILEMATRIXSET', tilematrixset)) request.append(('TILEMATRIX', tilematrix)) request.append(('TILEROW', str(row))) request.append(('TILECOL', str(column))) request.append(('FORMAT', format)) data = urlencode(request, True) return data
NOWPRICE = auto() #nowprice of stocks (int) STANDARD = auto() #standard value (int) STATE = auto() #Is it OK tweet? (Boolan) TWEET = auto() #Should we tweet? (Boolean) class Request(Enum): CODE = 0 UPDOWN = auto() STANDARD = auto() request = [] price = [] now_price = [] request.append(["5019", "DOWN", 2479]) request.append(["3390", "UP", 91]) price_list = [[0] * 2 for i in range(len(request))] #[[now_price][past_price]] stock_list = [["0"] * len(StockList) for i in range(2)] def makeStockList(prm_stock_list, prm_request): for i in range(len(prm_request)): prm_stock_list[i][StockList.CODE.value] = prm_request[i][ Request.CODE.value] if prm_request[i][Request.UPDOWN.value] == "DOWN": prm_stock_list[i][StockList.UPDOWN.value] = False else: prm_stock_list[i][StockList.UPDOWN.value] = True
def getTravelTimes(self, latitude, longitude, depth, locations=[], model='iasp91'): """ Returns travel times for specified station-event geometry using standard velocity models such as ``iasp91``, ``ak135`` or ``qdt``. :type latitude: float :param latitude: Event latitude. :type longitude: float :param longitude: Event longitude. :type depth: float :param depth: Event depth in km. :type locations: list of tuples :param locations: Each tuple contains a pair of (latitude, longitude) of a station. :type model: str, optional :param model: Velocity model, one of ``'iasp91'``, ``'ak135'``, or ``'qdt'``. Defaults to ``'iasp91'``. :return: List of dicts containing phase name and arrival times in ms. .. seealso:: http://www.orfeus-eu.org/wsdl/taup/taup.wsdl .. rubric:: Example >>> client = Client() >>> locations = [(48.0, 12.0), (48.1, 12.0)] >>> result = client.getTravelTimes(latitude=20.0, longitude=20.0, ... depth=10.0, locations=locations, ... model='iasp91') >>> len(result) 2 >>> result[0] # doctest: +SKIP {'P': 356981.13561726053, 'S': 646841.5619481194} """ # enable logging if debug option is set if self.debug: import logging logging.basicConfig(level=logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) # initialize client client = SudsClient(TAUP_WSDL) # set cache of 5 days cache = client.options.cache cache.setduration(days=5) # create request request = [] for location in locations: req = {'event-depth': float(depth), 'event-lat': float(latitude), 'event-lon': float(longitude), 'model': str(model), 'point-lat': float(location[0]), 'point-lon': float(location[1])} request.append(req) data = client.service.getArrivalTimes(request) result = [] for item in data: times = {} if hasattr(item, 'arrival-time'): for time in item['arrival-time']: times[str(time._phase)] = float(time['_time-ms']) result.append(times) return result
def _doAction(self, action): """This function will perform a FileMaker action.""" if self._db == '': raise FMError('No database was selected') try: uu = urllib.parse.urlencode request = [ uu({'-db': self._db}) ] if self._layout != '': request.append(uu({'-lay': self._layout})) if action == '-find' and self._lop != 'and': request.append(uu({'-lop': self._lop})) if action in ['-find', '-findall']: if self._skipRecords != 0: request.append(uu({'-skip': self._skipRecords})) if self._maxRecords != 0: request.append(uu({'-max': self._maxRecords})) #else: # request.append( uu( { '-max': 'all' } ) ) for i in range(0, len(self._sortParams)): sort = self._sortParams[i] request.append(uu({'-sortfield.' + str(i + 1): sort[0]})) if sort[1] != '': request.append(uu({'-sortorder.' + str(i + 1): sort[1]})) for dbParam in self._dbParams: if dbParam[0] == 'RECORDID': request.append(uu({'-recid': dbParam[1]})) elif dbParam[0] == 'MODID': request.append(uu({'-modid': dbParam[1]})) elif hasattr(dbParam[1], 'strftime'): d = dbParam[1] if (not d.hasattr(d, 'second')) and (d.second + d.minute * 60 + d.hour * 3600) == 0: request.append(uu({dbParam[0]: d.strftime('%m-%d-%Y')})) else: request.append(uu({dbParam[0]: d.strftime('%m-%d-%Y %H:%M:%S')})) del d else: request.append(uu({dbParam[0]: dbParam[1]})) request.append(action) result = self._doRequest(request) #if action == '-view': # result = FMProLayout.FMProLayout( result ) #else: try: result = FMResultset.FMResultset(result) except FMFieldError as value: # Is that clear? realfields = FMServer('%s://%s:%s@%s:%s%s' % ( self._protocol, self._login, self._password, self._host, self._port, self._address), self._db, self._layout).doView() #print realfields # How to get fields? l = [] for k, v in self._dbParams: if k[-3:] != '.op' and k[0] != '-': l.append(("'%s'" % k.replace('::', '.')).encode('utf-8')) raise FMError("Field(s) %s not found on layout '%s'" % (', '.join(l), self._layout)) if action == '-view': result = result.fieldNames finally: self._dbParams = [] self._sortParams = [] self._skipRecords = 0 self._maxRecords = 0 self._lop = 'and' return result
def number(): url = ['https://blog.csdn.net/qq_41116956/article/details/84105041','https://blog.csdn.net/qq_41116956/article/details/80595285'\ ,'https://blog.csdn.net/qq_41116956/article/details/80581624','https://blog.csdn.net/qq_41116956/article/details/84105734'\ ,'https://blog.csdn.net/qq_41116956/article/details/82661381','https://blog.csdn.net/qq_41116956/article/details/82697164'\ ,'https://blog.csdn.net/qq_41116956/article/details/82767078','https://blog.csdn.net/qq_41116956/article/details/82704365'\ ,'https://blog.csdn.net/qq_41116956/article/details/82768479','https://blog.csdn.net/qq_41116956/article/details/82767418'\ #-------------------------------------------------------------------------------------------------------------------------------------- ,'https://blog.csdn.net/qq_41116956/article/details/82767604','https://blog.csdn.net/qq_41116956/article/details/82996319'\ ,'https://blog.csdn.net/qq_41116956/article/details/82767764','https://blog.csdn.net/qq_41116956/article/details/82768093'\ ,'https://blog.csdn.net/qq_41116956/article/details/82787400','https://blog.csdn.net/qq_41116956/article/details/83541818'\ ,'https://blog.csdn.net/qq_41116956/article/details/83272420','https://blog.csdn.net/qq_41116956/article/details/83272020'\ ,'https://blog.csdn.net/qq_41116956/article/details/84256151','https://blog.csdn.net/qq_41116956/article/details/83015312'\ #-------------------------------------------------------------------------------------------------------------------------------------- ,'https://blog.csdn.net/qq_41116956/article/details/82781270','https://blog.csdn.net/qq_41116956/article/details/82788775'\ ,'https://blog.csdn.net/qq_41116956/article/details/82862900','https://blog.csdn.net/qq_41116956/article/details/82851001'\ ,'https://blog.csdn.net/qq_41116956/article/details/84775177','https://blog.csdn.net/qq_41116956/article/details/84825963'\ ,'https://blog.csdn.net/qq_41116956/article/details/84838113'] count = 0 # 初始化计数器 page = [] #页面信息 # 组装GET方法的请求 request = [] for i in range(0, url.__len__()): request.append(urllib.request.Request(url[i])) while 1: # 一旦开刷就停不下来 count += 1 # 计数器加1 print('开始第%s循环' % count) # 打印当前循环次数 for i in range(0, url.__len__()): def num(): rec = urllib.request.urlopen(request[i]) # 发送GET请求,获取博客文章页面资源 sleep_time = random.randint(50, 60) print("正在执行页面:%s 页" % i) print('等待时间:%s s' % sleep_time) time.sleep(sleep_time) if ((count % 5 == 0 and i == 0) or (count % 5 == 0 and i == 1) or (count % 6 == 0 and i == 2) or (count % 6 == 0 and i == 3) or (count % 5 == 0 and i == 4)): num() if ((count % 4 == 0 and i == 5) or (count % 6 == 0 and i == 6) or (count % 6 == 0 and i == 7) or (count % 7 == 0 and i == 8) or (count % 3 == 0 and i == 9)): num() if ((count % 4 == 0 and i == 10) or (count % 5 == 0 and i == 11) or (count % 6 == 0 and i == 12) or (count % 5 == 0 and i == 13) or (count % 7 == 0 and i == 14)): num() if ((count % 6 == 0 and i == 15) or (count % 6 == 0 and i == 16) or (count % 8 == 0 and i == 17) or (count % 12 == 0 and i == 18) or (count % 10 == 0 and i == 19)): num() if ((count % 10 == 0 and i == 20) or (count % 9 == 0 and i == 21) or (count % 10 == 0 and i == 22) or (count % 6 == 0 and i == 23) or (count % 10 == 0 and i == 24)): num() if ((count % 12 == 0 and i == 25) or (count % 14 == 0 and i == 26)): num() sleep_time = random.randint(30, 60) print('第%s循环完成,等待时间' % count, sleep_time, 's') time.sleep(sleep_time)
def getTravelTimes(self, latitude, longitude, depth, locations=[], model='iasp91'): """ Returns travel times for specified station-event geometry using standard velocity models such as ``iasp91``, ``ak135`` or ``qdt``. :type latitude: float :param latitude: Event latitude. :type longitude: float :param longitude: Event longitude. :type depth: float :param depth: Event depth in km. :type locations: list of tuples :param locations: Each tuple contains a pair of (latitude, longitude) of a station. :type model: str, optional :param model: Velocity model, one of ``'iasp91'``, ``'ak135'``, or ``'qdt'``. Defaults to ``'iasp91'``. :return: List of dicts containing phase name and arrival times in ms. .. seealso:: http://www.orfeus-eu.org/wsdl/taup/taup.wsdl .. rubric:: Example >>> client = Client() >>> locations = [(48.0, 12.0), (48.1, 12.0)] >>> result = client.getTravelTimes(latitude=20.0, longitude=20.0, ... depth=10.0, locations=locations, ... model='iasp91') >>> len(result) 2 >>> result[0] # doctest: +SKIP {'P': 356981.13561726053, 'S': 646841.5619481194} """ # enable logging if debug option is set if self.debug: import logging logging.basicConfig(level=logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) # initialize client client = SudsClient(TAUP_WSDL) # set cache of 5 days cache = client.options.cache cache.setduration(days=5) # create request request = [] for location in locations: req = { 'event-depth': float(depth), 'event-lat': float(latitude), 'event-lon': float(longitude), 'model': str(model), 'point-lat': float(location[0]), 'point-lon': float(location[1]) } request.append(req) data = client.service.getArrivalTimes(request) result = [] for item in data: times = {} if hasattr(item, 'arrival-time'): for time in item['arrival-time']: times[str(time._phase)] = float(time['_time-ms']) result.append(times) return result