Skip to content

FactorialHR auto clock in for the whole month from the command line

Notifications You must be signed in to change notification settings

xmsanchez/factorialsucks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

factorialsucks

ALL CREDITS FOR THE ORIGINAL SCRIPT GO TO alejoar

Updates on this FORK

  • The app now allows setting environment variables for credentials (FACTORIAL_EMAIL, FACTORIAL_PASS)
  • Now is possible to define multiple clock-in and clock-out (--ci xxx --ci xxx ...)
  • It uses a different time for Fridays (with a really weird and dirty harcoded workaround)

Requirements for building

⚠️ You need to have go environment installed or use the official go docker image to be able to run and build the app.

On Ubuntu

If using docker, check that go is working with this command:

docker run --rm --name golang -v $(pwd):/app -w /app golang go version

...otherwise just install it through the package manager:

sudo apt install golang-go
go version

On MacOs

...come on. Just switch to a real OS.

Build & install

If you chose to use docker:

docker run --rm --name golang -v $(pwd):/app -w /app golang go build -o build/factorialsucks factorialsucks.go utils.go

Else, use this:

go build -o build/factorialsucks factorialsucks.go utils.go

Then move the binary to a more convenient path (if you were in docker, remember to exit the container):

sudo mv build/factorialsucks /usr/local/bin

Setup credentials

As an upgrade to the original code you can now use environment variables!

This allows to achieve full automation :-)

export FACTORIAL_EMAIL='xxxx@example.com'
export FACTORIAL_PASSWORD='xxxx'

If you don't provide the environment variables the script will still ask you to input the values manually just like before.

Show help

❯ factorialsucks -h

NAME:
   factorialsucks - FactorialHR auto clock in for the whole month from the command line

USAGE:
   factorialsucks [options]

GLOBAL OPTIONS:
   --email value, -e value        you factorial email address
   --year YYYY, -y YYYY           clock-in year YYYY (default: current year)
   --month MM, -m MM              clock-in month MM (default: current month)
   --clock-in HH:MM, --ci HH:MM   clock-in time HH:MM. You can define it multiple times.
   --clock-out HH:MM, --co HH:MM  clock-in time HH:MM. You can define it multiple times.
   --today, -t                    clock in for today only (default: false)
   --until-today, --ut            clock in only until today (default: false)
   --dry-run, --dr                do a dry run without actually clocking in (default: false)
   --reset-month, --rm            delete all shifts for the given month (default: false)
   --help, -h                     show help (default: false)

How to run

The following example will clock everyday from 09:00 to 14:00 except fridays that will clock 09:00 to 15:00. This is hardcoded in the code at the moment.. You still have to supply the clock-in and clock-out hours for the rest of the days.

factorialsucks --ci 09:00 --co 14:00

As an update to the original script, you can now set multiple clock-in and clock-out!

factorialsucks --ci 09:00 --co 14:00 --ci 15:00 --co 18:30

Note that providing a clock-in later than 15:00 in the command line, will make friday to clock a second row. This should be avoided, I'll might fix it in the future.

To clock only until today, just use the --ut argument:

factorialsucks --ci 09:00 --co 14:00 --ci 15:00 --co 18:30 --ut

If you wish to remove all entries for the current month, run:

factorialsucks --reset-month

Running in a cron

Edit your local crontab:

crontab -e

Add at the end:

00 19   * * *   root    echo "Starting..."; FACTORIAL_EMAIL='xxxx@example.com' FACTORIAL_PASSWORD='xxxx' factorialsucks --ci 09:00 --co 14:00 --ci 15:00 --co 18:30 --ut >> $HOME/factorial.txt; echo -e "\nFinished at: $(date)\n\n---" >> $HOME/factorial.txt;

Note that you should be able to load the environment variables from a file, for example bash_profile or bashrc

About

FactorialHR auto clock in for the whole month from the command line

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%