Created
July 13, 2018 17:03
-
-
Save davidhuser/1f34241bfab065902742eb498ca78542 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests, json | |
| base_url = "https://play.dhis2.org/dev" | |
| username = "admin" | |
| password = "district" | |
| programs = [ | |
| "kla3mAPgvCH" | |
| ] | |
| session = requests.Session() | |
| session.auth = (username, password) | |
| for program_uid in programs: | |
| # GET all events of a program | |
| filter1 = { | |
| 'program': program_uid, | |
| 'skipPaging': True, | |
| 'fields': 'event' | |
| } | |
| req1 = session.get(url="{}/api/events.json".format(base_url), params=filter1) | |
| response1 = req1.json() | |
| events = [x['event'] for x in req1.json()['events']] | |
| print("Found {} events to delete...".format(len(events))) | |
| # Delete each event | |
| for i, uid in enumerate(events, 1): | |
| req2 = session.delete("{}/api/events/{}".format(base_url, uid)) | |
| req2.raise_for_status() | |
| print("[{}/{}] Event {} deleted".format(i, len(events), uid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment