-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
146 lines (134 loc) · 5.9 KB
/
Copy pathexample.js
File metadata and controls
146 lines (134 loc) · 5.9 KB
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
import {
getAuthorData,
getAuthorFilters,
getRecommendedAuthors,
getPromoPoems,
getWeeklyRatedAuthors,
getActiveAuthors,
getPoemById
} from './index.js';
const AUTHOR_IDENTIFIER = 'oreh-orehov';
const POEM_ID_TO_FETCH = 317868;
const PAGE_TO_FETCH = 1;
const REQUEST_DELAY_MS = 500;
async function runAllExamples() {
console.log("=============================================");
console.log(" StihiRus Reader Examples ");
console.log("=============================================");
console.log(`\n--- 1. Fetching Author Data for: ${AUTHOR_IDENTIFIER} (Page: ${PAGE_TO_FETCH}) ---`);
try {
const response = await getAuthorData(AUTHOR_IDENTIFIER, PAGE_TO_FETCH, REQUEST_DELAY_MS);
if (response.status === 'success') {
console.log("Status: success");
console.log("Author Data:", JSON.stringify(response.data, null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getAuthorData):", error);
}
console.log(`\n--- 2. Fetching Filtered Author Data for: ${AUTHOR_IDENTIFIER} (Rubric ID: 5) ---`);
try {
const filterOptions = { rubricId: 5 };
const response = await getAuthorData(AUTHOR_IDENTIFIER, null, REQUEST_DELAY_MS, filterOptions);
if (response.status === 'success') {
console.log("Status: success");
console.log(`Filtered Poems Count: ${response.data.poems.length}`);
if (response.data.poems.length > 0) {
console.log("First Filtered Poem:", JSON.stringify(response.data.poems[0], null, 2));
}
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getAuthorData - Filtered):", error);
}
console.log(`\n--- 3. Fetching Filters for: ${AUTHOR_IDENTIFIER} ---`);
try {
const response = await getAuthorFilters(AUTHOR_IDENTIFIER);
if (response.status === 'success') {
console.log("Status: success");
console.log("Filters Data:", JSON.stringify(response.data, null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getAuthorFilters):", error);
}
console.log(`\n--- 4. Fetching Recommended Authors ---`);
try {
const response = await getRecommendedAuthors();
if (response.status === 'success') {
console.log("Status: success");
console.log(`Found ${response.data.length} recommended authors.`);
console.log("Recommended Authors (first 5):", JSON.stringify(response.data.slice(0, 5), null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getRecommendedAuthors):", error);
}
console.log(`\n--- 5. Fetching Promo Poems ---`);
try {
const response = await getPromoPoems();
if (response.status === 'success') {
console.log("Status: success");
console.log(`Found ${response.data.length} promo poems.`);
console.log("Promo Poems (first 5):", JSON.stringify(response.data.slice(0, 5), null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getPromoPoems):", error);
}
console.log(`\n--- 6. Fetching Weekly Rated Authors ---`);
try {
const response = await getWeeklyRatedAuthors();
if (response.status === 'success') {
console.log("Status: success");
console.log(`Found ${response.data.length} weekly rated authors.`);
console.log("Weekly Rated Authors (first 5):", JSON.stringify(response.data.slice(0, 5), null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getWeeklyRatedAuthors):", error);
}
console.log(`\n--- 7. Fetching Active Authors ---`);
try {
const response = await getActiveAuthors();
if (response.status === 'success') {
console.log("Status: success");
console.log(`Found ${response.data.length} active authors.`);
console.log("Active Authors (first 5):", JSON.stringify(response.data.slice(0, 5), null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getActiveAuthors):", error);
}
console.log(`\n--- 8. Fetching Poem By ID: ${POEM_ID_TO_FETCH} ---`);
try {
const response = await getPoemById(POEM_ID_TO_FETCH);
if (response.status === 'success') {
console.log("Status: success");
console.log("Poem Data:", JSON.stringify(response.data, null, 2));
} else {
console.error("Status: error");
console.error("Error:", JSON.stringify(response.error, null, 2));
}
} catch (error) {
console.error("!!! UNEXPECTED SCRIPT ERROR (getPoemById):", error);
}
console.log("\n=============================================");
console.log(" Examples Finished ");
console.log("=============================================");
}
runAllExamples();