Skip to content

Instantly share code, notes, and snippets.

@masaponto

masaponto/README.md

Last active Apr 25, 2016
Embed
What would you like to do?

systemdによる定期実行

$HOME/.config/systemd/user/ofls-bot.serviceに以下を書く

[Unit]
Description=ofls-bot-service

[Service]
Type=simple
ExecStart=/home/s1200107/.pyenv/shims/python /home/s1200107/Dropbox/Works/ofls-bot/ofls_bot.py


[Install]
WantedBy=default.target

$HOME/.config/systemd/user/ofls-bot-everyday.timerに以下を書く

[Unit]
Description=ofls bot every day, How annoying!

[Timer]
OnCalendar=*-*-* 00:00:00
Unit=ofls-bot.service

[Install]
WantedBy=timers.target

で、

$ systemctl --user start ofls-bot.service

ユニット起動

$  systemctl --user start ofls-bot-everyday.timer  

起動時実行

$  systemctl --user enable ofls-bot-everyday.timer  

環境変数を引き継ぐ簡単な方法

$  systemctl --user import-environment 

Reference

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import os
import sys
from ofls_shift import OFLS_SHIFT
from kamebot import Kamebot
kame = Kamebot(channel='#ofls', error_comment='エラーだお')
@kame.comment
def main():
shift = OFLS_SHIFT()
date = datetime.date.today().weekday()
SUNDAY = 6
if date == SUNDAY:
print("OFLSBotだよー。\n来週の" + shift.NAME + "君のシフトをお知らせするよ!")
print('```')
print(shift.get_your_week_shift(1))
print('```')
print("\n全体のシフトはこれ!")
print('```')
print(shift.week_shift(1))
print('```')
else:
print("OFLSBotだよー。\n今日のシフトをお知らせするよ!")
print('```')
print(shift.date_shift())
print('```')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.