Skip to main content

Calculate the length that Twitter will consider a Tweet to be

Project description

Tweet counter

Calculate the size that Twitter will consider a tweet to be.

This is not as advanced as the official twitter-text libraries, but attempts to at least take into account the following:

  • Twitter will convert anything that looks like a URL (with a valid TLD) into a Twitter short link, and count it as taking up exactly 23 characters
  • Twitter counts emoji and any unicode character above U+2037 as each taking up 2 characters

Installation

pip3 install tweet-counter

Python usage

from tweet_counter import count_tweet

print(count_tweet("Otters 👪 otters 𝗼𝘁𝘁𝗲𝗿𝘀 otters otters.com/otters"))
# Output => 60

Command-line usage

$ count-tweet "Otters 👪 otters 𝗼𝘁𝘁𝗲𝗿𝘀 otters otters.com/otters"
60

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tweet-counter-0.1.0.tar.gz (2.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page