init
This commit is contained in:
0
web/utils/__init__.py
Normal file
0
web/utils/__init__.py
Normal file
44
web/utils/fe_sucks.py
Normal file
44
web/utils/fe_sucks.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from nc_http.tools.fe_sucks import FESucks
|
||||
from nc_http.tools.helpers.dict import camelize_dict
|
||||
|
||||
|
||||
class FESucks(FESucks):
|
||||
@classmethod
|
||||
def set_placeholder(cls, data, key, placeholder_name_list, placeholder=None):
|
||||
"""
|
||||
:param data:
|
||||
:param key:
|
||||
:param placeholder_name_list:
|
||||
:param placeholder:
|
||||
:return:
|
||||
[{'a': 1, 'b': 'name_1'}]
|
||||
+
|
||||
['name_1', 'name_2', 'name_3']
|
||||
+
|
||||
{'a': 0}
|
||||
=
|
||||
[{'a': 1, 'b': 'name_1'}, {'a': 0, 'b': 'name_2'}, {'a': 0, 'b': 'name_3'}]
|
||||
"""
|
||||
placeholder = placeholder or {}
|
||||
miss_placeholder_name_list = set(placeholder_name_list) - set(item[key] for item in data)
|
||||
for placeholder_name in miss_placeholder_name_list:
|
||||
_placeholder = placeholder.copy()
|
||||
_placeholder[key] = placeholder_name
|
||||
data.append(_placeholder)
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def camelize(cls, result):
|
||||
"""
|
||||
:param result:
|
||||
:return:
|
||||
"""
|
||||
if isinstance(result, dict):
|
||||
return camelize_dict(result)
|
||||
if isinstance(result, list):
|
||||
_result = []
|
||||
for item in result:
|
||||
_result.append(camelize_dict(item))
|
||||
return _result
|
||||
|
||||
return result
|
63
web/utils/flask_pylint.py
Normal file
63
web/utils/flask_pylint.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
class Pylint:
|
||||
|
||||
def __init__(self, app=None):
|
||||
self._disable = True
|
||||
self.app = None
|
||||
if app is not None:
|
||||
self.init_app(app)
|
||||
|
||||
def init_app(self, app):
|
||||
self.app = app
|
||||
|
||||
# 避免在 flask debug 模式下重复执行
|
||||
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
|
||||
return self
|
||||
|
||||
if 'PYLINT_DISABLE' in app.config:
|
||||
self._disable = app.config.get('PYLINT_DISABLE')
|
||||
else:
|
||||
self._disable = not app.config.get('DEBUG', True)
|
||||
|
||||
if not self._disable:
|
||||
self._prepare_hook()
|
||||
# todo 移入脚本
|
||||
self._check_code()
|
||||
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def _prepare_hook():
|
||||
subprocess.call(['pre-commit', 'install'])
|
||||
|
||||
@staticmethod
|
||||
def _check_code():
|
||||
# 预检查代码风格
|
||||
_, output = subprocess.getstatusoutput('pre-commit run --all-files')
|
||||
# 输出最差评分代码信息
|
||||
output_lines = output.split('\n')
|
||||
for line in output_lines[0:3]:
|
||||
print(line)
|
||||
|
||||
worst_score_info = []
|
||||
current_info = []
|
||||
worst_score = 10
|
||||
for line in output_lines[3:]:
|
||||
current_info.append(line)
|
||||
|
||||
if line.startswith('Your code has been rated at'):
|
||||
score = float(line.split()[6].split('/')[0])
|
||||
if score < worst_score:
|
||||
worst_score = score
|
||||
worst_score_info = tuple(current_info)
|
||||
current_info = []
|
||||
|
||||
for line in worst_score_info:
|
||||
print(line)
|
||||
# 通过检查或无法获取最差分数的场合 直接输出所有信息
|
||||
if not worst_score_info:
|
||||
for line in output_lines[3:]:
|
||||
print(line)
|
97
web/utils/login.py
Normal file
97
web/utils/login.py
Normal file
@@ -0,0 +1,97 @@
|
||||
import time
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
|
||||
HOME_PAGE_URL = 'https://fuzhou.mysteel.com/'
|
||||
USERNSAME = '13960925044'
|
||||
PASSWORD = 'mysteel336627'
|
||||
|
||||
|
||||
def load_element(browser, pattern, time=3600.0):
|
||||
''' 等待元素载入 '''
|
||||
element = WebDriverWait(browser, time).until(expected_conditions.presence_of_element_located((By.XPATH, pattern)))
|
||||
return element
|
||||
|
||||
|
||||
def login_mysteel():
|
||||
options = webdriver.ChromeOptions()
|
||||
browser = webdriver.Remote(
|
||||
command_executor="http://localhost:4444/wd/hub",
|
||||
options=options
|
||||
)
|
||||
|
||||
browser.get(HOME_PAGE_URL)
|
||||
print('Visit {0} ...'.format(HOME_PAGE_URL))
|
||||
print(browser.title)
|
||||
try:
|
||||
# 打开登陆窗口
|
||||
print('Click Login...')
|
||||
time.sleep(1)
|
||||
load_element(browser, '//*[@id="mysteel-topBar"]/div[3]/p').click()
|
||||
time.sleep(1)
|
||||
|
||||
# 填写登陆资料
|
||||
print('Insert data ...')
|
||||
print('username: {0}'.format(USERNSAME))
|
||||
browser.find_elements(By.XPATH, "//div[contains(text(),'账号登录')]")[0].click()
|
||||
time.sleep(2)
|
||||
browser.find_elements(By.XPATH, '/html/body/div/div/div[2]/div[5]/div[1]/input')[0].send_keys(USERNSAME)
|
||||
browser.find_elements(By.XPATH, '/html/body/div/div/div[2]/div[5]/div[3]/input')[0].send_keys(PASSWORD)
|
||||
time.sleep(1)
|
||||
browser.find_elements(By.XPATH, '/html/body/div/div/div[2]/div[6]/div[1]/div[1]')[0].click()
|
||||
time.sleep(5)
|
||||
|
||||
cookies = browser.get_cookies()
|
||||
for i in range(10):
|
||||
if cookies:
|
||||
break
|
||||
else:
|
||||
browser.refresh()
|
||||
time.sleep(5)
|
||||
cookies = browser.get_cookies()
|
||||
|
||||
print(cookies)
|
||||
print([i for i in cookies if i['name'] == '_login_token'])
|
||||
print([i for i in cookies if i['name'] == '_MSPASS_SESSION'])
|
||||
return cookies
|
||||
finally:
|
||||
browser.close()
|
||||
browser.quit()
|
||||
|
||||
|
||||
def login_baiinfo(home_page_url='http://www.baiinfo.com/shiyou/liqing', usernsame='fjglsl', password='111111'):
|
||||
options = webdriver.ChromeOptions()
|
||||
browser = webdriver.Remote(
|
||||
command_executor="http://localhost:4444/wd/hub",
|
||||
options=options
|
||||
)
|
||||
browser.set_window_size(1280, 800)
|
||||
browser.get('http://www.baiinfo.com/login')
|
||||
print('Visit {0} ...'.format(home_page_url))
|
||||
print(browser.title)
|
||||
try:
|
||||
# 填写登陆资料
|
||||
print('Insert data ...')
|
||||
print('username: {0}'.format(usernsame))
|
||||
load_element(browser, '//*[@id="__nuxt"]')
|
||||
print('ddd')
|
||||
time.sleep(2)
|
||||
browser.find_elements(By.XPATH, '//form/div[1]/input')[0].click()
|
||||
browser.find_elements(By.XPATH, '//form/div[1]/input')[0].send_keys(usernsame)
|
||||
browser.find_elements(By.XPATH, '//form/div[2]/input')[0].send_keys(password)
|
||||
time.sleep(3)
|
||||
browser.find_elements(By.XPATH, '//*[@id="__nuxt"]/div/div[5]/div/div[2]/div/div[2]/div[2]/div[2]/form/div[4]/div/img')[0].click()
|
||||
time.sleep(4)
|
||||
cookies = browser.get_cookies()
|
||||
print(cookies)
|
||||
return cookies
|
||||
finally:
|
||||
browser.close()
|
||||
browser.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
login_baiinfo()
|
Reference in New Issue
Block a user