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
| """Insert missing https://www.autotyp.uzh.ch N.levels from overview into metadata files | |
| see https://github.com/autotyp/autotyp-data/pull/7 | |
| """ | |
| import csv | |
| import operator | |
| import pathlib | |
| import regex |
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
| """Compare ways to have unique columns with NULLs.""" | |
| import os | |
| import subprocess | |
| import time | |
| import uuid | |
| import sqlalchemy as sa | |
| import sqlalchemy.orm |
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
| """SQL-injection safe dynamic query with pl/pgsql.""" | |
| import sqlalchemy as sa | |
| UNIQUE_NULL = [('contributioncontributor', ['contribution_pk', 'contributor_pk'], []), | |
| ('contributionreference', ['contribution_pk', 'source_pk', 'description'], []), | |
| ('editor', ['dataset_pk', 'contributor_pk'], []), | |
| ('languageidentifier', ['language_pk', 'identifier_pk'], []), | |
| ('languagesource', ['language_pk', 'source_pk'], []), | |
| ('sentencereference', ['sentence_pk', 'source_pk', 'description'], []), |
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
| """Decorator with an optional parameter. | |
| See also https://mypy.readthedocs.io/en/stable/generics.html#decorator-factories | |
| """ | |
| from collections.abc import Callable | |
| import functools | |
| from typing import Any, overload | |
| FUNCS = {} |
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
| r"""Split a string into chunks by a pattern matching at the start of each item. | |
| >>> list(itersplit(r'!', 'spam !eggs !ham')) | |
| ['spam ', '!eggs ', '!ham'] | |
| >>> list(itersplit(r'X', 'spam !eggs !ham')) | |
| ['spam !eggs !ham'] | |
| >>> list(itersplit(r'!', '!spam !eggs !ham')) | |
| ['', '!spam ', '!eggs ', '!ham'] |
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
| """os.walk() variation with Google Drive API v3.""" | |
| from collections.abc import Iterator, Sequence | |
| import os | |
| import pathlib | |
| from typing import TypedDict | |
| # $ pip install google-api-python-client google-auth-oauthlib | |
| from apiclient import discovery | |
| from google.oauth2 import credentials |
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
| """Download all sheets of a Google Docs spreadsheet as CSV.""" | |
| from collections.abc import Sequence | |
| import contextlib | |
| import csv | |
| import itertools | |
| import os | |
| import pathlib | |
| # $ pip install google-api-python-client google-auth-oauthlib |
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
| """Download all available audio books from DB ICE Portal.""" | |
| import json | |
| import os | |
| import urllib.parse | |
| import urllib.request | |
| BASE = 'http://iceportal.de/api1/rs/' |
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
| """Compare feed enclosure length with content-length of file url.""" | |
| import urllib.request | |
| import xml.etree.ElementTree as etree | |
| URL = 'https://feeds.feedburner.com/thebuglefeed?format=xml' | |
| with urllib.request.urlopen(URL) as f: | |
| tree = etree.parse(f) |
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
| """Use advanced XPath features of lxml (see also scrapy parsel).""" | |
| from collections.abc import Callable | |
| import functools | |
| from typing import Any, Self, overload | |
| import urllib.request | |
| import lxml.etree | |
| import lxml.html |