#!/usr/bin/env python
#coding:utf-8
'''
author:shilei
'''
import time
import unittest
from selenium import webdriver
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
class Auto_metting():
def setUp(self,username,password,h_name1,floor,second):
self.username = username
self.password = password
self.h_name1 = h_name1
self.floor = floor
self.second = second
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(2)
self.driver.maximize_window()
self.driver.get("")
def teatDown(self):
self.driver.quit()
def test_01(self):
'''
loging
:return:
'''
self.driver.find_element_by_id('username').send_keys(self.username)
self.driver.find_element_by_id('password-email').send_keys(self.password)
self.driver.implicitly_wait(0.3)
login = self.driver.find_element_by_id('emailLogin').click()
close_1 = self.driver.find_element_by_xpath('/html/body/div[3]/div/div[1]/button/i')
# i = 7#空闲会议室,例子:9点是1,14点是6
# i = 1
# i = int(i)
j = 0
if close_1:
close_1.click()
self.driver.implicitly_wait(10)
time.sleep(0.3)
F_xpath = '//*[@id="app"]//*[@class="item"][{0}]'.format(self.floor)
self.driver.find_element_by_xpath(F_xpath).click()
#7天后会议室
self.driver.find_element_by_xpath(
'//*[@id="app"]/div/div[2]/div/div[2]/div[3]/div/div/div/ul[1]/li[9]/span').click()#today_ago_7
time.sleep(0.3)
now = time.time()
# print("当前时间戳:%s" % now)
# 格式化年月日时分秒
local_time = time.localtime(now)
date_format_localtime = time.strftime('%Y-%m-%d %H:%M:%S', local_time)
# date_format_localtime = time.strftime('%H:%M:%S', local_time)
print("格式化时间之后为:%s" % date_format_localtime)
date_format_localtime = time.strftime('%S', local_time)
print("格式化时间之后为:%s" % date_format_localtime)
if date_format_localtime != '00':
s_1 = 60 - int(date_format_localtime)
print(s_1)
time.sleep(s_1)
while j<20:
now1 = time.time()
local_time = time.localtime(now1)
date_format_localtime = time.strftime('%Y-%m-%d %H:%M:%S', local_time)
print(date_format_localtime)
j += 1
time.sleep(0.1)
self.driver.implicitly_wait(5)
num = r'//*[@id={0}]//*[@class="time-list free"][{1}]'.format(self.h_name1,self.second)
xiawu = self.driver.find_element_by_xpath(num).click()#会议室时间段
yuding_1 = '//*[@id={0}]/div[2]/div[4]/button[5]/span'.format(self.h_name1)
try:
if self.driver.find_element_by_xpath(yuding_1):#预定按钮
self.driver.find_element_by_xpath(yuding_1).click()
self.driver.implicitly_wait(1)
# time.sleep(0.1)
self.driver.find_element_by_xpath('/html/body/div[3]/div/div[1]/button/i').click()
pass
else:
self.driver.refresh() # 刷新
pass
except Exception as ex:
self.driver.refresh()
print(ex)
self.driver.implicitly_wait(1)
else:
print('no close page')
def main():
username = ''#账号
password = '' # 密码
h_name1 = "10113336" # 采茶煮春碧
h_name2 = "10114246" # 东平引
h_name3 = "10113334" # 东风吹酒面
h_name4 = "10113615" # 金菊香
h_name5 = "10113317" # 白苹香
floor = 6# # 选择楼层5,floor=楼层+1
second = 8# # 空闲会议室,例子:9点是1,14点是6
Auto_metting.setUp(username, password,h_name1,floor,second)
Auto_metting.test_01()
def main1():
sched = BlockingScheduler()
# sched.add_job(main, 'interval', hours=2, start_date='2019-12-25 10:14:55',end_date='2019-12-25 10:18:00')
# sched.add_job(main, 'interval', minutes=0.5, start_date='2019-12-26 9:59:52',end_date='2019-12-27 10:28:00')
# sched.add_job(main, 'interval', days=1, start_date='2019-12-26 9:59:50',end_date='2019-12-27 10:28:00')
sched.add_job(main, 'interval', days=1, start_date='2019-12-26 9:59:47',end_date='2020-1-31 10:28:00')
sched.start()
if __name__ == '__main__':
Auto_metting = Auto_metting()
# BlockingScheduler
main1()
# Schedule job_function to be called every two hours
# sched.add_job(main(), 'interval', hours=2)
# The same as before, but starts on 2010-10-10 at 9:30 and stops on 2014-06-15 at 11:00
环境:python2+selenium
库:
import time import unittest from selenium import webdriver from datetime import datetime from apscheduler.schedulers.blocking import BlockingScheduler#定时