示例#1
0
 def request_url(self, _url, proxy):
     proxy_meta = ''
     proxies = ''
     if proxy: proxy_meta, proxies = self.get_proxy_meta(proxy)
     try:
         s = requests.session()
         s.keep_alive = False
         req = requests.get(url=_url,
                            headers=headers,
                            proxies=proxies,
                            timeout=5)
         req.encoding = 'utf-8'
         if req.status_code == 200:
             html = req.text
             com_html = etree.HTML(html)
             read_count = com_html.xpath('//span[@class="read-count"]')
             print(proxy_meta, read_count[0].text)
         else:
             print("请求无响应:")
     except Exception as e:
         self.remove_port(proxy)
         dom = _url.split('//')[1].split('.net')[0]
         print("ip不可用__%s__>>" % dom, proxy_meta, e)
         save_log("ip不可用__%s__>>" % dom, proxy_meta, e)
     finally:
         self.wait_time(2)
示例#2
0
文件: remote.py 项目: Nozdi/gitraffe
def push(window, additional_args=None):
    child = pexpect.spawn('git push')
    try:
        child.expect("Username*", timeout=2)
        dialog = AuthorizationWrapper(window)
        dialog.exec_()
        child.sendline(dialog.username)
        child.expect("Password*", timeout=2)
        child.sendline(dialog.password)
        child.expect(pexpect.EOF)
        info = child.before
    except (pexpect.TIMEOUT, pexpect.EOF):
        try:
            child.expect("Password*", timeout=2)
            dialog = AuthorizationWrapper(window)
            dialog.ui.Username_lineEdit.setText("Not needed")
            dialog.ui.Username_lineEdit.setReadOnly(True)
            dialog.exec_()
            child.sendline(dialog.password)
            child.expect(pexpect.EOF)
            info = child.before
        except (pexpect.TIMEOUT, pexpect.EOF):
            if get_url().startswith('https://'):
                info = 'Timeout error!'
            else:
                info = getoutput('git push')
    save_log('git push', info)
    return info
示例#3
0
def get_commits():
    command = 'git log --graph --pretty=format:"%h\n%s\n%an\n%ad"'
    output = getoutput_lines(command)
    save_log(command, output[0])
    commits = []
    i = 0
    commit = []
    for line in output[1]:
        j = 0
        for char in line:
            if char == '*' or char == '|' or char == '\\' or char == '/' or char == '_' or char == ' ':
                j += 1
            else:
                break
        commit.append(line[j:])
        i += 1
        if i == 4:
            i = 0
            commits.append(commit)
            commit = []
    i = 0
    while i < len(commits):
        command = 'git branch -r --contains ' + commits[i][0]
        output = getoutput(command)
        if output != '':
            break
        commits[i][1] = '[not pushed] ' + commits[i][1]
        i += 1
    return commits
示例#4
0
def get_current_branch():
    command = 'git branch'
    output = getoutput_lines(command)
    save_log(command, output[0])
    for line in output[1]:
        if '*' in line:
            return line[2:]
示例#5
0
 def http(self, _url, _proxyHttp, _proxyHost, _proxyPort):
     proxy_meta = "%(http)s://%(host)s:%(port)s" % {
         "http": _proxyHttp,
         "host": _proxyHost,
         "port": _proxyPort
     }
     proxies = {
         "http": proxy_meta,
         "https": proxy_meta,
     }
     try:
         # print(self.proxies)
         # requests.adapters.DEFAULT_RETRIES = 3
         req = requests.get(url=_url,
                            headers=headers,
                            proxies=proxies,
                            timeout=5)
         req.encoding = 'utf-8'
         if req.status_code == 200:
             html = req.text
             com_html = etree.HTML(html)
             read_count = com_html.xpath('//span[@class="read-count"]')
             if read_count:  # 输出:阅读数
                 print(proxy_meta, read_count[0].text)
         else:
             print("请求无响应:")
     except Exception as e:
         print("ip不可用:", proxy_meta, e)
         save_log("ip不可用:", proxy_meta, e)
     finally:
         time.sleep(1)
