Skip to content

Instantly share code, notes, and snippets.

@lokal-profil
lokal-profil / xml_parser.py
Last active August 18, 2019 08:45
Parser for Wikimania 2019 xml to tsv (the tsv output format might since then have become outdated)
import sys
from xml.etree import ElementTree
import datetime
from collections import defaultdict
DAY_TITLE_FORMAT = '%A' # '%A %d %B'
BLOCK_FORMAT = '{day}-session-block-{num}' # saturday-session-block-1
TSV_FORMAR = '{id}\t{day}\t{title}\t"{abstract}"\t"{persons_list}"\t{persons}\t{room}\t\t{block}\t{space}\t{start}\t{end}\t{link}\t\tTRUE\t"{tags}"\t\t\t\n'
@lokal-profil
lokal-profil / replace_header.py
Last active July 30, 2019 13:04
Quick modification of existing pywikibot script to run replacements on wikimania wiki
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Bot to replace the manual submission header by a template.
Pages provided by a generator. e.g. -catr:2019:Submissions
'&params;'
"""
from queue import Queue
@lokal-profil
lokal-profil / _Fortnox huvudbok processing
Last active September 20, 2019 07:52
Crunch fortnox huvudbok export to combine all entries by konto and kostnadsställe
The contents of this gist has moved to https://github.com/Wikimedia-Sverige/scripts/tree/master/fortnox_huvudbok_processing
where it will also be kept updated.
@lokal-profil
lokal-profil / 5_words.txt
Last active October 2, 2018 12:08
libris_descriptions_sample quick clean
stockholms universitet, Botaniska institutionen (2011)
fysiker (mekanik), universitetslektor vid KTH
fil. dr. i nordiska språk
beteendevetare, arbetar även med ledningsutveckling
rysk författare. Emigrerade efter 1920
skrivit om KFUM-kören i Örebro
tysk politiker & ekonom, 1897-1977
kulturredaktör på Norrländska socialdemokraten (1996)
litteraturvetare, docent vid Uppsala universitet
fransk tonsättare och organist, 1907-1991
@lokal-profil
lokal-profil / clean_logs.py
Last active August 22, 2018 22:43
Additional cleanup step for analysing WLM logs.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import re
def clean_log(filename):
import codecs
f_in = codecs.open(filename, 'r', 'utf-8')
f_out = codecs.open('{}.clean'.format(filename), 'w', 'utf-8')
bad_warnings = (
@lokal-profil
lokal-profil / heritage_log_handling.sh
Last active August 22, 2018 09:22
Shell script for chopping heritage logs to only the last copleted run
#!/bin/bash
#
# Script to make a local copy of the last complete log
# make a local copy of the logs
cp /data/project/heritage/logs/update_monuments.log ./raw.log;
# cut log at last complete
last_complete=$(grep --binary-files=text -n "Done with the update!" raw.log | tail -n1 | cut -f1 -d:);
head -n "$last_complete" raw.log > tmp.log;
@lokal-profil
lokal-profil / project_connection_import.py
Last active July 19, 2018 14:14
Import script for project connection on Wikidata
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Quick pywikibot wrapper for statement addition.
"""
import pywikibot
PROP = 'P5008'
TARGET_Q = 'Q123'
REF_PROP = 'P248'
@lokal-profil
lokal-profil / Burnchart.js
Last active July 4, 2019 08:28
Burnchart calcs for use in Google Calc sheet
// Backup copy at https://gist.github.com/lokal-profil/31d8651049d1ebf58bc668c7f27ab288
var rangeRef = "Staff!G1" // this is the cell in which the allowed personnel range (on the same sheet) is specified.
var delimiterLookup = {
"COMMA": ",",
"SEMICOLON": ";",
"PERIOD": ".",
"SPACE": " "
}
/**
@lokal-profil
lokal-profil / check_WLE_id.py
Created May 14, 2018 15:26
Short script for reproducing WLM style reporting pages for Wikidata powered competitions (here WLE in Sweden)
# -*- coding: utf-8 -*-
# python check_WLE_id.py -live -dir:~/Projects/batchUploadTools/
"""Script for updating unused imges/unknonw ids pages for WLE on sv.wp."""
import pywikibot
import wikidataStuff.wdqsLookup as query
SETTING = {
'prop': 'P3613',
'formatter_url': 'http://skyddadnatur.naturvardsverket.se/sknat/?nvrid={}',
'cat': 'Category:Protected areas of Sweden with known IDs',
@lokal-profil
lokal-profil / lowerCaseConnections.py
Last active November 9, 2015 19:46
LSH: Script for a one-time replacement of upper case connections in Materials, Keywords and ObjKeywords
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Cleanup function for a one-time replacement of upper case connections
# in Materials, Keywords and ObjKeywords
#
import helpers
import codecs
import os