Last active
September 27, 2022 14:59
-
-
Save lognaturel/16fb9692fdf499cf96793b95580b5c0f to your computer and use it in GitHub Desktop.
Given a series of names, provision Public Links for any that don't have active links and output all the active links.
This file contains 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
from pyodk.client import Client | |
PROJECT = 149 | |
FORMID = "audit-log" | |
# The web form URL you get from the New button on the Submissions tab | |
ENKETO_URL = "https://test.getodk.cloud/-/single/juNrxf5H94Dwc09rudQvjAOzCUKOVic" | |
client = Client().open() | |
with open('people.csv', newline='') as f: | |
people = f.readlines() | |
people = [person.rstrip() for person in people] | |
existing_links = client.get(f"projects/{PROJECT}/forms/{FORMID}/public-links").json() | |
existing_links = [link for link in existing_links if link["token"] is not None] | |
existing_links | |
for person in people: | |
exists = False | |
for link in existing_links: | |
if link["displayName"] == person: | |
print(f"{person}: {ENKETO_URL}?st={link['token']}") | |
exists = True | |
break | |
if not(exists): | |
try: | |
r = client.post(f"/projects/{PROJECT}/forms/{FORMID}/public-links", json={"displayName": person}) | |
r.raise_for_status() | |
except Exception as err: | |
print(err) | |
print(f"{person} (new): {ENKETO_URL}?st={r.json()['token']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment