-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonToCal.py
executable file
·102 lines (91 loc) · 3.22 KB
/
jsonToCal.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
from datetime import datetime
import json
from pprint import pprint
from insertGoogleCal import *
import configparser
import sys
import asyncio
import time
def asyncInsert(dict, kaisaiday):
print(dict, kaisaiday)
classs = ""
if dict.get('class') != None:
classs = dict['class']
if dict.get('class') == None:
classs = ""
if dict.get('jikan') != None:
jyo = j['jyo']
jikan, startTime, endTime = jikanToDatetime(dict['jikan'], kaisaiday)
insStr = f'{jyo}{classs}{jikan}{startTime}{endTime}'
# print(insStr)j
insertGoogleCal(f'{jyo}{shubetuStr}',
startTime, endTime, colorId, calendarId)
else:
jyo = dict['jyo']
startTime = datetime.strptime(
f'{nowYear}{kaisaiday} 12:00', '%Y%m/%d %H:%M')
endTime = datetime.strptime(
f'{nowYear}{kaisaiday} 17:00', '%Y%m/%d %H:%M')
jikan = "日中"
insStr = f'{jyo}{jikan}{startTime}{endTime}'
print(insStr)
insertGoogleCal(f'{jyo}{shubetuStr}',
startTime, endTime, colorId, calendarId)
def auth_cal_id(envName):
config = configparser.ConfigParser()
config.read('setting.ini')
calId = config.get(envName, 'calId')
return calId
def selectGamble(envName):
if envName == "kyotei":
shubetuStr = "競艇"
colorId = "1"
if envName == "keirin":
shubetuStr = "競輪"
colorId = "2"
if envName == "keiba":
shubetuStr = "競馬"
colorId = "3"
if envName == "autorace":
shubetuStr = "オートレース"
colorId = "4"
if envName == "keiba_jra":
shubetuStr = "中央競馬"
colorId = "5"
return shubetuStr, colorId
def jikanToDatetime(jikan, kaisaiDay):
rawStr = f'{nowYear}{kaisaiDay}'
if jikan == 'midnight':
returnStr = 'ミッドナイト'
rawDateStart = f'{rawStr} 20:00'
rawDateEnd = f'{rawStr} 23:30'
startTime = datetime.strptime(rawDateStart, '%Y%m/%d %H:%M')
endTime = datetime.strptime(rawDateEnd, '%Y%m/%d %H:%M')
if jikan == 'nighter':
rawDateStart = f'{rawStr} 15:00'
rawDateEnd = f'{rawStr} 20:50'
startTime = datetime.strptime(rawDateStart, '%Y%m/%d %H:%M')
endTime = datetime.strptime(rawDateEnd, '%Y%m/%d %H:%M')
returnStr = 'ナイター'
if jikan == 'morning':
returnStr = 'モーニング'
rawDateStart = f'{rawStr} 09:00'
rawDateEnd = f'{rawStr} 15:00'
startTime = datetime.strptime(rawDateStart, '%Y%m/%d %H:%M')
endTime = datetime.strptime(rawDateEnd, '%Y%m/%d %H:%M')
if jikan == 'summer':
returnStr = 'サマータイム'
rawDateStart = f'{rawStr} 12:30'
rawDateEnd = f'{rawStr} 18:30'
startTime = datetime.strptime(rawDateStart, '%Y%m/%d %H:%M')
endTime = datetime.strptime(rawDateEnd, '%Y%m/%d %H:%M')
return returnStr, startTime, endTime
envName = sys.argv[1]
nowYear = sys.argv[2]
nowMouth = sys.argv[3]
calendarId = auth_cal_id(envName)
shubetuStr, colorId = selectGamble(envName)
loadJson = json.load(open(f'{nowYear}{nowMouth}{envName}.json'))
for i in loadJson.items():
for j in i[1]:
asyncInsert(j, i[0])