Skip to content

Instantly share code, notes, and snippets.

@lognaturel
lognaturel / download_attachments.py
Last active January 23, 2023 23:12
Download all latest submission attachments for a given form_id
from pyodk.client import Client
import json
from functools import reduce
import urllib.parse
import os.path
def get_attachment_fields():
schema_r = client.get(f"projects/{client.config.central.default_project_id}/forms/{FORM_ID}/fields?odata=true")
schema = schema_r.json()
@lognaturel
lognaturel / public_link_provisioning.py
Last active September 27, 2022 14:59
Given a series of names, provision Public Links for any that don't have active links and output all the active links.
@lognaturel
lognaturel / app_user_provisioner.py
Last active December 20, 2023 17:55
Given a series of names, provision App Users for them and build a PDF of configuration QR codes.
from pyodk.client import Client
import base64
import json
import glob
import segno
from typing import Optional
import zlib
from PIL import Image, ImageOps, ImageFont, ImageDraw
@lognaturel
lognaturel / generate_subs_w_images.py
Created July 20, 2022 17:09
Generate random ODK submissions with attached media
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import uuid
import random
import os
import string
from PIL import Image
import numpy
@lognaturel
lognaturel / settings_qr.py
Created June 2, 2022 05:22
Given a string representing some ODK Collect user settings, create a configuration QR code
import base64
import json
import segno
import codecs
import zlib
settings = {
"general": {
"server_url": "https://demo.getodk.org"
},
@lognaturel
lognaturel / odk_central_basics.py
Last active April 5, 2022 22:15
A basic example of getting ODK data as a pandas dataframe
"""
Copyright 2022 ODK
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@lognaturel
lognaturel / copy_translations.py
Last active December 14, 2020 21:38
Quick Python script to pull translations downloaded from Transifex to the ODK Collect Android project
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import shutil
def replace_ellipses_with_special_char(file_path):
with open(file_path, 'r') as file :
filedata = file.read()
@lognaturel
lognaturel / gist:232395ee1079ff9e4b1b8e7096c3afaf
Last active February 14, 2023 13:15
Use DatePicker spinners in API 24
/**
* Workaround for this bug: https://code.google.com/p/android/issues/detail?id=222208
* In Android 7.0 Nougat, spinner mode for the DatePicker in DatePickerDialog is
* incorrectly displayed as calendar, even when the theme specifies otherwise.
*
* Modified slightly from the equivalent fix for TimePicker from @jeffdgr8:
* https://gist.github.com/jeffdgr8/6bc5f990bf0c13a7334ce385d482af9f
*/
private void fixSpinner(Context context, int year, int month, int dayOfMonth) {
// The spinner vs not distinction probably started in lollipop but applying this

Keybase proof

I hereby claim:

  • I am lognaturel on github.
  • I am lognaturel (https://keybase.io/lognaturel) on keybase.
  • I have a public key whose fingerprint is 3A30 F32D BB30 3EEF B4D4 14A4 5A97 E654 D02E 7DB3

To claim this, I am signing this object:

@lognaturel
lognaturel / FB birth months
Created August 5, 2011 20:09
Facebook friends birth month counts (Python)
# Uses Facebook Graph API to calculate birth month counts for your network.
# Get an access token from http://developers.facebook.com/tools/explorer/ (you'll need to check friend_birthday in 'Get Access Token' permissions)
import json
import urllib2
def load(id, thing):
address = "https://graph.facebook.com/" + str(id) + "/" + str(thing) + "?access_token=" + ACCESS_TOKEN
return json.load(urllib2.urlopen(address))