-
Notifications
You must be signed in to change notification settings - Fork 18
update kobo job code example #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,43 +113,46 @@ With this OpenFn job snippet we fetch submission data from a list of surveys, | |
| indicated by their IDs. | ||
|
|
||
| ```js | ||
| cursor($.lastEnd || $.manualCursor || '2020-11-20T14:32:43.325+01:00'); | ||
|
|
||
| // Update lastEnd to now | ||
mtuchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cursor('now', { | ||
| key: 'lastEnd', | ||
| format: c => dateFns(c, 'YYYY-MM-DD:HH:mm:ss'), | ||
| }); | ||
|
|
||
| fn(state => { | ||
| console.log('Current cursor value:', state.lastEnd); | ||
| console.log('Current cursor value:', state.cursor); | ||
| // Set a manual cursor if you'd like to only fetch data after this date. | ||
mtuchi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const manualCursor = '2020-11-20T14:32:43.325+01:00'; | ||
| state.data = { | ||
| surveys: [ | ||
| //** Specify new forms to fetch here **// | ||
| { | ||
| id: 'aVdh90L9979L945lb02', | ||
| name: 'Initial Data Collection', | ||
| }, | ||
| { | ||
| id: 'bkgIF96fK7v9n7Hfj2', | ||
| name: 'Follow-up', | ||
| }, | ||
| ].map(survey => ({ | ||
| formId: survey.id, | ||
| name: survey.name, | ||
| url: `https://kf.kobotoolbox.org/api/v2/assets/${survey.id}/data/?format=json`, | ||
| query: `&query={"end":{"$gte":"${state.lastEnd || manualCursor}"}}`, | ||
| })), | ||
| }; | ||
| state.surveys = [ | ||
| //** Specify new forms to fetch here **// | ||
| { | ||
| formId: 'aVdh90L9979L945lb02', | ||
| name: 'Initial Data Collection', | ||
| }, | ||
| { | ||
| formId: 'bkgIF96fK7v9n7Hfj2', | ||
| name: 'Follow-up', | ||
| }, | ||
| ]; | ||
| return state; | ||
| }); | ||
|
|
||
| each(dataPath('surveys[*]'), state => { | ||
| const { url, query, formId, name } = state.data; | ||
| return get(`${url}${query}`, {}, state => { | ||
| state.data.submissions = state.data.results.map((submission, i) => { | ||
| return { | ||
| i, | ||
| // Here we append the names defined above to the Kobo form submission data | ||
| formName: name, | ||
| }; | ||
| }); | ||
| }); | ||
| }); | ||
| each( | ||
| $.surveys, | ||
| getSubmissions($.data.formId, { | ||
| query: { end: { $gte: `${$.cursor}` } }, | ||
| }).then(state => { | ||
| const { name, formId } = state.references.at(-1); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a comment here explaining this line. Like I also wish we had an easier answer to this. After the each it's always super hard to chain functionality based on the item under iteration. I guess this works but I wish we ad something more elegant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I totally agree, every time i write that code my eyes squint a little and i get ptsd from my previous job writing training having to explain why |
||
|
|
||
| state.submissions[formId] = { | ||
| name, | ||
| submissions: state.data, | ||
| }; | ||
|
|
||
| return state; | ||
| }) | ||
| ); | ||
| ``` | ||
|
|
||
| Check out some of our | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.