Created
May 29, 2019 11:32
-
-
Save hackerkid/f73294d76d4a7ecdccee4e856b37ca6e to your computer and use it in GitHub Desktop.
Script for replacing https://github.com/zulip/zulip-electron with https://github.com/zulip/zulip-desktop in Message.rendered_content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zerver.models import Message | |
| from bs4 import BeautifulSoup | |
| def replace_zulip_electron_links(): | |
| messages = Message.objects.filter(rendered_content__contains="https://github.com/zulip/zulip-electron") | |
| for message in messages: | |
| soup = BeautifulSoup(message.rendered_content, "html.parser") | |
| link_elements = soup.findAll("a") | |
| for link in link_elements: | |
| link["href"] = link["href"].replace("https://github.com/zulip/zulip-electron", "https://github.com/zulip/zulip-desktop") | |
| link["title"] = link["title"].replace("https://github.com/zulip/zulip-electron", "https://github.com/zulip/zulip-desktop") | |
| message.rendered_content = str(soup) | |
| message.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment