-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidou.py
149 lines (114 loc) · 4.57 KB
/
idou.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import csv
import discord
import requests
import datetime
# 移動販売
IDOU_DIR_URL = "https://hyouhyan.github.io/ait-info/idou/"
# 日付の整合性チェック
def checkDate(year, month, day):
try:
newDateStr = "%04d/%02d/%02d"%(year, month, day)
newDate = datetime.datetime.strptime(newDateStr, "%Y/%m/%d")
return True
except:
return False
def idou_ymd(year, month, day):
# str型(表示用)
tume_m = str(month)
tume_d = str(day)
if(len(tume_m) == 1):
tume_m = "0" + tume_m
if(len(tume_d) == 1):
tume_d = "0" + tume_d
try:
# csvをリストに変換
# エラーポイント1 オープン時のエラー
# URLから取得
file = requests.get(f"{IDOU_DIR_URL}{year}{tume_m}.csv").text.splitlines()
# print(file)
reader = csv.reader(file)
# print(reader)
# dayに相当する要素を検索
for i in reader:
# print(i)
if(i[0] == str(day)):
schedule = i
break
# エラーポイント2 該当曜日がなかった場合 schedule == None のためエラー
embed = discord.Embed(title=f"{tume_m}月{tume_d}日 ({schedule[1]}) 移動販売スケジュール")
except:
embed = discord.Embed(title="エラー", description=f"該当データが存在しません", color=discord.Colour.red())
embed.add_field(name="year", value = f"{year} {type(year)}")
embed.add_field(name="month", value = f"{month} {type(month)}")
embed.add_field(name="day", value = f"{day} {type(day)}")
return embed
else:
spEmoji = ""
# 1号館前
ichigo = schedule[2]
if(ichigo == ""):
ichigo = "なし"
if("ベイサデ" in ichigo):
ichigo = "ベイザデケバブ"
# セントラル
central = schedule[3]
if(central == ""):
central = "なし"
if("ベイサデ" in central):
central = "ベイザデケバブ"
# 自由が丘
# value = schedule[4]
# if(value != ""):
# embed.add_field(name="自由が丘", value=value)
# jiyugaoka = value
# spEmoji
if("ベイザデケバブ" in central or "ベイザデケバブ" in ichigo):
spEmoji = "🥙"
elif("178" in central or "178" in ichigo):
spEmoji = "🍗"
embed = discord.Embed(title=f"{spEmoji} {tume_m}月{tume_d}日 ({schedule[1]}) 移動販売スケジュール {spEmoji}")
embed.add_field(name="1号館前", value=ichigo)
embed.add_field(name="セントラル", value=central)
embed.set_footer(text="Powered by hyouhyan.com")
return embed
def idou_command(date: str = ""):
# 日付取得
dt_now = datetime.datetime.now()
idou_y = (dt_now.year)
idou_m = (dt_now.month)
idou_d = (dt_now.day)
if date == "":
embed = idou_ymd(idou_y, idou_m, idou_d)
elif(date == "next" or date == "n"):
# 翌日
idou_d += 1
# 翌日が存在しない日だった場合
if(not checkDate(idou_y, idou_m, idou_d)):
idou_d = 1
# さらに年末だった場合
if(idou_m == 12):
idou_m = 1
idou_y += 1
else:
idou_m += 1
embed = idou_ymd(idou_y, idou_m, idou_d)
elif(date.isdigit()):
if(len(date) == 2 or len(date) == 1):
# 0詰めさせないためのint変換
idou_d = int(date)
embed = idou_ymd(idou_y, idou_m, idou_d)
elif(len(date) == 4):
result = list(date)
idou_m = int(result[0] + result[1])
idou_d = int(result[2] + result[3])
embed = idou_ymd(idou_y, idou_m, idou_d)
elif(len(date) == 8):
result = list(date)
idou_y = int(result[0] + result[1] + result[2] + result[3])
idou_m = int(result[4] + result[5])
idou_d = int(result[6] + result[7])
embed = idou_ymd(idou_y, idou_m, idou_d)
else:
embed = discord.Embed(title="エラー", description=f"日時の指定方法が違います。", color=discord.Colour.red())
embed.add_field(name="記述例", value=f"今月20日の場合\n`/idou 20`\n12月1日の場合\n`/idou 1201`\n2022年1月12日の場合\n`/idou 20220112`", inline=False)
return embed