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.
180 lines
4.3 KiB
180 lines
4.3 KiB
|
4 years ago
|
import { hasPath, pathOr, props, last } from 'ramda';
|
||
|
|
import { do_request } from './facebook-request.mjs';
|
||
|
|
const sleep = (s) => new Promise((res) => setTimeout(res, s * 1000));
|
||
|
|
|
||
|
|
const doPageEventsTabPastEventsCardRendererQuery = async ({ pageID }) => {
|
||
|
|
const doc_id = '4421910857857782';
|
||
|
|
const renderer_query_result = await do_request(doc_id, { pageID });
|
||
|
|
const page = pathOr(
|
||
|
|
null,
|
||
|
|
['data', 'page', 'past_events'],
|
||
|
|
renderer_query_result
|
||
|
|
);
|
||
|
|
|
||
|
|
if (page === null) {
|
||
|
|
console.error('doPageEventsTabPastEventsCardRendererQuery returned null.');
|
||
|
|
}
|
||
|
|
|
||
|
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
|
const doPageEventsTabUpcomingEventsCardRendererQuery = async ({ pageID }) => {
|
||
|
|
const doc_id = '5182274978466320';
|
||
|
|
const renderer_query_result = await do_request(doc_id, { pageID });
|
||
|
|
const page = pathOr(
|
||
|
|
null,
|
||
|
|
['data', 'page', 'upcoming_events'],
|
||
|
|
renderer_query_result
|
||
|
|
);
|
||
|
|
|
||
|
|
if (page === null) {
|
||
|
|
console.error(
|
||
|
|
'doPageEventsTabUpcomingEventsCardRendererQuery returned null.'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
|
const doPageEventsTabPastEventsCardPaginationQuery = async ({
|
||
|
|
pageID,
|
||
|
|
cursor
|
||
|
|
}) => {
|
||
|
|
const doc_id = '6953034388071359';
|
||
|
|
let count = 9;
|
||
|
|
const renderer_query_result = await do_request(doc_id, {
|
||
|
|
pageID,
|
||
|
|
cursor,
|
||
|
|
count
|
||
|
|
});
|
||
|
|
const page = pathOr(
|
||
|
|
null,
|
||
|
|
['data', 'page', 'past_events'],
|
||
|
|
renderer_query_result
|
||
|
|
);
|
||
|
|
|
||
|
|
if (page === null) {
|
||
|
|
console.error(
|
||
|
|
'doPageEventsTabPastEventsCardPaginationQuery returned null.'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
|
const doPageEventsTabUpcomingEventsCardPaginationQuery = async ({
|
||
|
|
pageID,
|
||
|
|
cursor
|
||
|
|
}) => {
|
||
|
|
const doc_id = '6985622308176123';
|
||
|
|
let count = 9;
|
||
|
|
const renderer_query_result = await do_request(doc_id, {
|
||
|
|
pageID,
|
||
|
|
cursor,
|
||
|
|
count
|
||
|
|
});
|
||
|
|
const page = pathOr(
|
||
|
|
null,
|
||
|
|
['data', 'page', 'upcoming_events'],
|
||
|
|
renderer_query_result
|
||
|
|
);
|
||
|
|
|
||
|
|
if (page === null) {
|
||
|
|
console.error(
|
||
|
|
'doPageEventsTabUpcomingEventsCardPaginationQuery returned null.'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
|
// doPageEventsTabPastEventsCardPaginationQuery
|
||
|
|
const get_page_events = async ({
|
||
|
|
pageID,
|
||
|
|
get_past_events,
|
||
|
|
get_upcoming_events
|
||
|
|
}) => {
|
||
|
|
let past_events = [];
|
||
|
|
|
||
|
|
if (get_past_events) {
|
||
|
|
const result = await doPageEventsTabPastEventsCardRendererQuery({ pageID });
|
||
|
|
|
||
|
|
if (result !== null) {
|
||
|
|
let { has_next_page, end_cursor: cursor } = result.page_info;
|
||
|
|
|
||
|
|
let { edges } = result;
|
||
|
|
while (has_next_page) {
|
||
|
|
sleep(2);
|
||
|
|
const paginationResult =
|
||
|
|
await doPageEventsTabPastEventsCardPaginationQuery({
|
||
|
|
cursor,
|
||
|
|
pageID
|
||
|
|
});
|
||
|
|
if (paginationResult === null) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
edges = [...edges, ...paginationResult.edges];
|
||
|
|
has_next_page = paginationResult.page_info.has_next_page;
|
||
|
|
cursor = paginationResult.page_info.end_cursor;
|
||
|
|
}
|
||
|
|
past_events = [...edges];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let upcoming_events = [];
|
||
|
|
|
||
|
|
if (get_upcoming_events) {
|
||
|
|
const result = await doPageEventsTabUpcomingEventsCardRendererQuery({
|
||
|
|
pageID
|
||
|
|
});
|
||
|
|
if (result !== null) {
|
||
|
|
upcoming_events = [];
|
||
|
|
let { has_next_page, end_cursor: cursor } = result.page_info;
|
||
|
|
let { edges } = result;
|
||
|
|
while (has_next_page) {
|
||
|
|
sleep(2);
|
||
|
|
const paginationResult =
|
||
|
|
await doPageEventsTabUpcomingEventsCardPaginationQuery({
|
||
|
|
cursor,
|
||
|
|
pageID
|
||
|
|
});
|
||
|
|
if (paginationResult === null) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
edges = [...edges, ...paginationResult.edges];
|
||
|
|
|
||
|
|
has_next_page = paginationResult.page_info.has_next_page;
|
||
|
|
cursor = paginationResult.page_info.end_cursor;
|
||
|
|
}
|
||
|
|
upcoming_events = [...edges];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return [...upcoming_events, ...past_events].map(({ node }) => node);
|
||
|
|
};
|
||
|
|
|
||
|
|
/// const events = {
|
||
|
|
/// edges: [
|
||
|
|
/// {
|
||
|
|
/// node: {
|
||
|
|
/// __typename: "Event",
|
||
|
|
/// },
|
||
|
|
/// cursor:
|
||
|
|
/// "AQHRC7ZNKEqDS75jWJfLUWromnLVgAOGzVAZE7c7CcKfoEaLCcXFSvhMvoxN8yk_Yq6fFMTWjuHjitD5sE1IzW68sw",
|
||
|
|
/// },
|
||
|
|
/// ],
|
||
|
|
/// page_info: {
|
||
|
|
/// has_next_page: true,
|
||
|
|
/// end_cursor:
|
||
|
|
/// "AQHRAh7tKZowf3mdyxtYISP1LNVo45rFI8HJ4nT5SuVgl0NBUfZFslx5qy1eba3YXhdjJ-S2vfojcTGF4ygnt_DQiQ",
|
||
|
|
/// },
|
||
|
|
/// };
|
||
|
|
|
||
|
|
(async () => {
|
||
|
|
const res = await get_page_events({
|
||
|
|
pageID: '149127815110411',
|
||
|
|
get_upcoming_events: true
|
||
|
|
});
|
||
|
|
console.log(res);
|
||
|
|
})();
|