示例#6
0
def clone_repository(window, source, destination):
    cloning_timeout = 5
    command = 'git clone %s %s' % (source, destination)
    child = pexpect.spawn(command)
    try:
        child.expect("Username*", timeout=cloning_timeout)
        dialog = AuthorizationWrapper(window)
        dialog.exec_()
        child.sendline(dialog.username)
        child.expect("Password*", timeout=cloning_timeout)
        child.sendline(dialog.password)
        child.expect(pexpect.EOF)
        info = child.before
    except (pexpect.TIMEOUT, pexpect.EOF):
        rm_command = 'rm -rf ' + destination
        system(rm_command)
        try:
            child.expect("Password*", timeout=cloning_timeout)
            dialog = AuthorizationWrapper(window)
            dialog.ui.Username_lineEdit.setText("Not needed")
            dialog.ui.Username_lineEdit.setReadOnly(True)
            dialog.exec_()
            child.sendline(dialog.password)
            child.expect(pexpect.EOF)
            info = child.before
        except (pexpect.TIMEOUT, pexpect.EOF):
            system(rm_command)
            if source.startswith('https://') and '@' in source:
                return (False, 'Timeout error!')
            else:
                info = getoutput(command)
    save_log(command, info)
    return (True, info)
def visit(frame):
	'''
	This function is excuted when a visitor pushes a button.
	It checks whether the frame is enough to detect.
	If the frame is enough, it calls recognition.py and check the visitor is registered.
	If the visitor is recognized by id, it calls log.py to save the log about the visitor.
	Otherwise, it calls log.py to save the log about that Unkown visitor tried to access the place.
	'''
	# Detect face
	# If it cannot detect face, the library would return 0
	visitor_face = len(face_recognition.face_locations(frame))
	
	log_time = datetime.now(pytz.utc).astimezone(LOCAL_TZ).strftime('%Y-%m-%d %H:%M:%S')
	
	if visitor_face == 0:
		print("Cannot detect face. Try again")
	else:
		# Compare to registered faces and visitor's face
		__id = recognition.face_comparison(frame)
		if __id == 0:
			print("Does not register")
			log.save_log("Unkown", "Visitor", frame, 0, log_time, False)
			for n in range(2):
				log.led()
		else:
			print("I see someone id {}!".format(__id))
			log.permission_check(__id, frame, log_time)
示例#8
0
def get_remote_branches():
    command = 'git branch -r'
    output = getoutput_lines(command)
    save_log(command, output[0])
    branches = []
    for line in output[1]:
        branches.append(line[2:].split(' ')[0])
    return branches
示例#9
0
def get_local_branches():
    command = 'git branch'
    output = getoutput_lines(command)
    save_log(command, output[0])
    branches = []
    for line in output[1]:
        branches.append(line[2:])
    return branches
示例#10
0
def get_files(commit):
    command = 'git show --pretty="format:" --name-status ' +  commit
    output = getoutput_lines(command)
    save_log(command, output[0])
    files = []
    for line in output[1][1:]:
        files.append(line.split('\t'))
    return files
示例#11
0
def check_repository(path):
    chdir(path)
    command = 'git rev-parse --git-dir'
    output = getoutput(command)
    save_log(command, output)
    if 'fatal' in output:
        return False
    return True
示例#12
0
def create_branch(window, branch):
    command = 'git checkout -b ' + branch
    save_log(command, getoutput(command))
    url = get_url()
    additional_args = []
    if url.startswith("git@"):
        additional_args.append('origin')
    additional_args.append(branch)
    return push(window, additional_args)
示例#13
0
def scheduled_job_visit():
    '''
    访问博客
    采集频率:1分整倍数,就执行这个函数
    '''
    init_log(_log_path='', _log_name='scheduler.log', _filemode='a')
    save_log("_________visit start_________", now_datetime())
    KuiDaiLi().start()
    save_log("_________visit end_________\n", now_datetime())
示例#14
0
def job_brush_flow():
    '''
    访问博客
    采集频率:1分整倍数,就执行这个函数
    '''
    init_log(_log_path='', _log_name='brush_flow.log', _filemode='a')
    save_log("_________brush start_________", now_datetime())
    mogu = MoGuRequest()
    mogu.start(_type='mogu')
    save_log("_________brush end_________\n", now_datetime())
