125 lines
3.7 KiB
Python
125 lines
3.7 KiB
Python
import re
|
|
import jwt
|
|
import time
|
|
import json
|
|
import requests
|
|
|
|
from scholarly import scholarly
|
|
from scholarly import ProxyGenerator
|
|
|
|
# Aminer secret key
|
|
secret_key = "KJlS8eT9y9Gc1w=="
|
|
user_id = "650c31aa078ed986b5d526cc"
|
|
expire_time = int(time.time()) + 60 # Expire in 1 min
|
|
now_time = int(time.time())
|
|
|
|
# Aminer JWT token generator
|
|
head = {
|
|
"alg": "HS256",
|
|
"sign_type": "SIGN"
|
|
}
|
|
payload = {
|
|
"user_id": user_id,
|
|
"exp": expire_time,
|
|
"timestamp": now_time
|
|
}
|
|
jwt_token = jwt.encode(payload, secret_key, algorithm="HS256", headers=head)
|
|
|
|
# Aminer API
|
|
api_paper_id = "https://datacenter.aminer.cn/gateway/open_platform/api/v3/paper/list/by/publish"
|
|
api_paper_detail = "https://datacenter.aminer.cn/gateway/open_platform/api/v3/paper/detail/list"
|
|
api_author_id = "https://datacenter.aminer.cn/gateway/open_platform/api/v2/person/search"
|
|
|
|
|
|
def aminer_get_paper_id(title):
|
|
headers = {
|
|
"Authorization": f"Bearer {jwt_token}"
|
|
}
|
|
params = {
|
|
"page": "",
|
|
"size": "",
|
|
"title": re.sub(r'[^a-zA-Z0-9\s]+', ' ', title).strip()
|
|
}
|
|
response = requests.get(api_paper_id, headers=headers, params=params)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if data.get("success") and data['data'] is not None:
|
|
aminer_paper_id.append(data['data'][0]['id'])
|
|
else:
|
|
not_on_aminer.append(title)
|
|
|
|
|
|
def aminer_post_paper_citation(aminer_id):
|
|
headers = {
|
|
"Content-Type": "application/json;charset=utf-8",
|
|
"Authorization": f"Bearer {jwt_token}"
|
|
}
|
|
request_data = {
|
|
"ids": aminer_id
|
|
}
|
|
response = requests.post(api_paper_detail, headers=headers, data=json.dumps(request_data))
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if data.get("success"):
|
|
for item in data.get('data', []):
|
|
if 'n_citation' in item:
|
|
n_citation = item['n_citation']
|
|
else:
|
|
n_citation = 0
|
|
aminer_paper_citation.append(n_citation)
|
|
else:
|
|
aminer_paper_citation_retry.append(aminer_id)
|
|
|
|
|
|
def aminer_author_info(author_aminer_id, author_name, offset):
|
|
headers = {
|
|
"Content-Type": "application/json;charset=utf-8",
|
|
"Authorization": f"Bearer {jwt_token}"
|
|
}
|
|
request_data = {
|
|
"ids": author_aminer_id,
|
|
"query": author_name,
|
|
"offset": offset
|
|
}
|
|
response = requests.post(api_paper_detail, headers=headers, data=json.dumps(request_data))
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if data.get("success"):
|
|
for item in data.get('data', []):
|
|
if 'n_citation' in item:
|
|
n_citation = item['n_citation']
|
|
else:
|
|
n_citation = 0
|
|
aminer_paper_citation.append(n_citation)
|
|
else:
|
|
aminer_paper_citation_retry.append(author_aminer_id)
|
|
|
|
|
|
def scholarly_get_citation(title):
|
|
# # Set up a ProxyGenerator object to use free proxies. This needs to be done only once per session
|
|
pg = ProxyGenerator()
|
|
pg.FreeProxies()
|
|
scholarly.use_proxy(pg)
|
|
|
|
# Now search Google Scholar from behind a proxy
|
|
search_query = scholarly.search_pubs(title)
|
|
try:
|
|
scholarly.pprint(next(search_query, None))
|
|
except StopIteration:
|
|
return None
|
|
|
|
|
|
not_on_aminer = []
|
|
aminer_paper_id = []
|
|
aminer_paper_citation = []
|
|
aminer_paper_citation_retry = []
|
|
|
|
# scholarly_get_citation("Traveling waves for unbalanced bistable equations with density dependent diffusion")
|
|
aminer_get_paper_id("Heat kernel estimates for fourth-order non-uniformly elliptic operators with non-strongly convex symbols")
|
|
if aminer_paper_id:
|
|
aminer_post_paper_citation(aminer_paper_id)
|
|
print(aminer_paper_citation)
|