forked from dymik739/modular-bot-framework-for-telegram
		
	add testing code for web service
This commit is contained in:
		
							parent
							
								
									5af49c9147
								
							
						
					
					
						commit
						f213710601
					
				
							
								
								
									
										111
									
								
								modules/auto-schedule-pro/www/index.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								modules/auto-schedule-pro/www/index.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,111 @@
 | 
			
		||||
import datetime
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
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( open("../schedule.json").read() )
 | 
			
		||||
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( open("../additions.json").read() )
 | 
			
		||||
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()))
 | 
			
		||||
 | 
			
		||||
#print("test1")
 | 
			
		||||
#print(f"Full schedule #printout: {full_schedule}")
 | 
			
		||||
#print(f"Current delta_time: {current_seconds}")
 | 
			
		||||
p = None
 | 
			
		||||
next_pair_time = None
 | 
			
		||||
 | 
			
		||||
key_list = list(full_schedule.keys())
 | 
			
		||||
key_list.sort()
 | 
			
		||||
for i in key_list:
 | 
			
		||||
    if i > current_seconds - 5400:
 | 
			
		||||
        p = full_schedule[i]
 | 
			
		||||
        next_pair_time = i
 | 
			
		||||
        break
 | 
			
		||||
 | 
			
		||||
#print("test2")
 | 
			
		||||
if next_pair_time == None:
 | 
			
		||||
    if len(full_schedule.keys()) > 0:
 | 
			
		||||
        #print("test3.1")
 | 
			
		||||
        actual_pair_ts = reference_time + min(full_schedule.keys())
 | 
			
		||||
        dt_pair = datetime.datetime.fromtimestamp(actual_pair_ts)
 | 
			
		||||
        dt_pair_finish = datetime.datetime.fromtimestamp(actual_pair_ts + 5400)
 | 
			
		||||
        p = full_schedule[min(full_schedule.keys())]
 | 
			
		||||
        #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")) )))
 | 
			
		||||
 | 
			
		||||
        human_readable_date = ""
 | 
			
		||||
        if ((current_day + 2) == int(dt_pair.strftime("%u"))) or ((str(current_day) == "6") and (dt_pair.strftime("%u") == "1")):
 | 
			
		||||
            human_readable_date += "завтра "
 | 
			
		||||
        elif current_week != int(dt_pair.strftime("%W")) % 2:
 | 
			
		||||
            human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_NEXT[int(dt_pair.strftime("%u")) - 1])
 | 
			
		||||
        elif current_day != (int(dt_pair.strftime("%u")) - 1):
 | 
			
		||||
            human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_THIS[int(dt_pair.strftime("%u")) - 1])
 | 
			
		||||
        else:
 | 
			
		||||
            human_readable_date += "сьогодні "
 | 
			
		||||
 | 
			
		||||
        #print("test3.1.2")
 | 
			
		||||
 | 
			
		||||
        human_readable_date += "з "
 | 
			
		||||
        
 | 
			
		||||
        #print("test3.1.3")
 | 
			
		||||
        human_readable_date += dt_pair.strftime("%H:%M")
 | 
			
		||||
        #print("test3.1.4")
 | 
			
		||||
 | 
			
		||||
        human_readable_date += " до "
 | 
			
		||||
        human_readable_date += dt_pair_finish.strftime("%H:%M")
 | 
			
		||||
 | 
			
		||||
        #self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(p['name'], human_readable_date, p['teacher'], p['link'])
 | 
			
		||||
        #print("test3.1.5")
 | 
			
		||||
 | 
			
		||||
        print(f"Location: {p['link']}\n\n")
 | 
			
		||||
    else:
 | 
			
		||||
        self.RESPONCE = "Пар немає взагалі. Ми вільні!"
 | 
			
		||||
 | 
			
		||||
else:
 | 
			
		||||
    #print("test3.2")
 | 
			
		||||
    actual_pair_ts = reference_time + next_pair_time
 | 
			
		||||
    dt_pair = datetime.datetime.fromtimestamp(actual_pair_ts)
 | 
			
		||||
    dt_pair_finish = datetime.datetime.fromtimestamp(actual_pair_ts + 5400)
 | 
			
		||||
 | 
			
		||||
    human_readable_date = ""
 | 
			
		||||
    if ((current_day + 2) == int(dt_pair.strftime("%u"))) or ((str(current_day) == "6") and (dt_pair.strftime("%u") == "1")):
 | 
			
		||||
        human_readable_date += "завтра "
 | 
			
		||||
    elif current_week != int(dt_pair.strftime("%W")) % 2:
 | 
			
		||||
        human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_NEXT[int(dt_pair.strftime("%u")) - 1])
 | 
			
		||||
    elif current_day != (int(dt_pair.strftime("%u")) - 1):
 | 
			
		||||
        human_readable_date += "{} ".format(self.WEEKDAY_NAMES_ROD_WITH_THIS[int(dt_pair.strftime("%u")) - 1])
 | 
			
		||||
    else:
 | 
			
		||||
        human_readable_date += "сьогодні "
 | 
			
		||||
 | 
			
		||||
    human_readable_date += "з "
 | 
			
		||||
    human_readable_date += dt_pair.strftime("%H:%M")
 | 
			
		||||
 | 
			
		||||
    human_readable_date += " до "
 | 
			
		||||
    human_readable_date += dt_pair_finish.strftime("%H:%M")
 | 
			
		||||
 | 
			
		||||
    #self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(p['name'], human_readable_date, p['teacher'], p['link'])
 | 
			
		||||
 | 
			
		||||
    print(f"Location: {p['link']}\n\n")
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user