@@ -44,7 +44,8 @@ def getUrlData(url):
4444
4545 titleEle = article .find ("h1" , class_ = "ue-c-article__headline" )
4646 if not titleEle :
47- print ("Missing elements - Skipping\n " )
47+ print ("❗ Missing elements - Skipping" )
48+ print (f"🔗 URL for checking: { url } \n " )
4849 return None
4950
5051 title = translator .translate (titleEle .get_text (strip = True ))
@@ -73,12 +74,7 @@ def getUrlData(url):
7374 subTitle = ("\n " + subTitle + "\n " ) if subTitle else ""
7475 desc = "\n " + desc + "\n " if desc else ""
7576
76- caption = (
77- f"<b>{ title } </b>\n "
78- f"{ subTitle } "
79- f"{ desc } "
80- f"\n \n { publishedAt } "
81- )
77+ caption = f"<b>{ title } </b>\n " f"{ subTitle } " f"{ desc } " f"\n \n { publishedAt } "
8278 return caption , authorName
8379 except Exception as e :
8480 print (f"Exception ERR: { e } " )
@@ -138,11 +134,16 @@ def getUrlData(url):
138134
139135 for url in urls :
140136 if url_exists (collection = realMadridArticlesCollection , url = url ):
141- print ("Url in database - Continue" )
137+ print ("☑️ Url in database - Continue" )
142138 continue
143- print ("Url not in database - Working" )
144- caption , authorName = getUrlData (url )
145- if not caption :
139+ print ("\n ⌛ Url not in database - Working" )
140+ data = getUrlData (url )
141+ if not data :
142+ print ("❗ No data avaliable - Skipping" )
143+ print (f"🔗 URL for checking: { url } \n " )
144+ continue
145+ caption , authorName = data
146+ if not all ([caption , authorName ]):
146147 continue
147148 imageUrl = articlesImages .get (url )
148149 imageUrl = re .sub (r"(?<!:)//" , "/" , imageUrl )
@@ -153,28 +154,27 @@ def getUrlData(url):
153154 photo = BytesIO (imageResponse .content )
154155 # Send to telegram:
155156 print ("Send message to telegram - Sending..." )
156- isSuccessSend = asyncio .run (
157+ status = asyncio .run (
157158 send_photo_message (
158159 token = TELEGRAM_TOKEN_REAL_MADRID ,
159160 chat_id = TELEGRAM_CHAT_ID ,
160161 caption = caption ,
161162 photo_url = photo ,
162163 source_url = url ,
163- buttonText = f"{ authorName } عبر صحيفة ماركا"
164+ buttonText = f"{ authorName } عبر صحيفة ماركا" ,
164165 )
165166 )
166- if not isSuccessSend :
167- print ("Message not send to telegram - Skipping\n " )
168- continue
169- print ("Message sended to telegram successfully" )
170167
171- # Save to database:
172- print ("Save url to database - Saving..." )
173- save_to_database (
174- collection = realMadridArticlesCollection ,
175- data = {"article_url" : url , "source" : SOURCE_NAME },
176- )
177- print ("Url saved to database successfully" )
168+ if status == True or status == "TIMEOUT" :
169+ # Save to database:
170+ print ("Save url to database - Saving..." )
171+ save_to_database (
172+ collection = realMadridArticlesCollection ,
173+ data = {"article_url" : url , "source" : SOURCE_NAME },
174+ )
175+ print ("✅ Url saved to database successfully\n " )
176+ else :
177+ print ("Message failed strictly. Not saving to DB - Skipping\n " )
178178 print ("✅ All Done - Exiting" )
179179 except Exception as e :
180180 print (e )
0 commit comments