Skip to content
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

Given an IATI (activity) identifier, find the activity (efficiently!) #3

Open
andylolz opened this issue Dec 5, 2018 · 5 comments
Open
Labels
feature Cool stuff I’d like this library to be able to do

Comments

@andylolz
Copy link
Member

andylolz commented Dec 5, 2018

Doing this efficiently means leaning on the rule that all activity IDs must be prefixed by the publisher’s org ID.

E.g.:

import iatikit


activity_id = 'GB-COH-07676886-999999'

activity = iatikit.activities().find(iati_identifier=activity_id)

if activity:
    print('success! Found activity with IATI identifier: "{}"'.format(activity_id))
else:
    print('failed! Could not find an activity with IATI identifier: "{}"'.format(activity_id))

# failed! Could not find an activity with IATI identifier: "GB-COH-07676886-999999"
@andylolz andylolz added the feature Cool stuff I’d like this library to be able to do label Dec 5, 2018
@andylolz
Copy link
Member Author

andylolz commented Dec 5, 2018

Obviously this sort of thing is already possible:

for p in iatikit.publishers():
    activity = p.activities.find(iati_identifier=activity_id)
    if activity:
        break

This would be the way to do it inefficiently. I’m looking for the quick way!

@andylolz
Copy link
Member Author

andylolz commented Jan 9, 2019

Done in d32bc52.

@andylolz andylolz closed this as completed Jan 9, 2019
@andylolz
Copy link
Member Author

andylolz commented Jan 10, 2019

So, this now works, and is quite fast:

import iatikit


activity_id = 'GB-COH-07676886-999999'

try:
    activity = iatikit.data().activities.find(iati_identifier=activity_id, fast=True)
    print('success! Found activity with IATI identifier: "{}"'.format(activity_id))
except IndexError:
    print('failed! Could not find an activity with IATI identifier: "{}"'.format(activity_id))

# failed! Could not find an activity with IATI identifier: "GB-COH-07676886-999999"

@andylolz
Copy link
Member Author

andylolz commented May 5, 2019

Reopening because I removed this feature. It was experimental and had some problems.

@andylolz andylolz reopened this May 5, 2019
@andylolz
Copy link
Member Author

One of the problems here is: publishers can change their org ID, but they don’t declare this at org level (either in their org metadata or in their org file). So it’s non-trivial to do a fast lookup for activities that use old org IDs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Cool stuff I’d like this library to be able to do
Projects
None yet
Development

No branches or pull requests

1 participant