bear / python-twitter

A Python wrapper around the Twitter API.
Apache License 2.0
3.41k stars 957 forks source link

How to remove preview from a tweet that contain a link ? #648

Open bitsydoge opened 4 years ago

bitsydoge commented 4 years ago

Hello

I have a bot that tweet commits from a github git with the commit message and a link to the commit. But there is the annoying preview and I can't find how to remove it. Any idea and way of doing it ?

Thank's

Bracciata commented 4 years ago

I have looked into this and it seems if you add HTTPS:// before the link it will not show in the tweet but it will also not create a body text! Let me know if this works for you.

For example: Google.com will create a preview but https://google.com will not.

bitsydoge commented 4 years ago

I had https in the link since the start :/ https://twitter.com/GodotCommits

Bracciata commented 4 years ago

Do you mind posting a snippet of the code?

Bracciata commented 4 years ago

Ahhh I see. So for Google.com it fixes it. For youtube.com there is never a preview and for Github it does not. I will continue to look into this.

bitsydoge commented 4 years ago

Yeah no prob here a "simplified" version

def format_commit_message(commits):
    return commits.message + " " if len(commits.message) < 200 else commits.message[0:200] + " ... "

api.PostUpdate(format_commit_message(commits) + repo.remotes.origin.url + "/commit/" + commits.hexsha)
# repo.remotes.origin.url = https://github.com/godotengine/godot

# if config.log:
## Log
print("------------------------------------")
print(format_commit_message(commits))
print("URL : " + repo.remotes.origin.url + "/commit/" + commits.hexsha)

# Example log output
# Add WebSocket debugger, use it for Javascript.
#
# URL : https://github.com/godotengine/godot/commit/3097c2da963fe355c81816a74824170b6dce697c