Add in forever loop and remove redundant def
This commit is contained in:
		@@ -40,32 +40,6 @@ import argparse
 | 
				
			|||||||
def join_lines_with_newline(lines):
 | 
					def join_lines_with_newline(lines):
 | 
				
			||||||
    return "\n".join(lines)
 | 
					    return "\n".join(lines)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def extract_changelog_top(Wiki_link):
 | 
					 | 
				
			||||||
    response = requests.get(Wiki_link)
 | 
					 | 
				
			||||||
    soup = BeautifulSoup(response.text, 'html.parser')
 | 
					 | 
				
			||||||
    changelog_td = soup.find('td', class_='changelog')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if changelog_td:
 | 
					 | 
				
			||||||
        changelog_text = changelog_td.get_text(strip=False)
 | 
					 | 
				
			||||||
        lines = changelog_text.split('\n')
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        result = []
 | 
					 | 
				
			||||||
        seen = set()
 | 
					 | 
				
			||||||
        for line in lines:
 | 
					 | 
				
			||||||
            stripped_line = line.strip()
 | 
					 | 
				
			||||||
            if not stripped_line:
 | 
					 | 
				
			||||||
                if result:  # Stop at the first blank line after content
 | 
					 | 
				
			||||||
                    break
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
            if stripped_line not in seen:
 | 
					 | 
				
			||||||
                seen.add(stripped_line)
 | 
					 | 
				
			||||||
                if not result or stripped_line.startswith('-'):
 | 
					 | 
				
			||||||
                    result.append(stripped_line)
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        return join_lines_with_newline(result)
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        return []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Wiki RSS feed URL
 | 
					# Wiki RSS feed URL
 | 
				
			||||||
Wiki_RSS_URL = "https://wiki.koozali.org/api.php?hidebots=1&urlversion=2&days=7&limit=50&action=feedrecentchanges&feedformat=rss"
 | 
					Wiki_RSS_URL = "https://wiki.koozali.org/api.php?hidebots=1&urlversion=2&days=7&limit=50&action=feedrecentchanges&feedformat=rss"
 | 
				
			||||||
# Updated Rocket.Chat webhook URL
 | 
					# Updated Rocket.Chat webhook URL
 | 
				
			||||||
@@ -159,46 +133,47 @@ def main(one_shot=False, empty_db=False):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	send_startup_message()  # Send startup message
 | 
						send_startup_message()  # Send startup message
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entries = fetch_Wiki_feed()
 | 
						while True
 | 
				
			||||||
 | 
							entries = fetch_Wiki_feed()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for entry in entries:
 | 
							for entry in entries:
 | 
				
			||||||
		json_data = json.dumps(entry, indent=2)
 | 
								json_data = json.dumps(entry, indent=2)
 | 
				
			||||||
		data = json.loads(json_data)
 | 
								data = json.loads(json_data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		title = data["title"]
 | 
								title = data["title"]
 | 
				
			||||||
		published_date = data["published"]
 | 
								published_date = data["published"]
 | 
				
			||||||
		author = data["author"]
 | 
								author = data["author"]
 | 
				
			||||||
		revision_link = data["link"]
 | 
								revision_link = data["link"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		formatted_string = (
 | 
								formatted_string = (
 | 
				
			||||||
			f"Title: {title}\n"
 | 
									f"Title: {title}\n"
 | 
				
			||||||
			f"Published Date: {published_date}\n"
 | 
									f"Published Date: {published_date}\n"
 | 
				
			||||||
			f"Author: {author}\n"
 | 
									f"Author: {author}\n"
 | 
				
			||||||
			f"Link to Comparison (old vs new): {revision_link}"
 | 
									f"Link to Comparison (old vs new): {revision_link}"
 | 
				
			||||||
		)
 | 
								)
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		match = re.search(r'(.*?title=.*?)(.*)', data["id"])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if match:
 | 
					 | 
				
			||||||
			wiki_link = match.group(1)+title  # Everything up to and including "title=<whatever>"
 | 
					 | 
				
			||||||
			wiki_id = match.group(2)     # Everything from (and including) <whatever> to the end
 | 
					 | 
				
			||||||
		else:
 | 
					 | 
				
			||||||
			wiki_id = "Unexpected link"
 | 
					 | 
				
			||||||
			wiki_link = "Unexpected link"
 | 
					 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		#logging.info(f"{wiki_link} {wiki_id} {title}")
 | 
								match = re.search(r'(.*?title=.*?)(.*)', data["id"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if not has_wiki_been_sent(wiki_id):  # Check if the wiki has been sent
 | 
								if match:
 | 
				
			||||||
			send_to_rocket_chat(title, wiki_link, wiki_id, formatted_string)
 | 
									wiki_link = match.group(1)+title  # Everything up to and including "title=<whatever>"
 | 
				
			||||||
			mark_wiki_as_sent(wiki_id)  # Mark the wiki ID as sent
 | 
									wiki_id = match.group(2)     # Everything from (and including) <whatever> to the end
 | 
				
			||||||
			
 | 
								else:
 | 
				
			||||||
			if one_shot:
 | 
									wiki_id = "Unexpected link"
 | 
				
			||||||
				logging.info("One-shot mode activated; exiting after sending one message.")
 | 
									wiki_link = "Unexpected link"
 | 
				
			||||||
				return  # Exit after sending the first message
 | 
									
 | 
				
			||||||
 | 
								#logging.info(f"{wiki_link} {wiki_id} {title}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if not one_shot:
 | 
								if not has_wiki_been_sent(wiki_id):  # Check if the wiki has been sent
 | 
				
			||||||
		# Wait for 1 minute before polling again
 | 
									send_to_rocket_chat(title, wiki_link, wiki_id, formatted_string)
 | 
				
			||||||
		time.sleep(60)
 | 
									mark_wiki_as_sent(wiki_id)  # Mark the wiki ID as sent
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if one_shot:
 | 
				
			||||||
 | 
										logging.info("One-shot mode activated; exiting after sending one message.")
 | 
				
			||||||
 | 
										return  # Exit after sending the first message
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if not one_shot:
 | 
				
			||||||
 | 
								# Wait for 1 minute before polling again
 | 
				
			||||||
 | 
								time.sleep(60)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    parser = argparse.ArgumentParser(description="Wiki to Rocket.Chat integration.")
 | 
					    parser = argparse.ArgumentParser(description="Wiki to Rocket.Chat integration.")
 | 
				
			||||||
@@ -207,4 +182,4 @@ if __name__ == "__main__":
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    main(one_shot=args.one_shot, empty_db=args.empty_db)
 | 
					    main(one_shot=args.one_shot, empty_db=args.empty_db)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user