Skip to main content

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

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 details)

Uploaded Source

File details

Details for the file tweet-counter-0.1.0.tar.gz.

File metadata

  • Download URL: tweet-counter-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for tweet-counter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 69913254c01397b97f33eb058b887e991d2b2378cfeb3c0cd41d23c33d572221
MD5 15659d44581d8c37c4cc6b8d2a47d412
BLAKE2b-256 7997c7f93f13791aeeef1688a305f80c3bf8688c4690f587f715728eb144b27d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page