轻松安排Twitter更新

coo的Python项目详细描述


https://badge.fury.io/py/coo.svghttps://travis-ci.org/wilfredinni/coo.svg?branch=masterhttps://codecov.io/gh/wilfredinni/coo/branch/master/graph/badge.svghttps://readthedocs.org/projects/coo/badge/?version=latesthttps://img.shields.io/badge/License-Apache%202.0-blue.svg

coo是一个易于使用的python库,用于安排twitter更新。要使用它,你需要 首先在 Twitter Developers Platform并生成密钥和 访问令牌。

pipinstallcoo

初始化

fromcooimportCooat=Coo("consumer_key","consumer_secret","access_token","access_token_secret",preview=False,)

或者,您可以设置preview=True并在终端中打印您的tweets 在推特上发布。

安排Twitter更新:

fromcooimportCooat=Coo("consumer_key","consumer_secret","access_token","access_token_secret")tweets=[("2030-12-05 16:30",template,"Awesome Twitter update."),("2030-10-28 18:50",template,"Another awesome Twitter update."),("2030-10-29 18:15",template2,"One more update."),("2030-11-01 13:45",None,"Twitter update without a template."),at.schedule(tweets,time_zone="America/Santiago")

或者可以使用字符串列表并添加delayintervaltemplate

tweets=["My first awesome Twitter Update","My second awesome Twitter Update","My third awesome Twitter Update","My fourth awesome Twitter Update","My fifth awesome Twitter Update","My sixth awesome Twitter Update",]at.tweet(tweets,delay="13:45",interval="four_hours",template=my_template)

安排Twitter更新

使用datetime字符串或整数安排更新,并在需要时使用自定义aTemplate

Coo.schedule(updates,time_zone)

完整示例:

fromcooimportCooat=Coo("consumer_key","consumer_secret","access_token","access_token_secret")tweets=[# datetime with and without templates("2030-10-28 18:50",template,"My Twitter update with a template."),("2030-10-29 18:15",template2,"Update with a different template."),("2030-11-01 13:45",None,"Twitter update without a template."),# date with and without templates("2030-12-25",template3,"Merry christmas!"),("2031-01-01",None,"And a happy new year!"),# time with and without templates("18:46",template2,"Will be post today at 18:46."),("23:00",None,"A tweet for today at 23:00."),# integer (seconds) with and without templates(3600,template,"This tweet will be posted in an hour."),(86400,None,"This one, tomorrow at the same hour."),]at.schedule(tweets,time_zone="America/Santiago")

分析日期时间字符串

  • 如果未指定时区,则将其设置为local
  • 如果未指定,时间将设置为00:00:00。
  • 当只传递时间信息时,日期将默认为今天。
  • 需要将来的日期,否则将引发ScheduleError

在这里你可以找到所有 Time Zones

媒体文件

有两种方法可以将媒体文件添加到您的tweets中。第一个也是最简单的方法是对所有更新使用一个全局文件:

at.schedule(tweets,time_zone="America/Santiago",media="path/to/file.png")

此外,还可以为每个更新设置一个单独的文件:

tweets=[("2030-10-28 18:50",template,"Update with an image.","pics/owl.png"),("2030-10-29 18:15",template,"Update with other media.","videos/funny_video.mp4"),("2030-11-01 13:45",template,"Tweet without media."),]

最后,可以将这些方法结合起来。例如,如果大多数tweets将使用相同的媒体,而只有少数tweets将使用不同的媒体或没有媒体:

tweets=[("2030-11-01 13:45",template,"Tweet with global media."),("2030-11-02 13:45",template,"Tweet with global media."),("2030-11-03 13:45",template,"Tweet with global media."),("2030-11-04 13:45",template,"Tweet with global media."),("2030-11-05 13:45",template,"Tweet with global media."),("2030-11-06 13:45",template,"Tweet with global media."),("2030-11-07 13:45",template,"Tweet with global media."),("2030-11-08 13:45",template,"Tweet without media.",None),("2030-11-09 13:45",template,"Tweet without media.",None),("2030-12-10 18:50",template,"Update with an image.","pics/owl.png"),("2030-12-11 18:15",template,"Update with other media.","videos/funny_video.mp4"),]at.schedule(tweets,time_zone="America/Santiago",media="path/to/global_media.png")

按顺序发送字符串列表

如果需要,可以使用DelayIntervalTemplate发布顺序更新。

Coo.tweet(updates,delay,interval,template,time_zone)
fromcooimportCooat=Coo("consumer_key","consumer_secret","access_token","access_token_secret")tweets=["My first awesome Twitter Update","My second awesome Twitter Update","My third awesome Twitter Update","My fourth awesome Twitter Update","My fifth awesome Twitter Update","My sixth awesome Twitter Update",]# post the twitter updatesat.tweet(tweets)

延迟

您可以使用datetimedatetime字符串,将整数用作秒和一些 Keywordshalf_hourone_hourone_dayone_week之间 推迟发布第一次更新。

# datetime, date and time stringsat.tweet(tweets,delay="2030-11-24 13:45",time_zone="America/Santiago")at.tweet(tweets,delay="2030-11-24",time_zone="Australia/Sydney")at.tweet(tweets,delay="13:45",time_zone="America/New_York")# "keywords"at.tweet(tweets,delay="one_week")# integerat.tweet(tweets,delay=604800)

分析日期时间字符串时:

  • 如果未指定时区,则将其设置为local
  • 如果未指定,时间将设置为00:00:00。
  • 当只传递时间信息时,日期将默认为今天。
  • 需要将来的日期,否则将引发ScheduleError

在这里你可以找到所有的Time Zones

间隔

将整数用作秒或某些字符串用作Keywordshalf_hourone_hourone_dayone_week之间。

# "keywords"at.tweet(tweets,interval="four_hours")# integersat.tweet(tweets,interval=14400)

媒体文件

所有更新使用一个媒体文件:

at.tweet(tweets,media="path/to/media.jpeg")

随机更新

随机发送更新:

at.tweet(tweets,aleatory=True)

关键词

KeywordSeconds
now0
half_hour1800
one_hour3600
two_hours7200
four_hours14400
six_hours21600
eight_hours28800
ten_hours36000
twelve_hours43200
fourteen_hours50400
sixteen_hours57600
eighteen_hours64800
twenty_hours72000
twenty_two_hours79200
one_day86400
two_days172800
three_days259200
four_days345600
five_days432000
six_days518400
one_week604800

模板

模板非常简单,只需使用多行字符串并添加$message 您希望邮件出现的位置。

template="""My awesome header

$message

#python #coding #coo
"""

twitter api

coo是使用Python Twitter编写的 包装器,通过Coo.api您可以访问他的所有模型:

# get your followersfollowers=at.api.GetFollowers()# get your direct messagesd_messages=at.api.GetDirectMessages()# favorited tweetsfavorites=at.api.GetFavorites()# mentionsmentions=at.api.GetMentions()# retweetsretweets=at.api.GetRetweets()

还有更多。如果您感兴趣,请查看他们的documentation

文档

文档可在readthedocs.org找到。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在ArrayList中比较数字   java在Kotlin中使异步调用同步   让“Scala编程”junit示例在IntelliJ中工作的java问题   java Servlet侦听器未在ContextListener中设置属性   将Microsoft SQL Server数据库连接到我的Java项目   加载资源时出现java“需要注册工厂”异常   java如何使用POI检查excel中的重复记录?   java如何更改机器生成的代码   java如何确保重写的方法是同步的   用Spring编写Hibernate时的java XML奥秘   java管理mysql数据库中存储的用户权限   java如何运行。来自Javascript的jar方法   java我想在Web应用程序中进行身份验证&对桌面应用程序使用相同的凭据。我该怎么做?