Skip to content

Instantly share code, notes, and snippets.

View danizen's full-sized avatar

Dan Davis danizen

View GitHub Profile
@danizen
danizen / marcindex.py
Created July 5, 2022 21:40
Index a MARC file so you can read only the parts you need
import io
import logging
import os
import mmap
import time
from collections.abc import Sequence
from struct import pack, unpack
LOG = logging.getLogger(__name__)
@danizen
danizen / areport.py
Created July 5, 2022 16:02
base management command to run a PL/SQL report
from . import BaseReportCommand
class Command(BaseReportCommand):
help = 'Report on records with both .....'
LOGFILE = 'report_output.log'
TEMPLATE = 'report_template.sql'
SUBJECT = 'Record has ERMS data and FER flag'
RECIPIENTS = [
@danizen
danizen / sqlproc.py
Last active October 22, 2021 23:25
SQL processing management command
import os
from django.core.management.base import BaseCommand
from django.core.management import call_command
class Command(BaseCommand):
def handle(self, *args, **options):
# create a pipe and turn the output file descriptor into a Python IO object
import attr
@attr.s
class BibData:
mms_id = attr.ib()
title = attr.ib()
status = attr.ib()
mod_date = attr.ib()
@danizen
danizen / queries.yaml
Created December 29, 2020 20:00
Non-authorized mechanism to export/convert MeSH RDF to SKOs
prefixes: |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX meshsv: <http://id.nlm.nih.gov/mesh/skos/>
@danizen
danizen / getbibs.py
Created November 18, 2020 20:42
Python3 script to access Alma APIs
#!/usr/bin/env python3
import sys
from argparse import ArgumentParser
from io import BytesIO
import requests
from lxml import etree
DFLT_ENDPOINT = 'https://api-na.hosted.exlibrisgroup.com'
(define (script_fu_batch_brushes inDir inLoadType)
(let*
(
(varLoadStr 0)
(varSaveStr 0)
(image 0)
(drawable 0)
(newfilename 0)
(filename 0)
(varFileList 0)
---
secret: "/dbsecrets/pgadmin@cfom_db_int"
database_name: cfom_db_int
search:
prefix: |
SELECT "physicians"."PHYSICIANID",
"physicians"."FIRSTNAME",
"physicians"."MIDDLENAME",
"physicians"."LASTNAME",
"physicians"."MAIDENNAME",
import json
import sys
from argparse import ArgumentParser, ArgumentTypeError
from copy import deepcopy
from datetime import datetime, timedelta
import attr
import requests
from dateutil import parser as date_parser
@danizen
danizen / backends.py
Last active August 3, 2020 17:58
Excerpt of logout flow
class LogoutMixin:
def logout_params(self, next_page):
# Backend should provide this
return {
'logout_uri': next_page
}
def logout_baseurl(self):
# Backend should provide this
return '/logout'