1+ import os
12import logging
23import re
34import urllib .request
45import requests
6+ os .system ("" )
57
68from mkdocs .plugins import BasePlugin
79from bs4 import BeautifulSoup
1113LOG .setLevel ( logging .DEBUG )
1214LOG .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+
1437class 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