def create(self, ctx, color=discord.Color.red(), title='', description='', image=None, thumbnail=None, url=None, footer_text=None, footer_url=None, author_text=None): DEMARATUS = 'https://cdn.discordapp.com/attachments/769165401879478302/780802976205635634/vanguardskeindem1.png' if isinstance(ctx.message.channel, discord.abc.GuildChannel): color = ctx.message.author.color data = discord.Embed(color=color, title=title, url=url) if description is not None: if len(description) < 1500: data.description = description data.set_author(name=ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) if image is not None: validators.url(image) code = requests.get(image).status_code if code == 200: data.set_image(url=image) else: print('Image URL Failure, code {}'.format(code)) print('Attempted URL:\n{}'.format(image)) return data
def create(self, ctx, color=discord.Color.gold(), title='', description='', image=None, thumbnail=None, url=None, footer_text=None, footer_url=None, author_text=None): if isinstance(ctx.message.channel, discord.abc.GuildChannel): color = ctx.message.author.color data = discord.Embed(color=color, title=title, url=url) if description is not None: if len(description) < 1500: data.description = description data.set_author(name=ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) if image is not None: validators.url(image) code = requests.get(image).status_code if code == 200: data.set_image(url=image) else: print('Image URL Failure, code {}'.format(code)) print('Attempted URL:\n{}'.format(image)) if footer_text is None: footer_text = "Dadjokes"
def create(self, ctx, color=discord.Color.red(), title='', description='', image=None, thumbnail=None, url=None, footer_text=None, footer_url=None, author_text=None): '''Return a color styled embed with MDT footer, and optional title or description. user_id = user id string. If none provided, takes message author. color = manual override, otherwise takes gold for private channels, or author color for guild. title = String, sets title. description = String, sets description. image = String url. Validator checks for valid url. thumbnail = String url. Validator checks for valid url.''' CRYSTAL = 'https://vignette.wikia.nocookie.net/marvel-contestofchampions/images/f/fe/6-Star_Crystal.png/revision/latest?cb=20200605225602' PATREON = 'https://patreon.com/matrixdt' MDT_LOGO = 'https://cdn.discordapp.com/attachments/745608075670585344/767361113477611580/MatrixDevelopmentTeam.png' DEMARATUS = 'https://cdn.discordapp.com/attachments/758775890954944572/768452440785027132/demaratuscircle.png' if isinstance(ctx.message.channel, discord.abc.GuildChannel): color = ctx.message.author.color # if url is None: # url = PATREON data = discord.Embed(color=color, title=title, url=url) if description is not None: if len(description) < 1500: data.description = description data.set_author(name=ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) if image is not None: validators.url(image) code = requests.get(image).status_code if code == 200: data.set_image(url=image) else: print('Image URL Failure, code {}'.format(code)) print('Attempted URL:\n{}'.format(image)) # if thumbnail is None: # thumbnail = CRYSTAL # if thumbnail is not None: # validators.url(thumbnail) # code = requests.get(thumbnail).status_code # if code == 200: # data.set_thumbnail( # url=thumbnail) # else: # data.set_thumbnail(url=CRYSTAL) # print('Thumbnail URL Failure, code {}'.format(code)) # print('Attempted URL:\n{}'.format(thumbnail)) if footer_text is None: footer_text = "Demaratus | MCOC Commands" if footer_url is None: footer_url = DEMARATUS data.set_footer(text=footer_text, icon_url=footer_url) return data
def test_about(self): """Get project metadata""" self.assertIsInstance(__about__.__author__, str) self.assertIsInstance(__about__.__copyright__, str) self.assertIsInstance(__about__.__title__, str) self.assertTrue(semver.VersionInfo.isvalid(__about__.__version__)) validators.email(__about__.__email__) validators.url(__about__.__uri__)
def create(self, ctx, color=discord.Color.gold(), title='', description='', image=None, thumbnail=None, url=None, footer_text=None, footer_url=None, author_text=None): '''Return a color styled embed with CDT footer, and optional title or description. user_id = user id string. If none provided, takes message author. color = manual override, otherwise takes gold for private channels, or author color for server. title = String, sets title. description = String, sets description. image = String url. Validator checks for valid url. thumbnail = String url. Validator checks for valid url.''' COLLECTOR_ICON = 'https://raw.githubusercontent.com/CollectorDevTeam/assets/master/data/cdt_icon.png' PATREON = 'https://patreon.com/collectorbot' CDT_LOGO = 'https://raw.githubusercontent.com/CollectorDevTeam/assets/master/data/cdt_logo.png' if not ctx.message.channel.is_private: color = ctx.message.author.color if url is None: url = PATREON data = discord.Embed(color=color, title=title, url=url) if description is not None: if len(description) < 1500: data.description = description data.set_author(name=ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) if image is not None: validators.url(image) code = requests.get(image).status_code if code == 200: data.set_image(url=image) else: print('Image URL Failure, code {}'.format(code)) print('Attempted URL:\n{}'.format(image)) if thumbnail is None: thumbnail = CDT_LOGO if thumbnail is not None: validators.url(thumbnail) code = requests.get(thumbnail).status_code if code == 200: # data.set_thumbnail(url=thumbnail) data.set_thumbnail(url=thumbnail) else: data.set_thumbnail(url=CDT_LOGO) print('Thumbnail URL Failure, code {}'.format(code)) print('Attempted URL:\n{}'.format(thumbnail)) if footer_text is None: footer_text = "Collector | Contest of Champions | CollectorDevTeam" if footer_url is None: footer_url = CDT_LOGO data.set_footer(text=footer_text, icon_url=footer_url) return data
def isURL(url): if url == "": return False logging.info("---------- Checking " + url + " ----------") try: validators.url(url) return True except InvalidURLError as e: print(e) logging.error(e) return False
def is_valid(self, url: str) -> bool: ret = False try: ret = True if validators.url(url) else False except (errors.EmptyValueError, errors.CannotCoerceError, errors.InvalidURLError) as err: raise err return ret
def user_input(): try: url = validators.url(input("Enter the URL: ")) except Exception as ex: print(ex) return products_services = input("Ener Products/services (seperate by ','): ") _similarity = float(input("Enter similarity ratio between 0 and 1: ")) return url, products_services, _similarity
def test_georezo_parser(self): """Test parser module.""" # instanciate georezo_parser = GeorezoRssParser( items_to_parse=200, user_agent="ElGeoPaso/{} https://elgeopaso.georezo.net/".format( __version__), ) # enforce different metadata file path to avoid conflicts between tests and real process georezo_parser.CRAWLER_LATEST_METADATA = "tests/fixtures/tmp/{}.json".format( get_test_marker()) # check validators.url(georezo_parser._build_feed_url()) # parse feed and retrive new offers li_new_offers_to_add = georezo_parser.parse_new_offers() self.assertIsInstance(li_new_offers_to_add, list)
def check_if_url(possible_url: str): """ checks if input `possible_url` is and valid url. Appends "https://" in front of it beforehand. (maybe not necessary). Args: possible_url `str`: The string to check. Returns: `bool`: `True` if it is and valid url. """ if not possible_url.startswith('http://') and not possible_url.startswith('https://'): possible_url = 'https://' + possible_url try: validators.url(possible_url) return True except validator_collection.errors.InvalidURLError: return False
def is_url_valid(test): is_valid = False try: # 2-21-2019 bml workaround for current bug in validator-collection v1.3.2 (reported as issue #28) # where http(s)://localhost:port-number.... is flagged as invalid if not (getattr(settings, "SITE_MODE", "prod") == "dev" and '://localhost:' in test): test = validators.url(test, allow_special_ips=True) if test: is_valid = True except InvalidURLError: pass return is_valid
def addNewAnime(self, url, episodeNumber=1, seasonNumber=1, alias=''): if not validators.url(url): raise ValueError() if ' ' in alias: errMsg = 'alias provided: {0} has whitespace in it, please remove the whitespace'.format( alias) raise UnboundLocalError() animeNameClean = self.cleanAnimeName(url.split("/")[-1]) self.addUrl(animeNameClean, url) self.anime_ep[animeNameClean] = episodeNumber self.anime_season[animeNameClean] = seasonNumber self.addAlias(animeNameClean, alias)
def is_url(value, **kwargs): """Indicate whether ``value`` is a URL. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` """ try: value = validators.url(value, **kwargs) except Exception: return False return True
def geturl(stringsubmitted): headers = {'User-Agent': 'Mozilla/5.0'} splits = stringsubmitted.split() value = '' urltitle = '' urldescription = '' urlimage = '' for f in splits: try: if len(f) > 5: if f.endswith(('.jpg', '.png', '.gif', '.png', '.jpeg', '.JPG', '.webp')): pass else: if not f.lower().startswith(("http://", "https://")): f = 'https://' + f value = validators.url(f) mainurl = (checkers.is_url(value)) if mainurl is True: urltitle, urldescription, urlimage = web_preview( value, headers=headers) break else: value = '' urltitle = '' urldescription = '' urlimage = '' except: pass if value is None: value = '' if urltitle is None: urltitle = '' if urldescription is None: urldescription = '' if urlimage is None: urlimage = '' return value, urltitle, urldescription, urlimage
def is_url(value, **kwargs): """Indicate whether ``value`` is a URL. .. note:: URL validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 1738 <https://tools.ietf.org/html/rfc1738>`_, `RFC 6761 <https://tools.ietf.org/html/rfc6761>`_, `RFC 2181 <https://tools.ietf.org/html/rfc2181>`_ and uses a combination of string parsing and regular expressions, This approach ensures more complete coverage for unusual edge cases, while still letting us use regular expressions that perform quickly. :param value: The value to evaluate. :param allow_special_ips: If ``True``, will succeed when validating special IP addresses, such as loopback IPs like ``127.0.0.1`` or ``0.0.0.0``. If ``False``, will fail if ``value`` is a special IP address. Defaults to ``False``. :type allow_special_ips: :class:`bool <python:bool>` :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates keyword parameters passed to the underlying validator """ try: value = validators.url(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
def more_info_icon(self, value): self._more_info_icon = validators.url(value, allow_empty=True)
def is_url(url): if checkers.is_url(url): result = validators.url(url) return result else: return False
def proxy(self, value): self._proxy = validators.url(value, allow_empty=True) self.http_client.proxy = self._proxy
def property_page_link(self, value): self._property_page_link = validators.url(value, allow_empty=True)
def request(self, method, url, parameters=None, headers=None, request_body=None): """Execute a standard HTTP request. :param method: The HTTP method to use for the request. Accepts `GET`, `HEAD`, `POST`, `PATCH`, `PUT`, or `DELETE`. :type method: :class:`str <python:str>` :param url: The URL to execute the request against. :type url: :class:`str <python:str>` :param parameters: URL parameters to submit with the request. Defaults to :obj:`None <python:None>`. :type parameters: :class:`dict <python:dict>` / :obj:`None <python:None>` :param headers: HTTP headers to submit with the request. Defaults to :obj:`None <python:None>`. :type headers: :class:`dict <python:dict>` / :obj:`None <python:None>` :param request_body: The data to supply in the body of the request. Defaults to :obj:`None <python:None>`. :type request_body: :obj:`None <python:None>` / :class:`dict <python:dict>` / :class:`str <python:str>` / :class:`bytes <python:bytes>` :returns: The content of the HTTP response, the status code of the HTTP response, and the headers of the HTTP response. :rtype: :class:`tuple <python:tuple>` of :class:`bytes <python:bytes>`, :class:`int <python:int>`, and :class:`dict <python:dict>` :raises ValueError: if ``method`` is not either ``GET``, ``HEAD``, ``POST``, ``PATCH``, ``PUT`` or ``DELETE`` :raises ValueError: if ``url`` is not a valid URL :raises ValueError: if ``headers`` is not empty and is not a :class:`dict <python:dict>` :raises HTTPTimeoutError: if the request times out :raises SSLError: if the request fails SSL certificate verification :raises WalkScoreError: *or sub-classes* for other errors returned by the API """ method = validators.string(method, allow_empty=False) method = method.upper() if method not in HTTP_METHODS: raise ValueError('method (%s) not a recognized HTTP method' % method) url = validators.url(url, allow_empty=False) parameters = validators.dict(parameters, allow_empty=True) headers = validators.dict(headers, allow_empty=True) content, status_code, headers = self._request(method, url, parameters, headers, request_body) check_for_errors(status_code, content) return content, status_code, headers
def url_or_none(data): try: return validators.url(data, allow_special_ips=True) except: return None
def logo_url(self, value): self._logo_url = validators.url(value, allow_empty=True)
def test_url_validator(self): self.assertEqual(validators.domain('lifo.ai'), 'lifo.ai') self.assertEqual(validators.domain('www.lifo.ai'), 'www.lifo.ai') self.assertEqual(validators.url('http://lifo.ai/login'), 'http://lifo.ai/login') print(checkers.is_domain('lifo.ai'))
def more_info_link(self, value): self._more_info_link = validators.url(value, allow_empty=True)
def help_link(self, value): self._help_link = validators.url(value, allow_empty=True)