GithubHelp home page GithubHelp logo

x-t / serverless-gdrive-twitter Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 0.0 354 KB

Select and upload random images from a Google Drive folder to Twitter.

Home Page: https://twitter.com/PracticeLaps

License: MIT License

TypeScript 98.60% Dockerfile 1.40%
twitter twitter-api google-drive google-drive-api-v3 typescript azure azure-functions azure-function-app serverless nodejs docker

serverless-gdrive-twitter's Introduction

serverless-gdrive-twitter

lol rip twitter api, thx musk

rest of this is just for archival purposes.

feast upon the magnificent beast.

Codename: 3 horsepower v8

Gitpod ready-to-code

Select and upload random images from a Google Drive folder to Twitter

Building

$ npm install
$ npm run build

Running (from binary)

$ 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

Running (from source)

On Azure

GitHub Actions workflow included, just bring your own publishing profile.

On Azure (local)

You can use the Azure Functions CLI to test the function locally, or even deploy it manually. See here.

On Docker

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.

On your own machine

$ node dist/index.js

Set up

Google (required)

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
  • To access shared folder
    • Open the JSON key file, you will find an email [email protected].
    • 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.

Twitter (required)

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.

Discord/Slack (optional)

Sends you Discord or Slack notifications via a webhook. Looks something like this: discord webhook slack webhook

  • Add a webhook to your channel
  • Make an username, copy the /api or /services link into prod.env like in the example.

Deta (as cache) (optional)

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.

Sentry (optional)

Monitor the failures of your bot using Sentry.

prod.env

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

Architecture

architecture

Sharp is used to scale images. Thus, won't run on WASM workers.

Video support isn't battle-tested, but should work.

Different fire times (Azure)

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.

serverless-gdrive-twitter's People

Contributors

dependabot[bot] avatar snyk-bot avatar x-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.