Exemplo n.º 1
0
    def loop_reservate(self, roomId=16, seat_no=17, start=14.5, end=17):
        today = datetime.date.today()
        token = self.__token
        library = lib.Lib()

        self.reservate_exclude(roomId, str(today), start, end)

        while True:
            time.sleep(8)
            seats = library.free_seats(token, roomId, str(today), start, end)
            while seats == None:
                self.get_token()
                token = self.__token
                seats = library.free_seats(token, roomId, str(today), start,
                                           end)
                self.count()

            if len(seats) == 0:
                print('retrying...')
                continue
            self.stop_cancel()
            self.get_token()
            result, location = self.reservate(roomId, seat_no, str(today),
                                              start, end)
            if result:
                break
Exemplo n.º 2
0
    def get_post(self, id='', cat='', q=''):
        vdict = copy.deepcopy(config.vdict)

        if id:
            URL = "https://www.googleapis.com/blogger/v3/blogs/" + vdict[
                'blog-id'] + "/posts/" + id
            PARAMS = {"key": vdict['api-key']}
            r = requests.get(url=URL, params=PARAMS)
            data = r.json()
            vdict['post'] = data
            vdict['id'] = id
        elif cat:
            vdict['cat'] = cat
        elif q:
            URL = "https://www.googleapis.com/blogger/v3/blogs/" + vdict[
                'blog-id'] + "/posts/search"
            PARAMS = {"key": vdict['api-key'], 'q': q, 'fetchBodies': False}
            r = requests.get(url=URL, params=PARAMS)
            data = r.json()
            if 'items' in data:
                vdict['posts'] = data['items']

        self.vlib = lib.Lib()
        vdict['date'] = self.vlib.set_date()

        return vdict
Exemplo n.º 3
0
def get_lib():
    global library
    if not library:
        l = lib.Lib()
        l.load_defs()
        library = l
    return library
Exemplo n.º 4
0
    def set_root(self):
        vlib = lib.Lib()
        vdatetime = vlib.get_timezone()
        date = datetime.strptime(vdatetime[0], "%d/%m/%Y")
        time = datetime.strptime(vdatetime[1], '%H:%M:%S')

        self.userdb.insert('root', '*****@*****.**', 'root', 'Admin', '',
                           date, time, 'root')
Exemplo n.º 5
0
    def get_page(self, id=''):
        vdict = copy.deepcopy(config.vdict)

        if id:
            URL = "https://www.googleapis.com/blogger/v3/blogs/" + vdict[
                'blog-id'] + "/pages/" + id
            PARAMS = {"key": vdict['api-key']}
            r = requests.get(url=URL, params=PARAMS)
            data = r.json()
            print(data)
            vdict['page'] = data
            vdict['id'] = id

        self.vlib = lib.Lib()
        vdict['date'] = self.vlib.set_date()

        return vdict
Exemplo n.º 6
0
 def __init__(self):
   self.lib = lib.Lib()
   self.moviedb = Moviedb()
Exemplo n.º 7
0
 def __init__(self):
     self.userdb = Userdb()
     self.lib = lib.Lib()
Exemplo n.º 8
0
 def __init__(self):
     self.lib = lib.Lib()
     self.seriesdb = Seriesdb()
Exemplo n.º 9
0
    def reservate(self,
                  roomId=7,
                  seat_no=41,
                  date=str(datetime.date.today()),
                  start=9,
                  end=22):
        token = self.__token

        library = lib.Lib()
        seats_json = library.free_seats(token, roomId, date, start, end)
        while seats_json == None:
            self.get_token()
            token = self.__token
            seats_json = library.free_seats(token, roomId, date, start, end)
            self.count()

        # 若选中的房间在指定时间段内无可用座位,则结束程序
        if (len(seats_json) == 0):
            print('not available seats in the room selected,finish')
            return False, None

        form = {
            'startTime': int(start * 60),
            'endTime': int(end * 60),
            'seat': 0,
            'date': date,
        }

        headers = {
            'token': token,
            'Host': 'seat.lib.whu.edu.cn:8443',
            'Connection': 'Keep-Alive',
            'Expect': '100-continue',
            'User-Agent':
            'Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-TL00 Build/HUAWEINXT-TL00) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
            'Content-Tyep': 'application/x-www-form-urlencoded;charset=UTF-8',
        }

        minus = 9999
        s_id = ''
        for i in seats_json:
            seat = seats_json.get(i)
            seat_id = seat['id']
            seat_name = seat['name']
            s = abs(int(seat_name) - int(seat_no))
            if s < minus:
                minus = s
                s_id = seat_id
            if int(seat_name) > int(seat_no):
                break

        form['seat'] = s_id
        url = 'https://seat.lib.whu.edu.cn:8443/rest/v2/freeBook'
        try:
            result = requests.post(url, data=form, headers=headers)
        except requests.Timeout:
            self.count()
            self.get_token()
            print('time out when reservating {}'.format(self.__count))
            self.reservate(self, roomId, seat_no, date, start, end)
        except requests.RequestException:
            print('error when reservating:', requests.RequestException)
        if result.status_code == 200:
            status = result.json().get('status')
            if status == 'success':
                location = result.json().get('data').get('location')
                q, qq, qqq, loc, begin, end = self.reservation()
                print(self.__username, ' 预约成功:', location, begin + '--' + end)
                if self.__mail != None:
                    util.Util.sendMail(self.__mail,
                                       location + ',时间' + begin + ' -- ' + end)
                return True, location
            else:
                print(self.__username, '预约失败:', result.json().get('message'))
                return False, None
        else:
            print('reservation_err:', result.status_code)
            self.get_token()

        return False, None
Exemplo n.º 10
0
 def __init__(self):
     self.categorydb = Categorydb()
     self.lib = lib.Lib()
Exemplo n.º 11
0
def test_load():
    library = lib.Lib()
    library.load_defs()