示例#15
0
def get_settings():
    command_username = '******'
    command_email = 'git config --global user.email'
    settings = []
    output_username = getoutput(command_username)
    output_email = getoutput(command_email)
    save_log(command_username, output_username)
    save_log(command_email, output_email)
    settings.append(output_username)
    settings.append(output_email)
    return settings
示例#16
0
def get_file_changes(base_command, flag, path, commit=None, comparsion=None):
    try:
        out = '<pre>'
        if 'M' in flag:
            if commit:
                command = base_command + '%s:%s %s:%s' % (comparsion, path, commit, path)
            else:
                command = base_command + path
            #print(base_command, flag, path, commit, comparsion)
            output = getoutput_lines(command)
            save_log(command, output[0])
            if not output[1][4:] and 'Binary' in "".join(output[1]): return "Cannot decode this file"
            #print(output[1][2])
            for line in output[1][4:]:
                line = remove_html(line)
                if len(line) > 0:
                    if line[0]=='-':
                        line = '<font color="RED"> %s</font>' % (line)
                    elif line[0]=='+':
                        line = '<font color="GREEN"> %s</font>' % (line)
                    out += line + '\n'
            out += '</pre>'
            return out
        elif 'A' in flag or flag == '??':
            if commit: 
                command = 'git show %s:%s' % (commit, path)
                output = getoutput_lines(command)
                save_log(command, output[0])
            else:
                if isdir(path):
                    save_log('isdir(path)', 'True')
                    return '<pre>This is a directory</pre>'
                output = open(path).read()
                save_log("open(path).read()", output)
                output = [None, output.split("\n")]
            for line in output[1]:
                line = remove_html(line)
                line = '<font color="GREEN"> + %s </font>' % (line)
                out += line + '\n'
            out += '</pre>'
            return out
        elif 'D' in flag:
            command = 'git show %s:%s' % (comparsion, path)
            output = getoutput_lines(command)
            save_log(command, output[0])
            for line in output[1]:
                line = remove_html(line)
                line = '<font color="RED"> - %s </font>' % (line)
                out += line + '\n'
            out += '</pre>'
            return out
    except UnicodeDecodeError:
        return "Cannot decode this file"
示例#17
0
def login():
    bs = webdriver.Chrome()
    bs.maximize_window()
    bs.get("http://localhost/phpwind/")
    results = []
    posts = get_csv('posts.csv')
    for post in posts:
        msg = post_once(bs, post)
        results.append(msg)

    save_log(results)
    sleep(22)
示例#18
0
文件: commit.py 项目: Nozdi/gitraffe
def get_unstaged_files():
    command = 'git status -s'
    output = getoutput_lines(command)
    files = output[1]
    j = 0
    if len(files) > 0 and files[0] != '':
        for i in range(len(files)):
            if files[i-j][0] != ' ' and files[i-j][0] != '?' and files[i-j][0] != 'U':
                del files[i-j]
                j += 1
    save_log(command, output[0])
    return get_splited(output)
示例#19
0
def get_graph():
    command = 'git log --graph --pretty=format:""'
    output = getoutput_lines(command)
    save_log(command, output[0])
    graph_output = output[1]
    graph = []
    graph_log = ''
    i = 0
    graph_commit = []
    graph_commit.append(graph_output[0])
    for i in range(1, len(graph_output)):
        if '*' in graph_output[i]:
            graph.append(graph_commit)
            graph_commit = []
        graph_commit.append(graph_output[i])
    graph.append(graph_commit)
    return graph
