diff options
| author | Anton Bobov <anton@bobov.name> | 2022-01-30 21:03:14 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2022-01-30 21:03:14 +0500 |
| commit | b25a5b794be7093dbcd556fcab2ebc50bb33e8b2 (patch) | |
| tree | 282659aa4c647c87e004273efd4d02599afbcec2 | |
| parent | c83690911af9326784d81e49e2b55de9688c1e9b (diff) | |
Updates.
| -rwxr-xr-x | d-backup | 7 | ||||
| -rwxr-xr-x | emojis | 17 | ||||
| -rwxr-xr-x | git-split | 4 | ||||
| -rwxr-xr-x | ledger-price-db-update.py | 6 | ||||
| -rwxr-xr-x | mutt-ldap-query | 73 | ||||
| -rwxr-xr-x | packages-by-component | 28 |
6 files changed, 127 insertions, 8 deletions
@@ -7,7 +7,7 @@ # TARGET="sftp://server/path" # ---------------- 8< -------------------- -if [ ! $(whoami) = root ] ; then +if [ ! "$(whoami)" = root ] ; then echo "This script must be run by the user: root" exit 1 fi @@ -75,12 +75,12 @@ while (( "$#" )) ; do ;; list) shift - list $* + list "$@" exit 0 ;; restore) shift - restore $* + restore "$@" exit 0 ;; *) @@ -89,4 +89,3 @@ while (( "$#" )) ; do esac shift done - @@ -8,16 +8,33 @@ list() { fzf --no-sort --reverse | awk '{print $1}' | xsel } +print_help() { + cat <<EOF +Usage: $(basename "$0") [-h|--help] [-g|--git] + +-h, --help prints this message +-g, --git list gitmojis +EOF +} + name=EMOJI while [[ $# -gt 0 ]] ; do case "$1" in -g|--git) name=GITMOJI ;; + -h|--help) + HELP=1 + ;; esac shift done +if [ "$HELP" = 1 ] ; then + print_help + exit 0 +fi + list $name exit 0 @@ -12,7 +12,7 @@ SHA=$(git rev-parse --short HEAD) git reset HEAD^ -git diff-tree --no-commit-id --name-only -r $SHA | while read -r f; do +git diff-tree --no-commit-id --name-only -r "$SHA" | while read -r f; do git add "$f" - GIT_EDITOR="echo '0a\n$SHA $f\n\n.\nw' | ed -s" git commit -c $SHA + GIT_EDITOR="echo '0a\n$SHA $f\n\n.\nw' | ed -s" git commit -c "$SHA" done diff --git a/ledger-price-db-update.py b/ledger-price-db-update.py index eed54bc..0f517ff 100755 --- a/ledger-price-db-update.py +++ b/ledger-price-db-update.py @@ -73,7 +73,9 @@ def stocks(): params = {"assetclass": "stocks"} url = r'https://api.nasdaq.com/api/quote/%s/info' % (symbol) data = get_json(url, params=params) - price = float(data['data']['keyStats']['PreviousClose']['value'][1:]) + lastPriceString = data['data']['primaryData']['lastSalePrice'] + lastPrice = ''.join([c for c in lastPriceString if c.isdigit() or c == '.']) + price = float(lastPrice) print_price(symbol, price, '$') @@ -115,7 +117,7 @@ def bonds(): url = r'https://iss.moex.com/iss/engines/stock/markets/bonds/boards/TQOB/securities/%s.jsonp?from=%s' % ( symbol, date_str) else: - url = r'https://iss.moex.com/iss/engines/stock/markets/bonds/boards/EQOB/securities/%s.jsonp?from=%s' % ( + url = r'https://iss.moex.com/iss/engines/stock/markets/bonds/boards/TQCB/securities/%s.jsonp?from=%s' % ( symbol, date_str) data = get_json(url)['securities'] price = get_moex_value(data, 'PREVPRICE') diff --git a/mutt-ldap-query b/mutt-ldap-query new file mode 100755 index 0000000..bc5cab4 --- /dev/null +++ b/mutt-ldap-query @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +""" +Query LDAP directory for users and print it in a mutt query format. +""" +import argparse +import sys + +import ldap3 + + +def first(values): + if values is None or len(values) == 0: + return "" + return values[0] + + +def split_to_list(string): + return string.split(',') + + +def ldap_search(args): + search_filter = [f'({f}=*{args.term}*)' for f in args.search_filters] + search_filter = '(|' + ''.join(search_filter) + ')' + + with ldap3.Connection(ldap3.Server(args.server, port=args.port), + auto_bind=ldap3.AUTO_BIND_NO_TLS, + read_only=True, + check_names=True, + user=args.username, password=args.password) as c: + results = c.extend.standard.paged_search(search_base=args.search_base, + search_filter=search_filter, + search_scope=ldap3.SUBTREE, + attributes=list(args.search_attributes), + get_operational_attributes=True, + generator=False) + count = len(results) + if count: + print(f'Found {count} entries:') + for r in results: + attrs = [first(r['attributes'][attr]) for attr in args.search_attributes[:2]] + attrs.append(' / '.join([first(r['attributes'][attr]) for attr in args.search_attributes[2:]])) + last = '\t'.join(attrs) + print(last) + else: + print('Not found.') + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('term', help="search term") + parser.add_argument('-s', '--server', required=True, help='server hostname') + parser.add_argument('-p', '--port', type=int, default=389, help='server port (default: %(default)s)') + parser.add_argument('-u', '--username', help='username') + parser.add_argument('-P', '--password', help='password') + parser.add_argument('-b', '--search-base', metavar="SB", default='ou=people', type=split_to_list, + help="search base string (default: %(default)s)") + parser.add_argument('-f', '--search-filters', metavar="FILTERS", + default='mail,cn', type=split_to_list, + help="list of fields to filter (default: %(default)s)") + parser.add_argument('-a', '--search-attributes', metavar="ATTRIBUTES", + default='mail,cn', type=split_to_list, + help="list of resulting attributes (default: %(default)s)") + args = parser.parse_args() + + ldap_search(args) + + +if __name__ == '__main__': + try: + main() + except Exception as e: + print(e) + sys.exit(1) diff --git a/packages-by-component b/packages-by-component new file mode 100755 index 0000000..b4ab600 --- /dev/null +++ b/packages-by-component @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +print_help() { + cat <<EOF +Usage: $(basename "$0") COMPONENT + +COMPONENT - name of component (ex.: contrib, non-free) +EOF + exit 1 +} + +list_installed() { + dpkg -l | grep '^ii' | cut -d ' ' -f 3 | cut -d ':' -f 1 | sort -u +} + +list_packages() { + component="$1" + grep '^Package:' /var/lib/apt/lists/*_"${component}"_*Packages | cut -d ' ' -f 2 | sort -u + +} + +if [ $# -lt 1 ] ; then + print_help +fi + +comm -12 <(list_installed) <(list_packages "$1") |
