Skip to content

Commit 379ce44

Browse files
committed
feat: add verbose for fetchurl and enable feature
1 parent 95d4d6d commit 379ce44

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

mkdocs_link_embeds_plugin/fetchurl.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
12
import logging
23
import re
34
import urllib.request
45
import requests
6+
os.system("")
57

68
from mkdocs.plugins import BasePlugin
79
from bs4 import BeautifulSoup
@@ -11,6 +13,27 @@
1113
LOG.setLevel ( logging.DEBUG )
1214
LOG.addHandler ( logging.StreamHandler( ) )
1315

16+
# ------------------------------------------------------------------------------------------------------------------------------------------
17+
# Color ASCII
18+
# ------------------------------------------------------------------------------------------------------------------------------------------
19+
20+
class clr():
21+
BLACK = '\033[30m'
22+
RED = '\033[31m'
23+
GREEN = '\033[32m'
24+
YELLOW = '\033[33m'
25+
BLUE = '\033[34m'
26+
MAGENTA = '\033[35m'
27+
CYAN = '\033[36m'
28+
WHITE = '\033[37m'
29+
UNDERLINE = '\033[4m'
30+
RESET = '\033[0m'
31+
GREY = '\033[90m'
32+
33+
# ------------------------------------------------------------------------------------------------------------------------------------------
34+
# Fetch metadata from url
35+
# ------------------------------------------------------------------------------------------------------------------------------------------
36+
1437
class FetchURL:
1538

1639
# -----------------------------------------------------------------------------------------
@@ -30,7 +53,9 @@ def __init__( self, config={} ):
3053
# with valid metadata.
3154
# -----------------------------------------------------------------------------------------
3255

33-
def get_page( self, url ):
56+
def initialize( self, url ):
57+
if self.config.get( 'verbose' ):
58+
print(clr.MAGENTA + 'VERBOSE - ' + clr.WHITE + ' activate fetchurl->initialize()')
3459

3560
try:
3661
opener = urllib.request.build_opener( )
@@ -53,6 +78,9 @@ def get_page( self, url ):
5378
# -----------------------------------------------------------------------------------------
5479

5580
def get_title( self, soup, title ):
81+
if self.config.get( 'verbose' ):
82+
print(clr.MAGENTA + 'VERBOSE - ' + clr.WHITE + ' activate fetchurl->get_title()')
83+
5684
if soup.findAll( "meta", property="og:title" ):
5785
return soup.find( "meta", property="og:title")["content"]
5886
elif soup.findAll( 'title' ):
@@ -65,6 +93,9 @@ def get_title( self, soup, title ):
6593
# -----------------------------------------------------------------------------------------
6694

6795
def get_description( self, soup, desc, url ):
96+
if self.config.get( 'verbose' ):
97+
print(clr.MAGENTA + 'VERBOSE - ' + clr.WHITE + ' activate fetchurl->get_description()')
98+
6899
if soup.findAll( "meta", property="og:description" ):
69100
return soup.find( "meta", property="og:description")["content"]
70101
elif soup.findAll( 'meta', attrs={'name': 'description'} ):
@@ -77,6 +108,9 @@ def get_description( self, soup, desc, url ):
77108
# -----------------------------------------------------------------------------------------
78109

79110
def get_site_name( self, soup, name ):
111+
if self.config.get( 'verbose' ):
112+
print(clr.MAGENTA + 'VERBOSE - ' + clr.WHITE + ' activate fetchurl->get_site_name()')
113+
80114
if soup.findAll( "meta", property="og:site_name" ):
81115
return soup.find( "meta", property="og:site_name")["content"]
82116
elif soup.findAll( 'title' ):
@@ -89,6 +123,9 @@ def get_site_name( self, soup, name ):
89123
# -----------------------------------------------------------------------------------------
90124

91125
def get_image( self, soup, image ):
126+
if self.config.get( 'verbose' ):
127+
print(clr.MAGENTA + 'VERBOSE - ' + clr.WHITE + ' activate fetchurl->get_image()')
128+
92129
if soup.findAll( "meta", property="og:image" ):
93130
return soup.find( "meta", property="og:image")["content"]
94131
elif soup.findAll( "meta", property="twitter:image" ):
@@ -104,6 +141,8 @@ def get_image( self, soup, image ):
104141
# -----------------------------------------------------------------------------------------
105142

106143
def get_favicon( self, soup, url, favicon, input_favicon ):
144+
if self.config.get( 'verbose' ):
145+
print(clr.MAGENTA + 'VERBOSE - ' + clr.WHITE + ' activate fetchurl->get_favicon()')
107146

108147
if input_favicon:
109148
return input_favicon

0 commit comments

Comments
 (0)