lol rip twitter api, thx musk
rest of this is just for archival purposes.
feast upon the magnificent beast.
Select and upload random images from a Google Drive folder to Twitter
$ npm install
$ npm run build
$ docker pull ghcr.io/x-t/serverless-gdrive-twitter:latest
$ docker run -t --rm --env-file prod.env ghcr.io/x-t/serverless-gdrive-twitter
GitHub Actions workflow included, just bring your own publishing profile.
You can use the Azure Functions CLI to test the function locally, or even deploy it manually. See here.
It's a one-shot image, this means you'll have to bring in your own cron timer, most likely provided by your own OS.
$ docker build -t 3horsepowerv8 .
$ docker run -t --rm --env-file prod.env 3horsepowerv8
This creates a basic image, if a smaller size is needed, docker-slim can be used.
$ brew install docker-slim
$ docker build -t 3horsepowerv8 .
$ docker-slim build --http-probe-off 3horsepowerv8
$ docker run -t --rm --env-file prod.env 3horsepowerv8.slim
Now you have a smaller image.
$ node dist/index.js
From https://github.com/terence410/ts-google-drive
- Create a Google Cloud Project
- Create Service Account
- Service account details > Choose any service account name > CREATE
- Grant this service account access to project > CONTINUE
- Grant users access to this service account > CREATE KEY
- Save the key file into your project
- Enable Drive API
- APIs and Services > Enable APIS AND SERVICES
- Search Google Drive API > Enable
- To access shared folder
- Open the JSON key file, you will find an email xxx@xxx.iam.gserviceaccount.com.
- Go to your Google Drive Folder and shared the edit permission to the email address.
- Add your authentication in code from JSON
{
[...]
"private_key": "",
"client_email": "",
[...]
}
These are the only two values you'll need.
From https://github.com/desmondmorris/node-twitter
You will need valid Twitter developer credentials in the form of a set of consumer and access tokens/keys. You can get these here. Do not forgot to adjust your permissions - most POST request require write permissions.
Sends you Discord or Slack notifications via a webhook. Looks something like this:
- Add a webhook to your channel
- Make an username, copy the
/api
or/services
link intoprod.env
like in the example.
To reduce the amount of listing done by Google Drive, Deta can be used as a cache, where it holds the latest full-resolution image as well as the full listing of your Google Drive folder.
Monitor the failures of your bot using Sentry.
This is the file that stores all the tokens, usernames and emails.
It can be replaced by just using the environment, such as the "Configuration" tab in Azure or -env in Docker.
For a list of all options and examples, see CONFIG.md
Sharp is used to scale images. Thus, won't run on WASM workers.
Video support isn't battle-tested, but should work.
This is controlled by your Azure Function, via a NCRONTAB syntax. Changes in TwitterTimer1/function.json:
"direction": "in",
- "schedule": "0 */5 * * * *"
+ "schedule": "0 0 */1 * * *"
Example: removed to run every 5 minutes, added to run every 1 hour.