Skip to main content

用于检索推文并将其格式化为 LaTeX 片段的实用程序。

项目描述

PyPi 项目:https ://pypi.org/project/tweet2latex/

这是通过 ID 检索推文并将其转换为 LaTeX 的概念验证实用程序。此实用程序需要 Python 和 twarc模块。

从命令行运行它,例如,像这样:

./tweet2latex.py 762602474293321728 |tee tweet.tex

上述调用会将推文的信息下载为 JSON 格式,并将 JSON 和下载的图像缓存在当前目录中,以避免连续多次调用此工具时 Twitter API 的访问速率限制。

可能的内容tweet.tex如下所示:

\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}

然后将结果导入tweet.tex您的 LaTeX 文档:

\import{tweet}

推文的格式取决于您。参见tweet-document.tex示例用法。下面显示了推文的简单格式:

\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}}

tweet2latex.py实用程序还下载用户图像和链接图像并将它们放在工作目录中,以便生成的文档可以使用它们。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

tweet2latex-1.2.tar.gz (7.5 kB 查看哈希

已上传 source

内置分布

tweet2latex-1.2-py3-none-any.whl (7.8 kB 查看哈希

已上传 py3