Twitter通过模板发送文本。不知怎么的,它缩写为“twempest”。

twempest的Python项目详细描述


statusbuildstatuscodecovpypiversionpyversionslicence

twempest是一个用python编写的命令行程序。

动机

Twenpest出生时就需要定期回复我的twitter tweets 先是一个基于果冻的帖子,然后是鹈鹕建立的博客。就这样, 就这些。

许可证

版权所有2018戴夫罗杰斯。根据GNU General Public License, version 3授权。 请参阅所附的许可证文件或参阅http://www.gnu.org/licenses/ 详细情况。

更改日志

当前版本是0.2.12。特温普斯是 semver-ish的版本控制方案。

Twenpest目前是一个beta版本的候选者,正在为 版本1.0.0。

安装

自制(MacOS)

在MacOS上,Homebrew将负责安装任何依赖项, 包括python 3。

brew tap yukondude/tap
brew install twempest

pypi(posix)

在*nix上,首先需要使用 你喜欢的方法。

pip3 install twempest

Unicode区域设置配置

如果Unicode区域设置未在特定环境中配置 (例如,cron),您将看到以下错误:

RuntimeError: Click will abort further execution because Python 3
was configured to use ASCII as encoding for the environment.
Consult http://click.pocoo.org/python3/for mitigation steps.

To solve this你必须 在环境中显式导出Unicode区域设置。例如, 在^{tt2}顶部插入如下内容$ 文件:

LC_ALL=en_CA.UTF-8
LANG=en_CA.UTF-8

使用适合您的语言和地区的语言环境。错误 消息应显示可用区域设置的列表。

开发设置

  1. 确保安装了Python3.6或更高版本。
  2. 安装pipenv:pip install pipenv
  3. 克隆Twempest repo: git clone https://github.com/yukondude/Twempest.git ; cd Twempest
  4. 安装依赖项:pipenv install --dev--three
  5. 以开发模式安装项目: pipenv run ./setup.py develop
  6. 运行单元测试以确保所有内容都是一致的: pipenv run ./setup.py test
  7. 倒上一杯蒙蒂法德葡萄酒,点上一个落叶松贮藏室。 托罗。

在开发时,必须始终从 在pipenv虚拟环境中:pipenv run twempest

用法

运行twempest --help查看用法说明:

Usage: twempest [OPTIONS] TEMPLATE

  Download a sequence of recent Twitter tweets and convert these, via the
  given template file, to text format. Twempest uses the Jinja template
  syntax throughout: http://jinja.pocoo.org/docs/2.9/templates/

Options:
  -c, --config-path TEXT  Twempest configuration directory path, which must be
                          writable, and must also contain the twempest.conf
                          file.  [default: ~/.twempest]
  -A, --abbreviated       Render the abbreviated form of the tweet text rather
                          than the full, extended, version.
  -a, --append            Append rendered tweet(s) to existing file(s) rather
                          than skipping past with a warning.
  -n, --count TEXT        Maximum number of tweets to retrieve. The actual
                          number may be lower.  [default: 200]
  -D, --dry-run           Display all configuration options and template
                          contents without retrieving tweets.
  -i, --image-path TEXT   The directory path (template tags allowed) to write
                          downloaded image (media type == 'photo') files. The
                          directory path will be created if it doesn't exist.
                          Media file names use the --render-file name followed
                          by a number and the appropriate file extension. If
                          omitted, media files will not be downloaded.
  -u, --image-url TEXT    The URL path (template tags allowed) to use for all
                          image files downloaded via the --image-path option.
  --pickle                Serialize a list of the rendered tweet statuses as a
                          standard Python pickle byte stream. The stream will
                          be written to 'twempest.p' in the current working
                          directory.
  -q, --quiet             Suppress warning messages.
  -f, --render-file TEXT  The file name (template tags allowed) for the
                          rendered tweets. If omitted, tweets will be rendered
                          to STDOUT.
  -p, --render-path TEXT  The directory path (template tags allowed) to write
                          the rendered tweet files. The directory path will be
                          created if it doesn't exist.  [default: .]
  -@, --replies           Include @replies in the list of retrieved tweets.
  -r, --retweets          Include retweets in the list of retrieved tweets.
  -s, --since-id TEXT     Retrieve tweets that follow this ID in the timeline.
                          Required, unless the ID has already been recorded in
                          the config path directory after a previous run of
                          Twempest.
  -k, --skip TEXT         Skip any rendered tweets that contain this regular
                          expression pattern.
  -V, --version           Show version and exit.
  -h, --help              Show this message and exit.

示例配置

twempest.config.sample

