merging pull request #4
This commit is contained in:
commit
181e89b107
|
@ -222,4 +222,4 @@ while True:
|
||||||
if len(new_msg) == 0:
|
if len(new_msg) == 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
message_queue.append( Message(9, round(time.time()), Chat(575246355, 'supergroup'), text = new_msg) )
|
message_queue.append(Message(9, round(time.time()), Chat(575246355, 'supergroup'), text = new_msg))
|
||||||
|
|
|
@ -1,31 +1,14 @@
|
||||||
## env approximation ##
|
|
||||||
'''
|
|
||||||
import datetime, json, time
|
|
||||||
|
|
||||||
class Self:
|
|
||||||
def __init__(self):
|
|
||||||
self.path = ""
|
|
||||||
self.WEEKDAY_NAMES_ROD = ["понеділка", "вівторка", "середи", "четверга", "п'ятниці", "суботи", "неділі"]
|
|
||||||
self.WEEKDAY_NAMES_ROD_WITH_NEXT = ["наступного понеділка", "наступного вівторка", "наступної середи", "наступного четверга", "наступної п'ятниці", "наступної суботи", "наступної неділі"]
|
|
||||||
self.WEEKDAY_NAMES_ROD_WITH_THIS = ["цього понеділка", "цього вівторка", "цієї середи", "цього четверга", "цієї п'ятниці", "цієї суботи", "цієї неділі"]
|
|
||||||
|
|
||||||
|
|
||||||
def readfile(path):
|
|
||||||
return open(path).read()
|
|
||||||
|
|
||||||
self = Self()
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
## code ##
|
## code ##
|
||||||
if self.MESSAGE["text"].lower() == "!пара":
|
if (self.MESSAGE["text"].lower() == "!пара" or self.MESSAGE["text"].lower().split()[0] == "!пари"):
|
||||||
|
|
||||||
|
#getting current time
|
||||||
current_time = datetime.datetime.now()
|
current_time = datetime.datetime.now()
|
||||||
|
|
||||||
current_week = current_time.isocalendar()[1] % 2
|
current_week = current_time.isocalendar()[1] % 2
|
||||||
current_day = current_time.weekday()
|
current_day = current_time.weekday()
|
||||||
current_seconds = current_week*604800 + current_day*86400 + current_time.hour*3600 + current_time.minute*60 + current_time.second
|
current_seconds = current_week*604800 + current_day*86400 + current_time.hour*3600 + current_time.minute*60 + current_time.second
|
||||||
reference_time = int(current_time.strftime("%s")) - current_seconds
|
reference_time = int(current_time.strftime("%s")) - current_seconds
|
||||||
|
|
||||||
# baking defined schedule
|
# baking defined schedule
|
||||||
raw_schedule = json.loads( readfile(self.path + "schedule.json") )
|
raw_schedule = json.loads( readfile(self.path + "schedule.json") )
|
||||||
schedule = {}
|
schedule = {}
|
||||||
|
@ -35,8 +18,8 @@ if self.MESSAGE["text"].lower() == "!пара":
|
||||||
new_item = dict(raw_schedule[day][i])
|
new_item = dict(raw_schedule[day][i])
|
||||||
new_item["source"] = "schedule"
|
new_item["source"] = "schedule"
|
||||||
schedule[ts] = new_item
|
schedule[ts] = new_item
|
||||||
|
|
||||||
# baking additions (extra pairs)
|
# baking additions (extra lessons)
|
||||||
raw_additions = json.loads( readfile(self.path + "additions.json") )
|
raw_additions = json.loads( readfile(self.path + "additions.json") )
|
||||||
additions = {}
|
additions = {}
|
||||||
for day in range(len(raw_additions)):
|
for day in range(len(raw_additions)):
|
||||||
|
@ -47,40 +30,41 @@ if self.MESSAGE["text"].lower() == "!пара":
|
||||||
schedule[ts] = new_item
|
schedule[ts] = new_item
|
||||||
|
|
||||||
full_schedule = dict(list(schedule.items()) + list(additions.items()))
|
full_schedule = dict(list(schedule.items()) + list(additions.items()))
|
||||||
|
|
||||||
|
if self.MESSAGE["text"].lower() == "!пара":
|
||||||
print("test1")
|
print("test1")
|
||||||
print(f"Full schedule printout: {full_schedule}")
|
print(f"Full schedule printout: {full_schedule}")
|
||||||
print(f"Current delta_time: {current_seconds}")
|
print(f"Current delta_time: {current_seconds}")
|
||||||
p = None
|
p = None
|
||||||
next_pair_time = None
|
next_lesson_time = None
|
||||||
|
|
||||||
key_list = list(full_schedule.keys())
|
key_list = list(full_schedule.keys())
|
||||||
key_list.sort()
|
key_list.sort()
|
||||||
for i in key_list:
|
for i in key_list:
|
||||||
if i > current_seconds - 5400:
|
if i > current_seconds - 5400:
|
||||||
p = full_schedule[i]
|
p = full_schedule[i]
|
||||||
next_pair_time = i
|
next_lesson_time = i
|
||||||
break
|
break
|
||||||
|
|
||||||
print("test2")
|
print("test2")
|
||||||
if next_pair_time == None:
|
if next_lesson_time == None:
|
||||||
if len(full_schedule.keys()) > 0:
|
if len(full_schedule.keys()) > 0:
|
||||||
print("test3.1")
|
print("test3.1")
|
||||||
actual_pair_ts = reference_time + min(full_schedule.keys())
|
actual_lesson_ts = reference_time + min(full_schedule.keys())
|
||||||
dt_pair = datetime.datetime.fromtimestamp(actual_pair_ts)
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
||||||
dt_pair_finish = datetime.datetime.fromtimestamp(actual_pair_ts + 5400)
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
||||||
p = full_schedule[min(full_schedule.keys())]
|
p = full_schedule[min(full_schedule.keys())]
|
||||||
print("test3.1.1")
|
print("test3.1.1")
|
||||||
|
|
||||||
print("{} == 6 && {} == 1, {}".format(current_day, dt_pair.strftime('%u'), str( ((current_day + 2) == int(dt_pair.strftime("%u"))) or ((str(current_day) == "6") and (dt_pair.strftime("%u") == "1")) )))
|
print("{} == 6 && {} == 1, {}".format(current_day, dt_lesson.strftime('%u'), str( ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")) )))
|
||||||
|
|
||||||
human_readable_date = ""
|
human_readable_date = ""
|
||||||
if ((current_day + 2) == int(dt_pair.strftime("%u"))) or ((str(current_day) == "6") and (dt_pair.strftime("%u") == "1")):
|
if ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")):
|
||||||
human_readable_date += "завтра "
|
human_readable_date += "завтра "
|
||||||
elif current_week != int(dt_pair.strftime("%W")) % 2:
|
elif current_week != int(dt_lesson.strftime("%W")) % 2:
|
||||||
human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_NEXT[int(dt_pair.strftime("%u")) - 1])
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_NEXT[int(dt_lesson.strftime("%u")) - 1])
|
||||||
elif current_day != (int(dt_pair.strftime("%u")) - 1):
|
elif current_day != (int(dt_lesson.strftime("%u")) - 1):
|
||||||
human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_THIS[int(dt_pair.strftime("%u")) - 1])
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_THIS[int(dt_lesson.strftime("%u")) - 1])
|
||||||
else:
|
else:
|
||||||
human_readable_date += "сьогодні "
|
human_readable_date += "сьогодні "
|
||||||
|
|
||||||
|
@ -89,11 +73,11 @@ if self.MESSAGE["text"].lower() == "!пара":
|
||||||
human_readable_date += "з "
|
human_readable_date += "з "
|
||||||
|
|
||||||
print("test3.1.3")
|
print("test3.1.3")
|
||||||
human_readable_date += dt_pair.strftime("%H:%M")
|
human_readable_date += dt_lesson.strftime("%H:%M")
|
||||||
print("test3.1.4")
|
print("test3.1.4")
|
||||||
|
|
||||||
human_readable_date += " до "
|
human_readable_date += " до "
|
||||||
human_readable_date += dt_pair_finish.strftime("%H:%M")
|
human_readable_date += dt_lesson_finish.strftime("%H:%M")
|
||||||
|
|
||||||
self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(p['name'], human_readable_date, p['teacher'], p['link'])
|
self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(p['name'], human_readable_date, p['teacher'], p['link'])
|
||||||
print("test3.1.5")
|
print("test3.1.5")
|
||||||
|
@ -102,60 +86,31 @@ if self.MESSAGE["text"].lower() == "!пара":
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("test3.2")
|
print("test3.2")
|
||||||
actual_pair_ts = reference_time + next_pair_time
|
actual_lesson_ts = reference_time + next_lesson_time
|
||||||
dt_pair = datetime.datetime.fromtimestamp(actual_pair_ts)
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
||||||
dt_pair_finish = datetime.datetime.fromtimestamp(actual_pair_ts + 5400)
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
||||||
|
|
||||||
human_readable_date = ""
|
human_readable_date = ""
|
||||||
if ((current_day + 2) == int(dt_pair.strftime("%u"))) or ((str(current_day) == "6") and (dt_pair.strftime("%u") == "1")):
|
if ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")):
|
||||||
human_readable_date += "завтра "
|
human_readable_date += "завтра "
|
||||||
elif current_week != int(dt_pair.strftime("%W")) % 2:
|
elif current_week != int(dt_lesson.strftime("%W")) % 2:
|
||||||
human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_NEXT[int(dt_pair.strftime("%u")) - 1])
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_NEXT[int(dt_lesson.strftime("%u")) - 1])
|
||||||
elif current_day != (int(dt_pair.strftime("%u")) - 1):
|
elif current_day != (int(dt_lesson.strftime("%u")) - 1):
|
||||||
human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_THIS[int(dt_pair.strftime("%u")) - 1])
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_THIS[int(dt_lesson.strftime("%u")) - 1])
|
||||||
else:
|
else:
|
||||||
human_readable_date += "сьогодні "
|
human_readable_date += "сьогодні "
|
||||||
|
|
||||||
human_readable_date += "з "
|
human_readable_date += "з "
|
||||||
human_readable_date += dt_pair.strftime("%H:%M")
|
human_readable_date += dt_lesson.strftime("%H:%M")
|
||||||
|
|
||||||
human_readable_date += " до "
|
human_readable_date += " до "
|
||||||
human_readable_date += dt_pair_finish.strftime("%H:%M")
|
human_readable_date += dt_lesson_finish.strftime("%H:%M")
|
||||||
|
|
||||||
self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(p['name'], human_readable_date, p['teacher'], p['link'])
|
self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(p['name'], human_readable_date, p['teacher'], p['link'])
|
||||||
|
|
||||||
if self.MESSAGE["text"].lower().split()[0] == "!пари":
|
if self.MESSAGE["text"].lower().split()[0] == "!пари":
|
||||||
command = self.MESSAGE["text"].lower().split()
|
command = self.MESSAGE["text"].lower().split()
|
||||||
|
|
||||||
current_time = datetime.datetime.now()
|
|
||||||
|
|
||||||
current_week = current_time.isocalendar()[1] % 2
|
|
||||||
current_day = current_time.weekday()
|
|
||||||
current_seconds = current_week*604800 + current_day*86400 + current_time.hour*3600 + current_time.minute*60 + current_time.second
|
|
||||||
reference_time = int(current_time.strftime("%s")) - current_seconds
|
|
||||||
|
|
||||||
# baking defined schedule
|
|
||||||
raw_schedule = json.loads( readfile(self.path + "schedule.json") )
|
|
||||||
schedule = {}
|
|
||||||
for day in range(len(raw_schedule)):
|
|
||||||
for i in raw_schedule[day]:
|
|
||||||
ts = day*86400 + int(i.split(":")[0])*3600 + int(i.split(":")[1])*60
|
|
||||||
new_item = dict(raw_schedule[day][i])
|
|
||||||
new_item["source"] = "schedule"
|
|
||||||
schedule[ts] = new_item
|
|
||||||
|
|
||||||
# baking additions (extra pairs)
|
|
||||||
raw_additions = json.loads( readfile(self.path + "additions.json") )
|
|
||||||
additions = {}
|
|
||||||
for day in range(len(raw_additions)):
|
|
||||||
for i in raw_additions[day]:
|
|
||||||
ts = day*86400 + int(i.split(":")[0])*3600 + int(i.split(":")[1])*60
|
|
||||||
new_item = dict(raw_additions[day][i])
|
|
||||||
new_item["source"] = "additions"
|
|
||||||
schedule[ts] = new_item
|
|
||||||
|
|
||||||
full_schedule = dict(list(schedule.items()) + list(additions.items()))
|
|
||||||
|
|
||||||
preferences = {"name": True, "date": True, "teacher": True, "link": True}
|
preferences = {"name": True, "date": True, "teacher": True, "link": True}
|
||||||
selected_day = current_week*7 + current_day
|
selected_day = current_week*7 + current_day
|
||||||
|
|
||||||
|
@ -188,33 +143,33 @@ if self.MESSAGE["text"].lower().split()[0] == "!пари":
|
||||||
elif i[0] == "-":
|
elif i[0] == "-":
|
||||||
preferences[i[1:]] = False
|
preferences[i[1:]] = False
|
||||||
|
|
||||||
found_pairs = {}
|
found_lessons = {}
|
||||||
for i in full_schedule:
|
for i in full_schedule:
|
||||||
if selected_day*86400 <= i < (selected_day+1)*86400:
|
if selected_day*86400 <= i < (selected_day+1)*86400:
|
||||||
found_pairs[i] = dict(full_schedule[i])
|
found_lessons[i] = dict(full_schedule[i])
|
||||||
|
|
||||||
result_text = f"Пари у {self.WEEKDAY_NAMES_ZNAH[selected_day%7]}:\n\n"
|
result_text = f"Пари у {self.WEEKDAYS_ACCUSATIVE[selected_day%7]}:\n\n"
|
||||||
for i in found_pairs:
|
for i in found_lessons:
|
||||||
actual_pair_ts = reference_time + i
|
actual_lesson_ts = reference_time + i
|
||||||
dt_pair = datetime.datetime.fromtimestamp(actual_pair_ts)
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
||||||
dt_pair_finish = datetime.datetime.fromtimestamp(actual_pair_ts + 5400)
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
||||||
p = found_pairs[i]
|
p = found_lessons[i]
|
||||||
|
|
||||||
human_readable_date = ""
|
human_readable_date = ""
|
||||||
if ((current_day + 2) == int(dt_pair.strftime("%u"))) or ((str(current_day) == "6") and (dt_pair.strftime("%u") == "1")):
|
if ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")):
|
||||||
human_readable_date += "завтра "
|
human_readable_date += "завтра "
|
||||||
elif current_week != int(dt_pair.strftime("%W")) % 2:
|
elif current_week != int(dt_lesson.strftime("%W")) % 2:
|
||||||
human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_NEXT[int(dt_pair.strftime("%u")) - 1])
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_NEXT[int(dt_lesson.strftime("%u")) - 1])
|
||||||
elif current_day != (int(dt_pair.strftime("%u")) - 1):
|
elif current_day != (int(dt_lesson.strftime("%u")) - 1):
|
||||||
human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_THIS[int(dt_pair.strftime("%u")) - 1])
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_THIS[int(dt_lesson.strftime("%u")) - 1])
|
||||||
else:
|
else:
|
||||||
human_readable_date += "сьогодні "
|
human_readable_date += "сьогодні "
|
||||||
|
|
||||||
human_readable_date += "з "
|
human_readable_date += "з "
|
||||||
human_readable_date += dt_pair.strftime("%H:%M")
|
human_readable_date += dt_lesson.strftime("%H:%M")
|
||||||
|
|
||||||
human_readable_date += " до "
|
human_readable_date += " до "
|
||||||
human_readable_date += dt_pair_finish.strftime("%H:%M")
|
human_readable_date += dt_lesson_finish.strftime("%H:%M")
|
||||||
|
|
||||||
|
|
||||||
if preferences['name']:
|
if preferences['name']:
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
self.WEEKDAY_NAMES_ZNAH = ["понедулок", "вівторок", "середу", "четвер", "п'ятницю", "суботу", "неділю"]
|
# Accusative - znahidnyj
|
||||||
self.WEEKDAY_NAMES_ROD_WITH_NEXT = ["наступного понеділка", "наступного вівторка", "наступної середи", "наступного четверга", "наступної п'ятниці", "наступної суботи", "наступної неділі"]
|
self.WEEKDAYS_ACCUSATIVE = ["понеділок", "вівторок", "середу", "четвер", "п'ятницю", "суботу", "неділю"]
|
||||||
self.WEEKDAY_NAMES_ROD_WITH_THIS = ["цього понеділка", "цього вівторка", "цієї середи", "цього четверга", "цієї п'ятниці", "цієї суботи", "цієї неділі"]
|
# Genitive - rodovyj
|
||||||
self.current_seconds = 0
|
self.WEEKDAYS_GENITIVE_NEXT = ["наступного понеділка", "наступного вівторка", "наступної середи", "наступного четверга", "наступної п'ятниці", "наступної суботи", "наступної неділі"]
|
||||||
|
self.WEEKDAYS_GENITIVE_THIS = ["цього понеділка", "цього вівторка", "цієї середи", "цього четверга", "цієї п'ятниці", "цієї суботи", "цієї неділі"]
|
||||||
|
self.current_seconds = 0
|
Loading…
Reference in New Issue