posts/migrate-disqus-comments-to-utterances-github/ #29
Replies: 7 comments
-
Hey, thanks for the highly detailed post! I just switched my comments at https://blog.isquaredsoftware.com over to Utterances, and used 90% of your code to do the conversion work. Biggest difference was that the Also, I ran into a rate-limiting issue, so I had to update the script to check for dupe comments and slow down comment creation a bit: for i, post in enumerate(posts, 1):
name = post["author"]["name"]
user = post["author"].get("username")
mention = " @" + user if user and not user.startswith("disqus_") else ""
date = post["createdAt"]
message = post["message"]
issue = post["thread"]["issue"]
comments = post["thread"]["comments"]
body = f"*Original date: {date}*\n\n{message}"
# don't add original author when it's you
if user != USERNAME:
body = f"*Original author:* **{name}{mention}** \n{body}"
try:
for comment in comments:
if date in comment.body and name in comment.body:
raise Error("dupe found")
except:
print(f"Skipping comment {i}/{len(posts)}")
continue
print(f"Posting {i}/{len(posts)} to issue {issue.number} \r", end="")
issue.create_comment(body)
time.sleep(0.5) Thanks! Could have figured it out for myself if I'd spent enough time on it, but sure was nice to have an almost ready-made solution to paste in. |
Beta Was this translation helpful? Give feedback.
-
Great! Glad to hear my script helped you 😄 I just checked and you're right, I linked the wrong PyGitHub 😱 It should have been https://pypi.org/project/PyGithub/. I'll fix this in the post, thanks! I will also add a comment about rate limiting, and using a sleep to prevent it, thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hello @pawamoy Assume that your import script is based on From utterances:
Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
So by default Utterances uses Now my script is also using if issue.title == thread["link"].replace(BASE_URL, ""): We search for issue titles being the URL of the post minus the specified base URL, which results in what we can call the |
Beta Was this translation helpful? Give feedback.
-
Wonder if you can help. I have created "test" in posts that have comments and when run script ending with following error
Is that a thread will missing initiated issue by "test" or something else? |
Beta Was this translation helpful? Give feedback.
-
Yep, I sorted my own issue. Replaced this using Atom and import is in progress :) Thank you for your script. ps. when running this script on macOS I need to add additionally |
Beta Was this translation helpful? Give feedback.
-
Hey @idarek, glad you found the solution! Also, indeed, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Migrate Disqus comments to Utterances (in GitHub issues) with Python - pawamoy's website
Findings, thoughts, tutorials, work. Pieces of my mind!
https://pawamoy.github.io/posts/migrate-disqus-comments-to-utterances-github/
Beta Was this translation helpful? Give feedback.
All reactions