在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):philgyford/samuelpepys-twitter开源软件地址(OpenSource Url):https://github.com/philgyford/samuelpepys-twitter开源编程语言(OpenSource Language):Python 99.9%开源软件介绍(OpenSource Introduction):Samuel Pepys TwitterPython 3 script for posting Twitter tweets and/or Mastodon Toots at specific times. Used for the @samuelpepys Twitter account and @[email protected] Mastodon account. Uses Redis to store the time the script last ran. It can send only Twitter tweets, or only Mastodon toots, or send identical updates to both simultaneously. The instructions below mostly refer to "tweets" but consider tweets/toots interchangeable. It needs to be run automatically, ideally once per minute, e.g. via
See below for installation instructions, including for Heroku. Tweet filesThere are files of tweets in dated yearly directories and monthly files, eg,
You could set Tweets should be in time order, with most recent first. Each tweet should be on
a single line, preceded by its date and time, and an optional 'r' (to indicate
the tweet's "kind".
Any lines that aren't of that format will be ignored. So feel free to comment out any tweets to be ignored by prepending them with a different character, and leave blank lines to make reading easier. The script doesn't check for length of tweet, so any tweets longer than 280 characters will be submitted and rejected. What gets tweetedThe script looks through all the tweets and grabs any whose time (adjusted with
The last condition is to catch the following scenario: Something goes wrong with the server or script and it isn't run successfully for, say, 12 hours. The next time it's run it would instantly tweet all tweets set for the last 12 hours. Assuming we don't want this, set If you would want to tweet all the past 12 hours worth of tweets, set Any tweets that match those conditions will be tweeted a couple of seconds apart, in the order their datetimes are in. RepliesIf a line has an Note: Replies do not currently work across month boundaries. i.e. if the very
earliest tweet in a month's file is an TestingUse the included
ConfigurationConfiguration can either be set in a config file or in environment settings. If Whichever you use you should include the API settings for one or both of a Twitter app and Mastodon app. If you don't set the Twitter Consumer Key (or leave it empty), no tweets will be sent. If you don't set the Mastodon Client ID (or leave it empty), no toots will be sent. All other settings are optional. To use a config file, copy If using environment settings, they are listed below. If
See Wikipedia's list of TZ timezone strings for the Local setupUse pipenv to install required packages by doing:
Set up config values as above, either via a config file (probably best) or environment settings. Then just run the script:
That will send a tweet if there is one with an appropriate date and time. Heroku setupSet up a new Heroku app. Set Heroku environment variables for all the environment variables, eg:
Add a Redis database, eg:
Copy the Redis add-on's URL to the
Push all the code and tweets to your Heroku app:
There you go. I think that's it... The Running on Heroku with SchedulerPreviously we didn't use the clock process but ran this using the Scheduler. The downside is that it can only run up to once every 10 minutes. To do it that way, remove the Procfile and push the code to Heroku. Add the free Heroku Scheduler to your app:
Have it run |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论