0
1

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 3 years have passed since last update.

残人生のためのプログラミング 第-3回

Posted at

早速プログラムの紹介だ!!

今回紹介するのはこいつだ!!TaskNotify.py!!
前回からの変更点はtaskLoad関数の追加と,csv中のisRoutine列を使って期限日の自動更新機能の実装だ!!

datetimeやdateオブジェクトの更新にはtimedeltaオブジェクトを使う必要があるから覚えておいてくれよな!!

TaskNotify.py
import requests
import datetime
import pandas as pd

class Task:
	def __init__(self, name, date):
		self.name = name
		self.date = date
		self.sentence = "{}まで残り{}日\n".format(name, abs(self.date-today).days)


def loadTasks(path_csv):
	csv_tasks = pd.read_csv(path_csv)
	list_tasks =[]
	for row in csv_tasks.itertuples():
		date = datetime.datetime.strptime(row.deadline, '%Y年%m月%d日').date()
		if row.isRoutine and (date < today):
			date += datetime.timedelta(days=row.isRoutine)
		list_tasks.append(Task(row.name, date))
	return list_tasks


def createSend(tasks):
	sentences = "\n"
	for s in tasks:
		print(s.date)
		if s.date >= today:
			sentences += s.sentence
	return sentences


if __name__ == '__main__':
	today = datetime.date.today()

	list_tasks = loadTasks("tasks.csv")

	send_dict = {'message': createSend(list_tasks)}

	TOKEN = 'hoge'
	url = 'https://notify-api.line.me/api/notify'
	TOKEN_dict = {'Authorization': 'Bearer ' + TOKEN}

	requests.post(url, headers=TOKEN_dict, data=send_dict)
tasks.csv
name,deadline,isRoutine,priority
Qiitaの記事を投稿する,2021年6月3日,1,low
課題を提出する,2021年6月9日,,high
Toeicの試験,2021年6月20日,,high
コインランドリー,2021年6月3日,4,mid

TaskNotify_csv_isRoutine.png

次回 第-4回は!!

タスクの登録・削除部分を実装していきます.とりあえずはtkinterとかでGUIとして実装しようかなって感じです.

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?