def ImportMyXlsx(): path = GetExcelPath() info = Info() employee_id = str(info.get('MY_ID')) boss_id = str(info.get('BOSS_ID')) wb = openpyxl.load_workbook(path) ws = wb.worksheets[0] #シートの最終行を取得 Sheet_Max_Row = ws.max_row #シートの最終列を取得 Sheet_Max_Clm = ws.max_column my_list = [] title_list = [] boss_list = [] myrow = GetRowNumber(ws, Sheet_Max_Row, employee_id) bossrow = GetRowNumber(ws, Sheet_Max_Row, boss_id) my_list = CreateBaseList(ws, Sheet_Max_Clm, myrow) title_list = CreateBaseList(ws, Sheet_Max_Clm, 2) boss_list = CreateBaseList(ws, Sheet_Max_Clm, bossrow) y_m = YearMonth(ws.cell(row=1, column=1).value) start, end = GetStartIndexEndIndex(title_list) list_day = title_list[start:end] list_status = my_list[start:end] list_boss_status = boss_list[start:end] result_list = [] for index in range(len(list_day)): bossflag = BossStatus(list_boss_status[index]) flag, result_dict = SetWorkingTime(list_status[index], bossflag) if flag == True: list_day[index] = math.floor(list_day[index]) if list_day[index] < 10: list_day[index] = '0' + str(list_day[index]) else: list_day[index] = str(list_day[index]) result_list.append([ list_day[index], result_dict["start"], result_dict["end"], result_dict["status"] ]) return [y_m, result_list]
def main(mail_list): info = Info() FROM_ADDRESS = info.get('MAIL', 'FROM_ADDRESS') TO_ADDRESS = info.get('MAIL', 'TO_ADDRESS') PASSWD = info.get('MAIL', 'PASSWD') URL = info.get('MAIL', 'URL') K = info.get('K', 'NAME') S = info.get('S', 'NAME') if mail_list[0] == True: body = str(mail_list[2]) + "月の予定を更新しました。\n\n" + K + "\n出勤日数 : " + str(mail_list[3]) + "日\n" + \ S + "\n出勤日数 : " + str(mail_list[4]) + "日\n\n\n\n下記リンクから確認できます。\n" + URL subject = "Google Calendar " + str(mail_list[1]) + "年" + str(mail_list[2]) + "月" else: body = "パスワードが正しくありません。\n新しいパスワードを連絡して下さい。" subject = "Password Error" body_msg = CreateMsg(FROM_ADDRESS, TO_ADDRESS, subject, body) SendGmail(FROM_ADDRESS, PASSWD, body_msg) # if __name__ == '__main__': # main()
def CopyXlsx(): info = Info() KEYWORD = info.get('KEYWORD') # DIR = info.get('DIR') items = os.listdir("./") # items = os.listdir(DIR) for item in items: if KEYWORD in item: file_name = item shutil.copy("./" + file_name, './excel/' + file_name[len(KEYWORD):]) os.remove("./" + file_name)
from Info import Info # 編集スコープの設定(今回は読み書き両方OKの設定) SCOPES = ['https://www.googleapis.com/auth/calendar'] # 認証ファイルを使用して認証用オブジェクトを作成 gapi_creds = google.auth.load_credentials_from_file('credentials.json', SCOPES)[0] # 認証用オブジェクトを使用してAPIを呼び出すためのオブジェクト作成 service = googleapiclient.discovery.build('calendar', 'v3', credentials=gapi_creds) info = Info() DESCRIPTION = info.get('K', 'DESCRIPTION') CALENDAR_ID_K = info.get('K', 'CALENDAR_ID') CALENDAR_ID_S = info.get('S', 'CALENDAR_ID') def SettingEvents(CALENDAR_ID, y, m): # Call the Calendar API timefrom, timeto = SetTimeInfo(y, m) timefrom = datetime.datetime.strptime( timefrom, '%Y/%m/%dT%H:%M:%S').isoformat() + 'Z' timeto = datetime.datetime.strptime(timeto, '%Y/%m/%dT%H:%M:%S').isoformat() + 'Z' events_result = service.events().list(calendarId=CALENDAR_ID, timeMin=timefrom, timeMax=timeto, singleEvents=True,
import datetime import googleapiclient.discovery import google.auth from Info import Info # 編集スコープの設定(今回は読み書き両方OKの設定) SCOPES = ['https://www.googleapis.com/auth/calendar'] info = Info() HOLIDAY_CALENDAR_ID = info.get('S', 'HOLIDAY_CALENDAR_ID') SUMMARY = info.get('S', 'SUMMARY') LOCATION = info.get('S', 'LOCATION') DESCRIPTION = info.get('S', 'DESCRIPTION') TIMEZONE = info.get('S', 'TIMEZONE') # 認証ファイルを使用して認証用オブジェクトを作成 gapi_creds = google.auth.load_credentials_from_file('credentials.json', SCOPES)[0] # 認証用オブジェクトを使用してAPIを呼び出すためのオブジェクト作成 service = googleapiclient.discovery.build('calendar', 'v3', credentials=gapi_creds) day_list = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] def Holiday(year, month): sdt = datetime.datetime(year, month, 1, tzinfo=datetime.timezone.utc).isoformat() edt = datetime.datetime(year, month, day_list[month], tzinfo=datetime.timezone.utc).isoformat() # calendarIdに「日本の祝日」のカレンダーIDを指定して、イベントを取得する eventsResult = service.events().list( calendarId=HOLIDAY_CALENDAR_ID, timeMin=sdt, timeMax=edt,
def DownloadXlsx(): CHROME_DRIVER = './chromedriver' options = Options() options.add_argument('--headless') options.add_argument("--no-sandbox") options.add_argument("--disable-setuid-sandbox") options.add_argument('--disable-features=VizDisplayCompositor') driver = webdriver.Chrome(CHROME_DRIVER, options=options) # CHROME_BIN = "/usr/bin/chromium-browser" # options.binary_location = CHROME_BIN # driver = webdriver.Chrome(executable_path="./chromedriver") info = Info() URL = info.get('URL') ID = info.get('MY_ID') PASS = info.get('PASS') driver.get(URL) # 3秒待機 time.sleep(3) # ログインIDを入力 login_id = driver.find_element_by_name("p2") login_id.send_keys(ID) # 1秒待機 time.sleep(1) # パスワードを入力 password = driver.find_element_by_name("p3") password.send_keys(PASS) # 1秒待機 time.sleep(1) # 次へボタンをクリック next_btn = driver.find_element_by_xpath("/html/body/div/form/div/button") next_btn.click() # 3秒待機 time.sleep(3) try: close = driver.find_element_by_xpath( "/html/body/ngb-modal-window/div/div/lib-ngx-sibic-sp-dialog-info/div/button" ) except NoSuchElementException: pass driver.quit() return False close.click() # 1秒待機 time.sleep(1) dl_btn = driver.find_element_by_xpath( "/html/body/app-root/app-employee-view/app-footer/nav/nav/div/div[3]/button" ) dl_btn.click() # 1秒待機 time.sleep(1) download = driver.find_element_by_xpath( "/html/body/ngb-modal-window/div/div/lib-ngx-sibic-sp-dialog-download/div[2]/div/button" ) download.click() # 10秒待機 time.sleep(10) driver.quit() return True
from Info import Info from import_xlsx import ImportMyXlsx # シフト表のExcelファイルから自分の予定をimport return_list = ImportMyXlsx() y_m = return_list[0] working_list = return_list[1] info = Info() SUMMARY = info.get('K', 'SUMMARY') LOCATION = info.get('K', 'LOCATION') DESCRIPTION = info.get('K', 'DESCRIPTION') TIMEZONE = info.get('K', 'TIMEZONE') # 追加するスケジュールの情報を設定 def insert_event_K(): event_list = [] for i in range(len(working_list)): day = working_list[i][0] start = working_list[i][1] end = working_list[i][2] status = working_list[i][3] event = { 'summary': SUMMARY + status, 'location': LOCATION, 'description': DESCRIPTION, 'start': { 'dateTime': y_m[0] + '-' + y_m[1] + '-' + day + 'T' + start + ':00', 'timeZone': TIMEZONE,
import googleapiclient.discovery import google.auth from Info import Info from copy_xlsx import CopyXlsx from download_xlsx import DownloadXlsx import insert_event_K, insert_event_S from send_mail import main as send_mail # 編集スコープの設定(今回は読み書き両方OKの設定) SCOPES = ['https://www.googleapis.com/auth/calendar'] info = Info() CALENDAR_ID_K = info.get('K', 'CALENDAR_ID') CALENDAR_ID_S = info.get('S', 'CALENDAR_ID') def Push_Calendar(event_list, CALENDAR_ID): # 認証ファイルを使用して認証用オブジェクトを作成 gapi_creds = google.auth.load_credentials_from_file('credentials.json', SCOPES)[0] # 認証用オブジェクトを使用してAPIを呼び出すためのオブジェクト作成 service = googleapiclient.discovery.build('calendar', 'v3', credentials=gapi_creds) for event in event_list: # 予定を追加する event = service.events().insert(calendarId = CALENDAR_ID, body = event).execute() def main(): mail_list = [] mail_list.append(DownloadXlsx()) if mail_list[0] == True: CopyXlsx()