|
@@ -16,10 +16,7 @@ JSON_ACCOUNT_RECORD = (ROOT_PATH / 'config/account_record.json').resolve()
|
|
|
|
|
|
def account_record(uid, crawl_type):
|
|
def account_record(uid, crawl_type):
|
|
with open(JSON_ACCOUNT_RECORD, 'w+', encoding='utf-8') as wp:
|
|
with open(JSON_ACCOUNT_RECORD, 'w+', encoding='utf-8') as wp:
|
|
- item = {
|
|
|
|
- "uid": uid,
|
|
|
|
- "crawl_type": crawl_type
|
|
|
|
- }
|
|
|
|
|
|
+ item = {"uid": uid, "crawl_type": crawl_type}
|
|
wp.write(json.dumps(item, indent=4))
|
|
wp.write(json.dumps(item, indent=4))
|
|
|
|
|
|
|
|
|
|
@@ -34,15 +31,9 @@ def read_account():
|
|
|
|
|
|
def get_account(site, crawl_type):
|
|
def get_account(site, crawl_type):
|
|
url = "http://cc.spdata.jianyu360.com/competing_goods/account/fetch"
|
|
url = "http://cc.spdata.jianyu360.com/competing_goods/account/fetch"
|
|
- params = {
|
|
|
|
- "site": site,
|
|
|
|
- "crawl_type": crawl_type
|
|
|
|
- }
|
|
|
|
|
|
+ params = {"site": site, "crawl_type": crawl_type}
|
|
try:
|
|
try:
|
|
- response = requests.get(url,
|
|
|
|
- headers=_headers,
|
|
|
|
- params=params,
|
|
|
|
- timeout=60)
|
|
|
|
|
|
+ response = requests.get(url, headers=_headers, params=params, timeout=60)
|
|
data = response.json()['data']
|
|
data = response.json()['data']
|
|
logger.info("当前账号状态:{}".format(data['crawl_detail']))
|
|
logger.info("当前账号状态:{}".format(data['crawl_detail']))
|
|
except requests.RequestException:
|
|
except requests.RequestException:
|
|
@@ -53,24 +44,15 @@ def get_account(site, crawl_type):
|
|
|
|
|
|
|
|
|
|
def release_account(uid, crawl_type, disable_log=False):
|
|
def release_account(uid, crawl_type, disable_log=False):
|
|
-
|
|
|
|
url = "http://cc.spdata.jianyu360.com/competing_goods/account/release"
|
|
url = "http://cc.spdata.jianyu360.com/competing_goods/account/release"
|
|
- if uid is not None:
|
|
|
|
- params = {
|
|
|
|
- "uid": uid,
|
|
|
|
- "crawl_type": crawl_type
|
|
|
|
- }
|
|
|
|
- while True:
|
|
|
|
- try:
|
|
|
|
- response = requests.get(url,
|
|
|
|
- headers=_headers,
|
|
|
|
- params=params,
|
|
|
|
- timeout=60)
|
|
|
|
- if response.status_code == 200:
|
|
|
|
- acc_status = mongo_table('py_spider', 'match_account').find_one({'_id': ObjectId(uid)})['crawl_detail']
|
|
|
|
- if not disable_log:
|
|
|
|
- logger.info(f"release_account >>> {response.json()}, status : {acc_status}")
|
|
|
|
- break
|
|
|
|
- except requests.RequestException:
|
|
|
|
- logger.error("网络异常,归还账号失败")
|
|
|
|
- wait(1)
|
|
|
|
|
|
+ params = {"uid": uid, "crawl_type": crawl_type}
|
|
|
|
+ while True:
|
|
|
|
+ try:
|
|
|
|
+ response = requests.get(url, headers=_headers, params=params, timeout=60)
|
|
|
|
+ response.raise_for_status()
|
|
|
|
+ if not disable_log:
|
|
|
|
+ logger.info(f"release_account >>> {response.json()}")
|
|
|
|
+ break
|
|
|
|
+ except requests.RequestException:
|
|
|
|
+ logger.error("网络异常,归还账号失败")
|
|
|
|
+ wait(1)
|