def data_output(self, datas, ngt_type): for data in datas['items']: schedule = Schedule() # print('summary: ', data['summary']) schedule.title = data['summary'] schedule.event_type = ngt_type if 'dateTime' in data['start']: # print('start: ', data['start']['dateTime']) schedule.start_time = data['start']['dateTime'][11:16] if int(schedule.start_time[0:2]) <= 3: schedule.start_time = str(int(schedule.start_time[0:2]) + 24) + schedule.start_time[2:] if 'dateTime' in data['end']: # print('end: ', data['end']['dateTime']) schedule.end_time = data['end']['dateTime'][11:16] if int(schedule.end_time[0:2]) < 3: schedule.end_time = str(int(schedule.end_time[0:2]) + 24) + schedule.end_time[2:] if 'date' in data['start']: # print('start: ', data['start']['date']) schedule.start_time = "" if 'date' in data['end']: # print('end: ', data['end']['date']) schedule.end_time = "" if 'description' in data: # print('description: ', data['description']) schedule.description = data['description'] if 'location' in data: # print('location: ', data['location']) schedule.location = data['location'] self.schedule_list.append(schedule)
def get_schedule(self) -> [Schedule]: get_time = time.strptime(self.query_date, '%Y/%m/%d') year = time.strftime('%Y', get_time) month = time.strftime('%m', get_time) day = time.strftime('%d', get_time) body = {'month': month, 'year': year, 'category': 0} url = 'https://www.akb48.co.jp/public/api/schedule/calendar/' response_json = requests.post(url, data=body).json() today_key = year + '_' + month + '_' + str(int(day)) members_api = 'https://www.akb48.co.jp/public/api/member/list/' members_dic = requests.post(members_api).json()["data"] # print(json.dumps(response_json, ensure_ascii=False)) if today_key not in response_json["data"]["thismonth"]: return [] today_list = response_json["data"]["thismonth"][today_key] schedule_list = [] for schedule_dic in today_list: schedule = Schedule() schedule.title = schedule_dic["title"] if schedule_dic["parent_category"] in self.category: schedule.event_type = self.category[ schedule_dic["parent_category"]] schedule.start_time = schedule_dic["date"][-8:-3] schedule.end_time = schedule_dic["end_date"][-8:-3] if schedule_dic["member"]: member_key_list = schedule_dic["member"].split(',') else: member_key_list = [] # print(member_key_list) if members_dic and len(member_key_list) > 0: members_name_list = [] for member_no in member_key_list: if member_no in members_dic: name = members_dic[member_no]["name"].replace('\t', '') members_name_list.append(name) schedule.members = members_name_list schedule_list.append(schedule) # print(today_list) return schedule_list