Skip to main content

Utility to retrieve tweets and format them into LaTeX fragments.

Project description

This is proof of concept utility for retrieval of Tweets by their IDs and their conversion to LaTeX. This utility requires Python and twarc module.

Run this from command line, e.g., like this:

./tweet2latex.py 762602474293321728 |tee tweet.tex

The invocation above will download tweet's information as JSON and it will cache the JSON and downloaded images in current directory to avoid access rate limitations of Twitter API should this tool be invoked several times in succession.

The contents of the tweet.tex might looks something like this:

\begin{tweet}\tweetUserImage{https://pbs.twimg.com/profile\_images/887781725249585152/ihwPKKHi\_bigger.jpg}{ihwPKKHi-bigger.jpg}{701158958}\tweetUserName{701158958}{MedicNow}{MedicNow}\tweetUserEnd{}It could be worse. You could be the lifeguard at the \tweetHashtag{Rio}{\#Rio} swimming pool.... \tweetHashtag{MondayMotivation}{\#MondayMotivation} \tweetPhoto{https://twitter.com/MedicNow/status/762602474293321728/photo/1}{https://pbs.twimg.com/media/CpVOzW7WEAAhMte.jpg}{CpVOzW7WEAAhMte.jpg}{https://t.co/AfoOoV9qQw}\tweetRetweets{7}\tweetFavorites{12}\tweetItself{762602474293321728}{Mon Aug 08 10:52:52 +0000 2016}{August 8, 2016}{12:52:52 PM GMT+2}\end{tweet}

Then import the resulting tweet.tex in your LaTeX document:

\import{tweet}

Formatting of the tweet is up to you. See tweet-document.tex for example usage. The following shows simple formatting for tweets:

\newenvironment{tweet}{%
  \newcommand{\tweetUserImage}[3]{%
    \begingroup%
      \includegraphics[keepaspectratio,height=1em]{##2}%
      \quad
    \endgroup
  }%
  \newcommand{\tweetUserName}[3]{\href{https://twitter.com/intent/user?user_id=##1}{##2}\quad
    \href{https://twitter.com/intent/user?user_id=##1}{{\small
        \color{gray}@##3}}}%
  \newcommand{\tweetUserVerified}{\hskip 0.16667em\relax{\small
      \color{cyan}\textcircled{\(\checkmark\)}}}%
  \newcommand{\tweetUserEnd}{\\}%
  \newcommand{\tweetHashtag}[2]{\href{https://twitter.com/hashtag/##1}{##2}}%
  \newcommand{\tweetUserMention}[2]{\href{https://twitter.com/intent/user?user_id=##1}{##2}}%
  \newcommand{\tweetUrl}[4]{\href{##2}{##3}}%
  \newcommand{\tweetInReplyToTweet}[3]{{\small \color{gray}in reply to
      \href{https://twitter.com/statuses/##1}{tweet} by
      \href{https://twitter.com/intent/user?user_id=##2}{@##3}}\\}%
  \newcommand{\tweetPhoto}[4]{\\\includegraphics[keepaspectratio]{##3}\\}%
  \newcommand{\tweetRetweets}[1]{\flushright{\small \(\color{gray}\circlearrowright\)\color{gray}\hskip 0.16667em\relax##1}}%
  \newcommand{\tweetFavorites}[1]{ {\small \(\color{gray}\heartsuit\)\color{gray}\hskip 0.16667em\relax##1}}%
  \newcommand{\tweetItself}[4]{%
    \quad\href{https://twitter.com/statuses/##1}{{\small \color{gray}##3 ##4}}}%
  \newcommand{\tweetPlace}[3]{\flushright {\small \color{gray}\href{##3}{##1, ##2}}}%
  \newfontfamily\emojifont{Symbola}[Scale=MatchUppercase]%
  \begin{tcolorbox}[size=small,enhanced,breakable,autoparskip,halign=flush left]%
    \sffamily%
}{\end{tcolorbox}}

The tweet2latex.py utility also downloads user image and linked images and puts them in the working directory so that resulting document can use them.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tweet2latex-1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file tweet2latex-1.0-py3-none-any.whl.

File metadata

  • Download URL: tweet2latex-1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.0.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for tweet2latex-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f4cce7c572fa3debcedff0a37896baa0c1ca0a7dce952d109f2efee97329e4d
MD5 fef27470266f99801b0b56c573cd0a12
BLAKE2b-256 b9796d3c9e6561ba434b02a1445c33b6b35e89830b5566ce98d5cd4d5449b683

See more details on using hashes here.

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