[PYTHON] Countdown test dates and post automatically

Basic information / application information and information security specialist We will post a countdown to the test date on twitter. The difference between the date of execution and the test date in the order of priority of this spring> this fall> next spring is taken, and the number of remaining test days remaining for one day or more is posted. Count down the next exam if there are no leftovers. After the fall, it will be spring next year, so add +1 to year and take the date difference from the third Sunday in April next year. Variable names are appropriate because of a desperate flaw in their senses.

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
#Below is the one I made by myself and put the OAuth token separately, so please go through.
import kino


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

#Get a list of Sundays in April and October of this year and April of next year 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)]

#Get the difference between today and the test date when this code is executed 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 = "Until the Spring Applied Information Technology Engineer Examination" + str(xday1a.days) + "Only days left"elif xday2m.days > 0:    message = "Until the Applied Information Technology Engineer Examination in the fall" + str(xday2m.days) + "Only days left"else:    message = "Until the Spring Applied Information Technology Engineer Examination" + str(xday3o.days) + "Only days left"kino.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': message}))

2013/08/07 I think that there are many parts that should be reworked, but it is open to the public 2013/08/08 Saved 2 lines because the message was posted outside after preparing it in the if-else clause 2013/08/13 Delete the line where the difference is extracted only for days and no formatting is required

Recommended Posts

Countdown test dates and post automatically
Post test
Distribution and test
Python debug and test module
Hypothesis test and probability distribution