Giter Club home page Giter Club logo

picfetch's Introduction

picfetch: Cross-publish statuses/pics from Mastodon

This is a Racket script that will poll a Mastodon account, find the latest status with a specified hashtag that also has an image attachment, and save the image and metadata locally. I use this for the Latest Weather page on my website. I can post a pic to Mastodon from my phone and it shows up on that page within a minute.

I recommend looking through fetch.rkt: the code is short and sweet.

You are free to use modify this code however you want, as long as you give credit.

Setup

Clone the repository.

Install dependencies: raco pkg install http-easy threading.

Rename options.example.ini to options.ini and fill in your own options.

You will need your Mastodon account ID and an API access token.

To get an API access token, go to your Mastodon instance and go to PreferencesDevelopment and click New Application. Give the app a name like “Pic Fetcher” and select only the Read scope. Mastodon will set you up with three gnarly-lookin values, the one you want is “Your access token”.

Cross-compiling and deploying to a Linux server

You could install Racket on the web server and use it to run this program. What I do instead is cross-compile to a Linux executable and package this in a distribution folder containing all the dependencies. This way I never have to manage a Racket installation on any machine but my own laptop.

On my M1 Mac, I cross-compile as follows. The first two commands are only needed once.

raco cross pkg install http-easy-lib threading-lib
raco cross --target x86_64-linux pkg install http-easy-lib threading-lib
raco cross --target x86_64-linux exe fetch.rkt
raco cross --target x86_64-linux dist picfetch-dist fetch

At this point I have a picfetch-dist folder which I can upload to my web server. After uploading, I dig around inside that folder for the options.ini file and ensure it uses the correct output paths (inside my public web folder).

Creating a system service on the web server

Do sudo vim /etc/systemd/system/picfetch.service and save the file with this content (editing the ExecStart path and User to match your environment):

[Unit]
Description=Monitor Mastodon for new mnwx pics
DefaultDependencies=no
After=network.target
StartLimitIntervalSec=0

[Service]
ExecStart=/home/me/picfetch-dist/bin/fetch
User=me
Type=simple
Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target

Now you can do sudo systemctl start picfetch and sudo systemctl enable picfetch to start the program in the background.

You can monitor the background service with, e.g., journalctl -u picfetch.service.

picfetch's People

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.