Git Product home page Git Product logo

xpost-update's Introduction

xpost-update

Create a post on x.com (Twitter) and update this post by deleting the old one and create a updated one.

Usage

Create new post and update this post again

Create new post:

docker run -e SECRETS_FILE=secrets.json --volume ./secrets.json:/secrets.json --volume ./data:/data xpost-update "this is a post"

Update this post again:

docker run -e SECRETS_FILE=secrets.json --volume ./secrets.json:/secrets.json --volume ./data:/data xpost-update "this is a post edited"

secrets.json looks like:

{
  "consumer_key": "ABCDEFGHIJKLMNOPQRSTUVXYZ1234567890",
  "consumer_secret": "ABCDEFGHIJKLMNOPQRSTUVXYZ1234567890",
  "access_token": "ABCDEFGHIJKLMNOPQRSTUVXYZ1234567890",
  "access_token_secret": "ABCDEFGHIJKLMNOPQRSTUVXYZ1234567890"
}

Update existing post with known POST ID again

If you start xpost-update for the first time and want to update an existing post set the POST_ID as environment variable:

docker run -e POST_ID=123123123123 -e SECRETS_FILE=secrets.json --volume ./secrets.json:/secrets.json --volume ./data:/data xpost-update "this is a post edited again"

If xpost-update has a persistent volume on /data, it will save the new post id in /data/lastpost_id. When you start xpost-update again, it will use this saved post id instead of the POST_ID given.

Pass all needed parameters as environment variables

You can also pass all needed paramets as environments variables:

docker run -e POST_TEST="this is a post" -e CONSUMER_KEY=123 -e CONSUMER_SECRET=123 -e ACCESS_TOKEN=123 -e ACCESS_TOKEN_SECRET=123 --volume ./data:/data xpost-update

We will use this in the next use case below.

Use docker swarm, docker secrets and swarm-cronjob to start container regularly

Add docker secret with the content of secrets.json (see structure of secrets.json in the first usage example):

docker secret create xpost-update-secrets secrets.json

Add swarm-cronjob as new service:

version: "3.8"
services:
  swarm-cronjob:
    image: crazymax/swarm-cronjob
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      - "TZ=Europe/Berlin"
      - "LOG_LEVEL=info"
      - "LOG_JSON=false"
    deploy:
      placement:
        constraints:
          - node.role == manager

Add new stack for xpost-update:

version: "3.8"

services:
  xpost-update:
    image: bkendinibilir/xpost-update
    deploy:
      mode: replicated
      replicas: 0
      labels:
        - "swarm.cronjob.enable=true"
        - "swarm.cronjob.schedule=${CRON_SCHEDULE}"
        - "swarm.cronjob.skip-running=false"
      restart_policy:
        condition: none
    environment:
      - SECRETS_FILE=/run/secrets/xpost-update-secrets
      - POST_TEXT=${POST_TEXT}
    volumes:
      - xpost-update_data:/data
    secrets:
      - xpost-update-secrets

volumes:
  xpost-update_data:

secrets:
  xpost-update-secrets:
    external: true

Replace ${CRON_SCHEDULE} with "0 15 * * *" to start it daily at 3 pm and ${POST_TEXT} with your post text.

xpost-update's People

Watchers

Benjamin Kendinibilir 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.