Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import requests
import datetime
import click
import asyncio
import getpass
from pyppeteer import launch
from typing import List, Optional
from invenio_workflows import workflow_object_class, ObjectStatus
from collections import Counter
def _get_nice_message(wflw):
if 'Found workflows in ERROR or INITIAL state:' in wflw.extra_data['_error_msg']:
return wflw.extra_data['_error_msg'].splitlines()[-1].rsplit(':', 1)[0]
return wflw.extra_data['_error_msg'].splitlines()[-1]
def get_errors_by_type():
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
from invenio_db import db
def get_indexes_info():
return list(db.engine.execute('''
SELECT
pg_class.relname,
pg_size_pretty(pg_class.reltuples::BIGINT) AS rows_in_bytes,
pg_class.reltuples AS num_rows,
COUNT(indexname) AS number_of_indexes,
CASE WHEN x.is_unique = 1 THEN 'Y'
from invenio_db import db
from invenio_workflows import workflow_object_class, ObjectStatus, workflows
def has_name(task, task_name):
return ' ' + task_name + ' ' in str(task)
def get_task_index(workflow, task_name):
if callable(workflow):
if has_name(workflow, task_name):
import re
import os
from invenio_db import db
from invenio_workflows import workflow_object_class, ObjectStatus, workflows
from inspirehep.modules.records.utils import open_url_or_path
SITE_NAME = 'labs.inspirehep.net'
@david-caro
david-caro / create_new_oaiharvest_conf.py
Created November 21, 2017 18:11
Example of how to initialize an OAIHarvestConf
from invenio_oaiharvester.models import OAIHarvestConfig
new_conf = OAIHarvestConfig(
name='pos',
metadataprefix='pos-ext_dc',
setspecs='',
baseurl='https://pos.sissa.it/cgi-bin/oai/oai-script-spires-extended.cgi',
)
from invenio_db import db
db.session.add(new_conf)
db.session.commit()
from invenio_db import db
seqs = [
res[0]
for res in db.engine.execute(
"select relname from pg_class where relkind='S';"
)
]
@david-caro
david-caro / es_cli.py
Last active April 11, 2017 21:56
Small ES cli tool to remap an index
#!/usr/bin/env python
# encoding: utf-8
import json
import re
import time
import logging
import click
from elasticsearch import Elasticsearch
from elasticsearch.helpers import reindex
@david-caro
david-caro / db_helpers.py
Last active March 23, 2017 10:30
db consistency check
from invenio_db import db
from sqlalchemy import inspect
from sqlalchemy.exc import ProgrammingError
def check_col_seq_consistency(table, col):
seq_id = get_seq_id(table, col)
max_id = get_max_id(table, col)
if max_id is not None and seq_id != max_id:
print 'ERROR: {table}::{col} has a different seq={seq} than max={max}, please check.'.format(