With the above post, I got the J-League schedule, so I would like to make use of it. If you can import it into the calendar app you use every day, you can save yourself the trouble of entering it one by one. Therefore Create a file in a format that you can import into Google Calendar.
sample.ics
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART;TZID=Asia/Tokyo:20200223T130000
DTEND;TZID=Asia/Tokyo:20200223T150000
SUMMARY;LANGUAGE=jp-JP:Section 1 Day 3 FC Tokyo
DESCRIPTION;LANGUAGE=jp-JP:kick off:13:00\n
Stadium: Aista\n
club:http://www.fctokyo.co.jp/\n
JAL:https://www.jal.co.jp/\n
ANA:https://www.ana.co.jp/\n
END:VEVENT
END:VCALENDAR
BEGIN: VCALENDAR VERSION: 2.0
consists of the header line and ʻEND: VCALENDAR` consists of the footer line.BEGIN: VEVENT
and ʻEND: VEVENT`. If you have multiple items, you need to repeat this.DTSTART:
start time, DTEND:
end time, and time is % Y% m% dT% H% M% S
. Example: 20200223T130000; TZID = Asia / Tokyo
.; LANGUAGE = jp-JP
.DESCRIPTION
, add \ n
at the end of the line. Regarding the content, two airlines are added in the example, but it would be convenient if there were accommodation services and stadium location information.schedule_all.py
import datetime
import pandas as pd
# 'https://data.j-league.or.jp/'Get from the schedule result of
data = pd.read_csv('./csv/Game_Schedule_2020.csv', sep=',', encoding='utf-8')
schedule_all.py
#Prepare a local file that collects the address of the club HP
club = pd.read_csv('./csv/master_club_2020.csv', sep=',', encoding='utf-8')
I prepared my own data to include the address of the club to play in the detailed data.
schedule_all.py
yyyy = 2020
#Specify the team name you want to extract
team = data[(data['home'] == 'Team name') | (data['Away'] == 'Team name')]
Change the "team name" to the team name you want to get.
schedule_all.py
#Create a fixed string
header = (r'BEGIN:VCALENDAR' + '\n'
r'VERSION:2.0' + '\n')
footer = (r'END:VCALENDAR')
info = (' JAL:https://www.jal.co.jp/\\n\n'
' ANA:https://www.ana.co.jp/\\n')
timezone = ';TZID=Asia/Tokyo'
language = ';LANGUAGE=jp-JP'
Create the strings that make up the template.
schedule_all.py
schedule_all = []
for i in range(len(team)):
if team['KO time'].iloc[i] == '● Undecided ●':
break
#Create the following items for each section from specific team data
# start_datetime, end_datetime, section, home or away team, kick_off, stadium, club HP
tmp_date = team['Match day'].iloc[i]
tmp_date = str(yyyy) + '/' + tmp_date[:5]
start_time = team['KO time'].iloc[i]
tmp_date_time = tmp_date + ' ' + start_time + ':00'
tmp_dtstart = datetime.datetime.strptime(tmp_date_time, '%Y/%m/%d %H:%M:%S')
tmp_dtend = tmp_dtstart + datetime.timedelta(hours=2)
# start_datetime
dtstart = tmp_dtstart.strftime('%Y%m%dT%H%M%S')
# end_datetime
dtend = tmp_dtend.strftime('%Y%m%dT%H%M%S')
# section
sec = team['section'].iloc[i]
# team name
team_name = team['Away'].iloc[i] if team['home'].iloc[i] == 'Team name' else team['home'].iloc[i]
# kick off
kickoff = str(team['KO time'].iloc[i])
# stadium
stadium = team['Stadium'].iloc[i]
# club HP
club_url = club[club['Abbreviation'] == team_name]['Official site URL']
#Create a character string in iCalender format from data in node units.
begin = 'BEGIN:VEVENT'
dstart = 'DTSTART' + timezone + ':' + dtstart
dend = 'DTEND' + timezone + ':' + dtend
summary = 'SUMMARY' + language + ':' + sec + ' ' + team_name
description1 = r'DESCRIPTION' + language + ':' + 'kick off:' + kickoff + '\\n'
description2 = r'Stadium:' + stadium + '\\n'
description3 = r'club:' + club_url.values[0] + '\\n\n' + info
end = 'END:VEVENT' + '\n'
#List section-by-section data
contents = [begin, dstart, dend, summary, description1, description2, description3, end]
schedule_all.append(contents)
datetime.timedelta (hours = 2)
schedule_all
schedule_all.py
#Creating a calendar file
path = './csv/schedule_all_2020.ics'
with open(path, mode='a', encoding='utf-8') as f:
f.write(header)
for s in schedule_all:
f.write('\n'.join(s))
f.write(footer)
Finally, loop through the clause-by-section list to create a text file. (* For the sake of explanation, it is divided into a loop process for creating section data and a loop process for creating a text file.)
Recommended Posts