You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.8 KiB
168 lines
4.8 KiB
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
import httplib, urllib, base64
|
|
import json
|
|
|
|
result=[]
|
|
input = [2251253715, 2180737804]
|
|
encodeinput = json.dumps(input)
|
|
deinput = json.loads(encodeinput)
|
|
exp1 = "Composite(AA.AuId = %d )" % deinput[0]
|
|
params1 = urllib.urlencode({
|
|
'expr':exp1,
|
|
'offset': '0',
|
|
'model': 'latest',
|
|
'count': '10000',
|
|
'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId',
|
|
'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6',
|
|
})
|
|
conn = httplib.HTTPSConnection('oxfordhk.azure-api.net')
|
|
conn.request("GET", "/academic/v1.0/evaluate?%s" % params1)
|
|
response = conn.getresponse()
|
|
data = response.read()
|
|
data1 = json.loads(data)
|
|
conn.close()
|
|
#print data
|
|
|
|
#'''''''''''''''''''''''''2nd API'''''''''''''''''''''''''''''''''
|
|
exp2 = 'Id = %d' % deinput[1]
|
|
params1 = urllib.urlencode({
|
|
'expr':exp2,
|
|
'count': '100000',
|
|
'model': 'latest',
|
|
'attributes': 'F.FId,AA.AuId,AA.AfId,C.CId,J.JId',
|
|
'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6',
|
|
})
|
|
conn = httplib.HTTPSConnection('oxfordhk.azure-api.net')
|
|
conn.request("GET", "/academic/v1.0/evaluate?%s" % params1)
|
|
response = conn.getresponse()
|
|
data = response.read()
|
|
data2 = json.loads(data)
|
|
conn.close()
|
|
#print data2
|
|
|
|
#'''''''''''''''''''''''''3rd API'''''''''''''''''''''''''''''''''
|
|
exp3 = 'RId = %d' % deinput[1]
|
|
params1 = urllib.urlencode({
|
|
'expr':exp3,
|
|
'count': '10000',
|
|
'attributes': 'Id',
|
|
'model': 'latest',
|
|
'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6',
|
|
})
|
|
conn = httplib.HTTPSConnection('oxfordhk.azure-api.net')
|
|
conn.request("GET", "/academic/v1.0/evaluate?%s" % params1)
|
|
response = conn.getresponse()
|
|
data = response.read()
|
|
data3 = json.loads(data)
|
|
conn.close()
|
|
|
|
#'''''''''''''''''''''data 2''''''''''''''''''''''''''''''''
|
|
try:
|
|
FId2 = data2["entities"][0]["F"]
|
|
except (KeyError):
|
|
FId2 = []
|
|
try:
|
|
AuId2= data2["entities"][0]["AA"]
|
|
except (KeyError):
|
|
AuId2=[]
|
|
try:
|
|
CJId2= data2["entities"][0]["J"]["JId"]
|
|
except (KeyError):
|
|
try:
|
|
CJId2= data2["entities"][0]["C"]["CId"]
|
|
except:
|
|
CJId2=[]
|
|
|
|
#'''''''''''''''''''''data 1''''''''''''''''''''''''''''''''
|
|
Id1=[]
|
|
AfId1=[]
|
|
for i1 in data1["entities"]:
|
|
Id1.append(i1["Id"])
|
|
if i1["Id"]==deinput[1]:
|
|
result.append([deinput[0],deinput[1]]) # AA.AuId -> Id
|
|
try:
|
|
FId1 = i1["F"]
|
|
for tmp in FId1:
|
|
for x in FId2:
|
|
if x["FId"]==tmp["FId"]:
|
|
# AA.AuId -> Id -> F.FId -> Id
|
|
result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]])
|
|
except (KeyError):
|
|
pass
|
|
try:
|
|
AuId1= i1["AA"]
|
|
for tmp in AuId1:
|
|
for x in AuId2:
|
|
if tmp["AuId"]==x["AuId"]:
|
|
# AA.AuId -> Id -> AA.AuId -> Id
|
|
result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]])
|
|
except (KeyError):
|
|
pass
|
|
try:
|
|
for tmp in AuId1:
|
|
if tmp["AuId"]==deinput[0]:
|
|
if tmp["AfId"] not in AfId1:
|
|
AfId1.append(tmp["AfId"])
|
|
break
|
|
except(KeyError):
|
|
pass
|
|
try:
|
|
CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id
|
|
if CJId1 == CJId2:
|
|
result.append([deinput[0],i1["Id"],CJId1,deinput[1]])
|
|
except (KeyError):
|
|
try:
|
|
CJId1= i1["C"]["CId"]
|
|
if CJId1 == CJId2:
|
|
result.append([deinput[0],i1["Id"],CJId1,deinput[1]])
|
|
except:
|
|
CJId1=[]
|
|
# AA.AuId -> AA.AfId -> AA.AuId -> Id
|
|
for x in AuId2:
|
|
for y in AfId1:
|
|
try:
|
|
if y==x["AfId"]:
|
|
result.append([deinput[0],y,x["AuId"],deinput[1]])
|
|
except(KeyError):
|
|
continue
|
|
|
|
|
|
#'''''''''''''''''''''data 3''''''''''''''''''''''''''''''''
|
|
Id3 = []
|
|
for i3 in data3["entities"]:
|
|
Id3.append(i3["Id"])
|
|
|
|
#************************************************************need gevent
|
|
#''''''''''''''''''''4th API''''''''''''''''''''''''''''''''''''
|
|
for Aid in Id1:
|
|
exp4 = 'Id = %d' % Aid
|
|
params1 = urllib.urlencode({
|
|
'expr':exp4,
|
|
'count': '100000',
|
|
'attributes': 'RId',
|
|
'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6',
|
|
})
|
|
conn = httplib.HTTPSConnection('oxfordhk.azure-api.net')
|
|
conn.request("GET", "/academic/v1.0/evaluate?%s" % params1)
|
|
response = conn.getresponse()
|
|
data = response.read()
|
|
data4 = json.loads(data)
|
|
conn.close()
|
|
#print data4
|
|
try:
|
|
ReId4= data4["entities"][0]["RId"]
|
|
except (KeyError):
|
|
ReId4 = []
|
|
# AA.AuId -> id -> id # AA.AuId -> id -> id -> id
|
|
for rid in ReId4:
|
|
if deinput[1] == rid:
|
|
result.append([deinput[0],Aid,deinput[1]])
|
|
for tmp in Id3:
|
|
if rid == tmp:
|
|
result.append([deinput[0],Aid,rid,deinput[1]])
|
|
|
|
deresult = json.dumps(result)
|
|
print deresult
|
|
print len(result)
|