2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

試験日をカウントダウンして自動投稿

Last updated at Posted at 2013-08-06

基本情報・応用情報と情報セキュリティスペシャリスト試験日までのカウントダウンをtwitterで投げます。
実行時点の日付と今春>今秋>来春の優先順位で試験日との差分をとり、1日以上残っている試験日の残日数を投稿。
残がなければ次の試験をカウント・ダウンするように。
秋期の後は来年の春になるのでyearに+1して来年の4月の第三日曜日と日付差分を取るように。
変数名が適当なのはセンスに絶望的な欠陥があるせいです。

count.py
from urllib import urlencode
# from oauth2 import Client, Consumer, Token
from datetime import date, timedelta
import datetime
import calendar
import time
from datetime import date
import re
# from oauth2 import Client, Consumer, Token
# 下は私が勝手に作ってOAuthトークンを別に置いているものですのでスルーして下さい。
import kino


today = date.today()now = datetime.datetime.now()year = now.year

# 今年の4月と10月、来年の4月の日曜日をリストで取得xday1 = [x[calendar.SUNDAY] for x in calendar.monthcalendar(year, 4)]xday2 = [x[calendar.SUNDAY] for x in calendar.monthcalendar(year, 10)]xday3 = [x[calendar.SUNDAY] for x in calendar.monthcalendar(year+1, 4)]

# このコードを実行時点の今日と試験日との差分を取得xday1a = (date(year, 4, int(xday1[2])) - date.today())xday2m = (date(year, 10, int(xday2[2])) - date.today())xday3o = (date(year+1, 4, int(xday1[2])) - date.today())

if xday1a.days > 0:    message = "春期の応用情報技術者試験まであと" + str(xday1a.days) + "日しか残ってない "elif xday2m.days > 0:    message = "秋期の応用情報技術者試験まであと" + str(xday2m.days) + "日しか残ってない "else:    message = "春期の応用情報技術者試験まであと" + str(xday3o.days) + "日しか残ってない"kino.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': message}))

2013/08/07
手直しした方がいい箇所だらけだと思いますが公開
2013/08/08
messageをif-else節で用意した後に外で投稿投げられたので2行節約
2013/08/13
差分がdaysだけ取り出して整形が必要なくなった行を削除

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?