File size: 6,633 Bytes
3c6b551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env python3
"""
Crossref API 调试脚本
逐步测试不同的参数组合来找出问题
"""

import requests
import json

def test_basic_search():
    """测试最基本的搜索"""
    url = "https://api.crossref.org/works"
    
    headers = {
        'User-Agent': 'Academic-Reviewer-System/1.0 (mailto:[email protected])'
    }
    
    # 最基本的参数
    params = {
        "query": "machine learning",
        "rows": 3
    }
    
    print("=== 测试1: 基本搜索 ===")
    print(f"URL: {url}")
    print(f"参数: {params}")
    print("-" * 50)
    
    try:
        response = requests.get(url, params=params, headers=headers, timeout=30)
        print(f"状态码: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            items = data.get("message", {}).get("items", [])
            print(f"成功! 返回 {len(items)} 个结果")
            
            for i, item in enumerate(items, 1):
                title = item.get('title', ['N/A'])[0] if item.get('title') else 'N/A'
                print(f"{i}. {title}")
            
            return True
        else:
            print(f"失败: {response.text}")
            return False
            
    except Exception as e:
        print(f"异常: {str(e)}")
        return False

def test_with_sort():
    """测试添加排序参数"""
    url = "https://api.crossref.org/works"
    
    headers = {
        'User-Agent': 'Academic-Reviewer-System/1.0 (mailto:[email protected])'
    }
    
    # 添加排序参数
    params = {
        "query": "machine learning",
        "rows": 3,
        "sort": "published",
        "order": "desc"
    }
    
    print("\n=== 测试2: 添加排序参数 ===")
    print(f"参数: {params}")
    print("-" * 50)
    
    try:
        response = requests.get(url, params=params, headers=headers, timeout=30)
        print(f"状态码: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            items = data.get("message", {}).get("items", [])
            print(f"成功! 返回 {len(items)} 个结果")
            return True
        else:
            print(f"失败: {response.text}")
            return False
            
    except Exception as e:
        print(f"异常: {str(e)}")
        return False

def test_with_select():
    """测试添加select参数"""
    url = "https://api.crossref.org/works"
    
    headers = {
        'User-Agent': 'Academic-Reviewer-System/1.0 (mailto:[email protected])'
    }
    
    # 添加select参数
    params = {
        "query": "machine learning",
        "rows": 3,
        "select": "DOI,title,author"
    }
    
    print("\n=== 测试3: 添加select参数 ===")
    print(f"参数: {params}")
    print("-" * 50)
    
    try:
        response = requests.get(url, params=params, headers=headers, timeout=30)
        print(f"状态码: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            items = data.get("message", {}).get("items", [])
            print(f"成功! 返回 {len(items)} 个结果")
            return True
        else:
            print(f"失败: {response.text}")
            return False
            
    except Exception as e:
        print(f"异常: {str(e)}")
        return False

def test_cited_count_sort():
    """测试按引用量排序"""
    url = "https://api.crossref.org/works"
    
    headers = {
        'User-Agent': 'Academic-Reviewer-System/1.0 (mailto:[email protected])'
    }
    
    # 测试不同的排序选项
    sort_options = ["published", "relevance", "deposited"]
    
    for sort_option in sort_options:
        params = {
            "query": "machine learning",
            "rows": 3,
            "sort": sort_option,
            "order": "desc"
        }
        
        print(f"\n=== 测试4: 排序选项 '{sort_option}' ===")
        print(f"参数: {params}")
        print("-" * 50)
        
        try:
            response = requests.get(url, params=params, headers=headers, timeout=30)
            print(f"状态码: {response.status_code}")
            
            if response.status_code == 200:
                data = response.json()
                items = data.get("message", {}).get("items", [])
                print(f"成功! 返回 {len(items)} 个结果")
                
                # 显示引用量信息
                for i, item in enumerate(items, 1):
                    title = item.get('title', ['N/A'])[0] if item.get('title') else 'N/A'
                    cited_count = item.get('is-referenced-by-count', 0)
                    print(f"{i}. {title} (被引用: {cited_count})")
                
            else:
                print(f"失败: {response.text}")
                
        except Exception as e:
            print(f"异常: {str(e)}")

def test_full_params():
    """测试完整参数"""
    url = "https://api.crossref.org/works"
    
    headers = {
        'User-Agent': 'Academic-Reviewer-System/1.0 (mailto:[email protected])'
    }
    
    # 完整的参数
    params = {
        "query": "machine learning",
        "rows": 3,
        "sort": "published",
        "order": "desc",
        "select": "DOI,title,author,container-title,published-print,published-online,is-referenced-by-count"
    }
    
    print(f"\n=== 测试5: 完整参数 ===")
    print(f"参数: {params}")
    print("-" * 50)
    
    try:
        response = requests.get(url, params=params, headers=headers, timeout=30)
        print(f"状态码: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            items = data.get("message", {}).get("items", [])
            print(f"成功! 返回 {len(items)} 个结果")
            
            for i, item in enumerate(items, 1):
                title = item.get('title', ['N/A'])[0] if item.get('title') else 'N/A'
                cited_count = item.get('is-referenced-by-count', 0)
                print(f"{i}. {title} (被引用: {cited_count})")
            
            return True
        else:
            print(f"失败: {response.text}")
            return False
            
    except Exception as e:
        print(f"异常: {str(e)}")
        return False

if __name__ == "__main__":
    print("Crossref API 调试测试")
    print("=" * 60)
    
    # 逐步测试
    test_basic_search()
    test_with_sort()
    test_with_select()
    test_cited_count_sort()
    test_full_params()
    
    print("\n" + "=" * 60)
    print("调试完成")