def formatted_product_link(product_name, page_url, datasheet_url):
    if is_url(page_url):
        page_url_html = "<a class=product href='{0}' target='_blank'>{1}</a>".format(
            page_url, product_name)
    else:
        page_url_html = "<span class=product>{0}</span>".format(product_name)

    if is_url(datasheet_url):
        ds_url_html = "<a class=ds_link href='{0}' target='_blank'>datasheet</a>".format(
            datasheet_url)
    else:
        ds_url_html = ""

    return page_url_html + ds_url_html
Exemple #2
0
async def get_music_url(url, ctx):
    searched_url = None
    try:
        for i in range(3):
            if not is_url(url):
                result = YoutubeSearch(
                    url, max_results=3).to_dict()[0]['url_suffix']
                print(result)
                searched_url = f"https://www.youtube.com{result}"
            final_url = searched_url if searched_url else url
            print(final_url)
            loop = asyncio.get_event_loop()
            try:
                data = await loop.run_in_executor(
                    None,
                    lambda: ytdl.extract_info(url=final_url, download=False))
                break
            except youtube_dl.utils.DownloadError:
                i += 1
        return {
            'url': data['url'],
            'video_url': final_url,
            'title': data['title'],
            'duration': data['duration'],
            'author': ctx.author.mention
        }
    except IndexError:
        emb = cup_embed(title="There is a problem :(",
                        description=f"Sorry, I can't find {url}.")
        await ctx.send(embed=emb, delete_after=5)
        if ctx.message:
            await asyncio.sleep(5)
            await ctx.message.delete()
 def validate(self) -> MakeRequest[Name, Outcome]:
     if self.method not in self.methods:
         raise ValueError(f'Invalid HTTP method: {self.method}')
     url_validation = is_url(self.url)
     if url_validation is not True:
         raise url_validation
     return self
Exemple #4
0
        def validate_input_uri():
            """Validate the input URI unless configured to skip this."""
            if opts.broker_input_allow_any:
                return

            if not is_url(inquiry.input_uri):
                raise InvalidInputError(
                    "Invalid input URI value given <%s>" % inquiry.input_uri, )
Exemple #5
0
    async def add_emote(self, ctx, link, *name):
        """Add an emote to the server"""
        guild = ctx.guild
        author = ctx.author

        if is_url(link):
            if not name:
                await ctx.send('What do you want to name the emote as',
                               delete_after=30)
                try:
                    msg = await self.bot.wait_for('message',
                                                  check=basic_check(
                                                      author=author,
                                                      channel=ctx.channel),
                                                  timeout=30)
                except asyncio.TimeoutError:
                    msg = None
                if not msg:
                    return await ctx.send('Took too long.')
            data = await self._dl(ctx, link)
            name = ' '.join(name)

        else:
            if not ctx.message.attachments:
                return await ctx.send('No image provided')

            data = await self._dl(ctx, ctx.message.attachments[0].url)
            name = link + ' '.join(name)

        if not data:
            return

        data, mime = data
        if 'gif' in mime:
            fmt = 'data:{mime};base64,{data}'
            b64 = base64.b64encode(data.getvalue()).decode('ascii')
            img = fmt.format(mime=mime, data=b64)
            already_b64 = True
        else:
            img = data.getvalue()
            already_b64 = False

        try:
            await create_custom_emoji(guild=guild,
                                      name=name,
                                      image=img,
                                      already_b64=already_b64,
                                      reason=f'{ctx.author} created emote')
        except discord.HTTPException as e:
            await ctx.send(
                'Failed to create emote because of an error\n%s\nDId you check if the image is under 256kb in size'
                % e)
        except:
            await ctx.send('Failed to create emote because of an error')
            logger.exception('Failed to create emote')
        else:
            await ctx.send('created emote %s' % name)
Exemple #6
0
def table_to_tree(
    df,
    tree_level_names,
    parent_node,
    last_level_annotations,
    pop_up_notes,
    last_level_url_col_name=None,
):

    if df.empty:
        return

    conditions = variations(df, tree_level_names[0])
    for c in conditions:
        if pd.isna(c):
            continue

        filtered_df = take_only(df, tree_level_names[0], c)

        if len(tree_level_names) > 1:
            new_node = parent_node.new_node(c, parent_node)
            table_to_tree(filtered_df,
                          tree_level_names[1:],
                          new_node,
                          last_level_annotations,
                          pop_up_notes,
                          last_level_url_col_name=last_level_url_col_name)
        else:
            ann_list = annotations_with_title(filtered_df,
                                              last_level_annotations)
            new_node = parent_node.new_node(
                "{0}\n{1}".format(c, format_multiline_annot(ann_list)),
                parent_node)

            pop_up_notes_list = annotations_with_title(filtered_df,
                                                       pop_up_notes)
            new_node.set_note(format_multiline_annot(pop_up_notes_list))

            if last_level_url_col_name:
                url = get_single_col_value(filtered_df,
                                           last_level_url_col_name)
                if is_url(url):
                    new_node.set_url(url)

    return