的内容
# Sample Twempest configuration file. See https://github.com/yukondude/Twempest
# for details. Save this to ~/.twempest/twempest.config as the default
# configuration whenever twempest is run, or save it somewhere convenient as
# twempest.config and reference it via the -c/--config-path command-line switch.

[twempest]
# Most twempest long-form command-line switches may be used here (excluding the
# leading double-dash). The obvious exceptions would include --config-path,
# --help, and --version, but go ahead and try them if you like. The commented-
# out defaults are shown below. See the --help output for details.

# Render the full text of the tweet.
# abbreviated=false

# Do not append to existing files.
# append=false

# Retrieve at most 200 tweets.
# count=200

# Retrieve tweets normally.
# dry-run=false

# Do not download image files.
# image-path=

# Do not download image files.
# image-url=

# Do not serialize the rendered tweets.
# pickle=false

# Do not suppress warning messages.
# quiet=false

# Render tweets to STDOUT.
# render-file=
# Because template expressions are allowed for this option, you can generate
# rendered file names using any of the tweet context variable contents. For
# example: render-file={{tweet.created_at|isodate}}-{{tweet.text|slugify}}.md
# might render to something like: 2017-02-14-be-my-valentine.md
# Use the slugify filter to eliminate any non-filesystem-safe characters from
# the tweet text.

# Write rendered tweets to the current directory.
# render-path=.
# Template expressions are also allowed for this option, so the directory path
# can be made to change based upon a tweet status variable.

# Exclude @replies from the list of retrieved tweets.
# replies=false

# Exclude retweets from the list of retrieved tweets.
# retweets=false

# Don't specify a most recent Twitter ID.
# since-id=
# Since this isn't specified (and normally wouldn't be in a config file), there
# must already be an ID recorded in the config path directory after a previous
# run of Twempest.

# Don't skip any tweets.
# skip=

[twitter]
# Visit https://apps.twitter.com/ to generate these keys, secrets, tokens, and
# token secrets. Secret tokens? Token keys? Secret secrets?
consumer_key=
consumer_secret=
access_token=
access_token_secret=

样本模板

将tweet呈现为适合jekyll的标记文本的简单模板 帖子(twempest.template.sample):

---
title: '{{ tweet.text|delink|truncate(80,False)|qescape }}'
author: '{{ tweet.user.name|qescape }}'
date: '{{ tweet.created_at }}'
tweet_id: {{ tweet.id }}
---
{{ tweet.text | relink("[{{ text }}]({{ url }})") | reimage("![{{ alt }}]({{ url }})", "\n\n") }}

[tweet](https://twitter.com/{{tweet.user.screen_name}}/status/{{ tweet.id }})

此模板的呈现输出可能类似于 以下内容:

---
title: 'Ice fog 'boiling' up from the Yukon River.'
author: 'Dave Rogers'
date: '2016-12-06 12:12:36-08:00'
tweet_id: 806229878861201408
---
Ice fog 'boiling' up from the [#Yukon](https://twitter.com/hashtag/yukon) River.

![2016-12-06-ice-fog-boiling-up-from-the-yukon-river-0](/media/2016-12-06-ice-fog-boiling-up-from-the-yukon-river-0.jpg)

[tweet](https://twitter.com/yukondude/status/806229878861201408)

tweet上下文变量

请参阅Twitter API documentation for tweets以获取 可以在tweet上下文变量下找到的所有键 (字典)。

还提供了其他几把钥匙:

tweet.media[].original_media_url

^{tt16}列表中media_url键的原始值$ 在任何下载的图像url重写发生之前的项。

tweet.media[].original_media_url_https

列表中media_url_https键的原始值 media在任何下载的图像url重写发生之前。

模板过滤器

这些是除了built-in Jinja2 filters之外的。

isodate

将日期格式化为yyyy-mm-dd。

qescape

仅将单引号字符转义为HTML实体。

reimage(tag_format, delimiter=" ")

删除图像URL并将其附加到结尾(在分隔符之后)。 使用带有变量alturl的模板标记格式 格式化每个。


热门话题
java无法使用与Gradle发行版的连接运行生成操作https://services.gradle.org/distributions/gradle4.10.2bin.zip'   java显式定位窗格   java试图在安卓中退出。堆栈未正确清除   Java读取大文件Java堆空间   java如何处理未知的实体引用?   java如何在Spring框架中实现UDP   java在安卓中使用异常   java Android密钥库   java如何在opus文件中添加元数据?   swing无法在Java构建中添加自定义JButton。格拉德尔项目   java如何在MongoDB中按特定字段获取计数组?   基于java网络的屏幕录制器插件   java使用JDBC从Oracle获取唯一索引的所有外键   带有返回值的java simplify方法调用