12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #!/usr/bin/env python3
- import datetime
- import crontab
- def answer_next_showoffhour_delta(mastodon, context, toot):
- soh1_start = crontab.CronTab( "0 0 * * wed" )
- soh2_start = crontab.CronTab( "0 12 * * wed" )
- soh3_start = crontab.CronTab( "0 18 * * sat" )
- soh4_start = crontab.CronTab( "0 6 * * sun" )
- soh1_end = crontab.CronTab( "0 1 * * wed" )
- soh2_end = crontab.CronTab( "0 13 * * wed" )
- soh3_end = crontab.CronTab( "0 19 * * sat" )
- soh4_end = crontab.CronTab( "0 7 * * sun" )
- next_soh_in_seconds = int( min( soh1_start.next(default_utc=True),
- soh2_start.next(default_utc=True),
- soh3_start.next(default_utc=True),
- soh4_start.next(default_utc=True) ) )
-
- next_soh_end_in_seconds = int( min( soh1_end.next(default_utc=True),
- soh2_end.next(default_utc=True),
- soh3_end.next(default_utc=True),
- soh4_end.next(default_utc=True) ) )
-
- seconds = next_soh_in_seconds
- days = seconds // (3600*24)
- seconds = seconds % (3600*24)
- hours = seconds // 3600
- seconds = seconds % 3600
- minutes = seconds // 60
- seconds = seconds % 60
- now = datetime.datetime.now()
- tomorrow = datetime.datetime.combine ( datetime.date.today() \
- + datetime.timedelta(days=1),
- datetime.datetime.min.time() )
- seconds_to_tomorrow = (tomorrow - now).total_seconds()
- status = "@{} ".format(context["author"])
- status += "The next #showoffhour is "
- if next_soh_end_in_seconds < 60:
- status += "right now! Show the world your hard work!"
- else:
- if days == 1:
- if seconds_to_tomorrow > next_soh_end_in_seconds - (24*3600):
- status += "tomorrow! Be sure to join in. :)"
- else:
- status += "the day after tomorrow! Come back later!"
- elif days == 2:
- if seconds_to_tomorrow > next_soh_end_in_seconds - (48*3600):
- status += "the day after tomorrow! Come back later!"
- else:
- status += "in three days! You still have time to get ready"
- elif days != 0:
- status += "in more than {} days! You still have time. :)" \
- .format(days)
- else:
- if seconds_to_tomorrow < (hours*3600) + (minutes*60):
- status += "tomorrow! Be sure to join in. :)"
- elif 3 < hours:
- status += "in about {} hours. Time to prepare your gifs." \
- .format(hours)
- elif 0 < hours < 3:
- status += "in about {} hours! Stay logged in!" \
- .format(hours)
- else:
- if 15 < minutes:
- status += "in {} minutes! It's almost there!" \
- .format(minutes)
- elif 0 < minutes:
- status += "in {} minutes! So close!" \
- .format(minutes)
- else:
- status += "starting now! Show the world your hard work!"
- mastodon.status_post( status = status, in_reply_to_id = toot["id"] )
- return
|