Skip to content

Instantly share code, notes, and snippets.

@akirk
Created November 4, 2024 05:11
Show Gist options
  • Save akirk/8587326bd9830ea5fb09b38cbc63e60b to your computer and use it in GitHub Desktop.
Save akirk/8587326bd9830ea5fb09b38cbc63e60b to your computer and use it in GitHub Desktop.
Script to generate new rotations
<?php
echo 'Please paste previous lines:' . PHP_EOL;
$input = file_get_contents( 'php://stdin' );
echo PHP_EOL . '--------------------------------' . PHP_EOL;
$weeks = intval( $_SERVER['argv'][1] ?? 12 );
$lines = explode( PHP_EOL, trim( $input ) );
$ts = 0;
$i = 0;
$users = array();
foreach ( $lines as $line ) {
preg_match( '#(?:<li>)?([^:]+):\s+@([^\s<]+)(?:</li>)?#', $line, $m );
if ( empty( $m[2] ) ) {
continue;
}
if ( ! in_array( $m[2], $users ) ) {
$users[] = $m[2];
$i++;
} else {
$i = ( $i + 1 ) % count( $users );
}
$ts = max( strtotime( $m[1] ), $ts );
}
if ( ! $weeks ) {
$weeks = count( $lines );
}
$i = $i % count( $users );
for ( ; $weeks > 0; $weeks-- ) {
$ts += 86400*7;
$format = 'F j';
if ( date( 'Y', $ts ) !== date( 'Y' ) ) {
$format .= ', Y';
}
echo date( $format, $ts ) . ': @' . $users[$i] . PHP_EOL;
$i = ( $i + 1 ) % count( $users );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment