Ejemplo n.º 1
0
def cli(no_update, ocr, print_cookie, delay, check_delay, number, classtypeid):
    version = __version__
    echo('AutoElect by ' + __author__)
    echo('Version: ' + version)
    echo('Github: ' + __url__ + '\n')

    # TODO: remove in 1.0.0
    if not no_update and check_update():
        cmd = input('Continue without updating?(y/N)')
        if cmd != 'y':
            exit()

    # check argument
    if len(classtypeid) % 3 != 0:
        echoerror('CLASSTYPE and CLASSID should in pair!')
        exit()

    ui = UserInterface()
    if not ui.login(ocr, check_delay):
        exit()
    if print_cookie:
        ui.print_cookie()
    for i in range(0, len(classtypeid), 3):
        ui.add_elect(number, classtypeid[i], classtypeid[i + 1],
                     classtypeid[i + 2], delay)
    ui.start_elect()
    cmd = threading.Thread(target=ui.get_input)
    cmd.daemon = True
    cmd.start()
    while ui.check_alive():
        sleep(0.5)
    echo('')
    echoinfo('All task finished!')
Ejemplo n.º 2
0
    def login(self, ocr, delay):
        """Login user.

        Args:
            ocr: bool, True to use ocr
            delay: int, retry delay

        Returns:
            true for success.
        """
        echoinfo('Login to your JAccount:')
        self.session = login('https://i.sjtu.edu.cn/jaccountlogin', ocr)

        self.studentid = get_studentid(self.session)
        if not self.studentid:
            echoerror('Can\'t find student id!')
            return False

        while 1:
            self.params = get_params(self.session, self.studentid)
            if self.params['njdm_id'] and self.params['zyh_id']:
                break
            echoinfo('Not open, retry in %d seconds...' % delay)
            sleep(delay)

        echoinfo('Login successful!')
        return True
Ejemplo n.º 3
0
 def start_elect(self):
     echoinfo('Starting thread...')
     for i in self.tp:
         i.daemon = True
         i.start()
     echoinfo('Task running! Input "s" to view status.')
Ejemplo n.º 4
0
 def print_cookie(self):
     echoinfo('Your cookie:')
     echo(('; '.join([
         '='.join(item) for item in self.session.cookies.items()
     ])).replace('"', ''))
Ejemplo n.º 5
0
 def fetch_status(self):
     echoinfo('Current status:')
     for i, j in enumerate(self.status):
         self.__parse_status(i, j)
Ejemplo n.º 6
0
 def start_elect(self):
     echoinfo('Starting thread...')
     for i in self.tp:
         i.daemon = True
         i.start()