示例#20
0
 def get_easy_json(self, _url=easy_url, proxy=''):
     headers['Accept'] = 'application/json; charset=utf-8'
     # 存储代理的列表
     proxy_meta = ''
     proxies = ''
     _url_type = ''
     if proxy: proxy_meta, proxies = self.get_proxy_meta(proxy)
     try:
         req = requests.get(_url,
                            headers=headers,
                            proxies=proxies,
                            timeout=5)
         # print("json>>", req.text)
         if req.status_code == 200:
             if 'amap.com' in _url:
                 _url_type = '高德地图'
                 jsonObj = req.json()
                 if jsonObj.get("data"):
                     name = jsonObj.get('data').get("base").get("name")
                 elif jsonObj.get("poi_list"):
                     name = jsonObj.get("poi_list")[0].get("name")
                 print("json获取成功__%s__>>" % _url_type, proxy_meta, name)
             elif 'baidu' in _url:
                 _url_type = '百度地图'
                 name = req.json().get("result").get("what")
                 print("json获取成功__%s__>>" % _url_type, proxy_meta, name)
             else:  # easy-api
                 _url_type = 'easy-mock'
                 for ips in req.json().get("data"):
                     protocol = 'https'
                     if ips.get("Protocol"): protocol = ips.get("Protocol")
                     self._proxy_list.append(protocol + '#' +
                                             ips.get("IP") + '#' +
                                             str(ips.get("Port")))
         else:
             print("请求无响应:")
     except Exception as e:
         if _url_type:
             print("json解析错误__%s__>>" % _url_type, proxy_meta, e)
             save_log("json解析错误__%s__>>:" % _url_type, proxy_meta, e)
         else:
             dom = _url.split('//')[1].split('.com')[0]
             print("ip不可用__%s__>>" % dom, proxy_meta, e)
     finally:
         self.wait_time(2)
示例#21
0
文件: commit.py 项目: Nozdi/gitraffe
def clean(file):
    command = 'git clean -f ' + file
    output = getoutput(command)
    save_log(command, output)
示例#22
0
文件: commit.py 项目: Nozdi/gitraffe
def commit_amend(message):
    command = 'git commit --amend -m "%s"' % message
    output = getoutput(command)
    save_log(command, output)
    return output
示例#23
0
def diff(filename):
    command = 'git diff ' + filename
    output = getoutput(command)
    save_log(command, output)
    return output
示例#24
0
文件: commit.py 项目: Nozdi/gitraffe
def to_string(files, command):
    strfiles = " ".join(files)
    command += strfiles
    output = getoutput(command)
    save_log(command, output)
示例#25
0
文件: commit.py 项目: Nozdi/gitraffe
def git_add(file):
    command = 'git add ' + file
    output = getoutput(command)
    save_log(command, output)
示例#26
0
def change_remote_branch(branch, new_name):
    command = 'git checkout -b %s %s' % (new_name, branch)
    output = getoutput(command)
    save_log(command, output)
    return output
示例#27
0
文件: stash.py 项目: Nozdi/gitraffe
def stash():
    command = 'git stash'
    output = getoutput(command)
    save_log(command, output)
    return output
示例#28
0
文件: stash.py 项目: Nozdi/gitraffe
def stashes_list():
    command = 'git stash list'
    output = getoutput_lines(command)
    save_log(command, output[0])
    return output[1]
示例#29
0
文件: stash.py 项目: Nozdi/gitraffe
def drop_stash(stash):
    command = 'git stash drop ' + stash
    output = getoutput(command)
    save_log(command, output)
    return output
示例#30
0
文件: stash.py 项目: Nozdi/gitraffe
def apply_stash(stash):
    command = 'git stash apply ' + stash 
    save_log(command, getoutput(command))
示例#31
0
文件: remote.py 项目: Nozdi/gitraffe
def get_url():
    command = "git config --get remote.origin.url"
    output = getoutput(command)
    save_log(command, output)
    return output
示例#32
0
文件: commit.py 项目: Nozdi/gitraffe
def git_check_out(file):
    command = 'git checkout -- ' + file
    output = getoutput(command)
    save_log(command, output)
示例#33
0
def delete_branch(branch):
    command = 'git branch -d ' + branch
    output = getoutput(command)
    save_log(command, output)
    return output
示例#34
0
文件: commit.py 项目: Nozdi/gitraffe
def git_rm(file):
    command = 'git rm ' + file
    output = getoutput(command)
    save_log(command, output)
示例#35
0
文件: commit.py 项目: Nozdi/gitraffe
def get_staged_files():
    command = 'git diff --name-status --cached'
    output = getoutput_lines(command)
    save_log(command, output[0])
    return get_splited(output)
示例#36
0
def change_local_branch(branch):
    command = 'git checkout ' + branch
    save_log(command, getoutput(command))
示例#37
0
def cherry_pick(window, branch, commit):
    change_branch(branch)
    command = 'git cherry-pick ' + commit
    output = getoutput(command)
    save_log(command, output)
    return output