serhii.net

In the middle of the desert you can say anything you want

30 Mar 2020

Day 455

Qutebrowser edit url in editor

config.bind('E', 'set-cmd-text -s :edit-url') added to config.py allows me to press E and the command will be prefilled.

Interesting arguments 1:

-b, --bg: Open in a new background tab.
-t, --tab: Open in a new tab.
-w, --window: Open in a new window.
-p, --private: Open a new window in private browsing mode.

Keyboard layout changes

Made the following changes and bumped the version to v5:

// Changing aoeu for umlauted letters

    key <AC01> { [	    a,	A, adiaeresis,	s]	};
    key <AC02> { [	    o,	O, odiaeresis,	n]	};
    key <AC03> { [	    e,	E, ediaeresis,	t]	};
    key <AC04> { [	    u,	U, udiaeresis,	u]	};

// Adding ~` to the better key for this

    key <AD01> { [  apostrophe,	quotedbl,	grave,	asciitilde] };
    key <AD02> { [	comma,	less,   r, asciitilde] };
// Adding parentheses in a better place

    key <AD08> { [	    c,	C,	Up,	 parenleft	]	};
    key <AD09> { [	    r,	R,	BackSpace,	parenright		]	};

    key <AD07> { [	    g,	G,	bracketleft,	braceleft		]	};
    key <AD10> { [	    l,	L,	bracketright,	braceright]	};

// Numbers!

    key <AB01> { [   semicolon,	colon,1,	exclam] };
    key <AB02> { [	    q,	Q,	2,	at		]	};
    key <AB03> { [	    j,	J,	3,	numbersign		]	};
    key <AB04> { [	    k,	K,	4,	dollar		]	};
    key <AB05> { [	    x,	X,	5,	percent		]	};
    key <AB06> { [	    b,	B,	6,	asciicircum]	};
    key <AB07> { [	    m,	M,	7,	ampersand]	};
    key <AB08> { [	    w,	W,	8,	asterisk]	};
    key <AB09> { [	    v,	V,	9,	asterisk]	};
    key <AB10> { [	    z,	Z,	0,	asterisk]	};

// A new delete key
    key <AC06> { [	    d,	D,	KP_Delete,	asterisk]	};

Now I have brackets on my right hand letters :) I’ll think later what other symbols I still have not learned by heart and move the below. (Numbers, maybe?)

Fiamma userscript update

Updated the userscript to the following, now it removes stuff Mediawiki doesn’t like from the name of the page (but not from the Title, which is not part of the URL!)

#!/usr/bin/python3
import os
from urllib.parse import quote_plus

def urlencode(string):
  return quote_plus(string)

def replace(original):
    new = original.replace("|", "-")
    return new

def replace_name(original):
    new = original.replace("|", "-")
    new = new.replace("[", "(")
    new = new.replace("]", ")")
    new = new.replace("#", "(hash)")
    new = new.replace("{", "(")
    new = new.replace("}", ")")
    new = new.replace("_", " ") # TODO test
    return new

title = os.environ['QUTE_TITLE']
url = os.environ['QUTE_URL']
selected_text = os.environ['QUTE_SELECTED_TEXT']

newTitle = replace(title)
newArticleName = replace_name(title)
newUrl = replace(url)
newText = replace(selected_text)
print(newTitle)

article_title = urlencode(newTitle)
article_name = urlencode(newArticleName)
page_url = urlencode(newUrl)
selected_text = urlencode(newText)

fiammaUrl = 'https://pchr8.net/f/index.php'
url = fiammaUrl+'?title='+article_name+'&action=edit&preload=Template:NewLink&preloadparams[]='+page_url+'&preloadparams[]='+article_title+'&preloadparams[]='+selected_text

with open(os.environ['QUTE_FIFO'], 'w') as f:
    f.write("open -w {}".format(url))

Random / Interesting

This is a nice wikipedia page that starts with “Q.” and not with “Q:”, because “Q:” is forbidden as start of page name: Q. Are We Not Men? A: We Are Devo! - Wikipedia

Pizza dough

I’ll try to do this tomorrow: The Best Pizza Dough Recipe - Sugar Spun Run

Mattermost and Python

For when I get to this, it’s easy, after I install matterhook:

>>> mwh = Webhook('https://chat.mycompany.de', 'myAPIhook')
>>> mwh.send('test',channel='notif')

Very nice explanation here: GitHub - numberly/matterhook: Interact with Mattermost incoming webhooks easily.

Python run from command line / shell with all the imports and stuff

Say I’m in folder2 and want to run folder2/folder/main.py

python3 -m folder.main adds folder2 to $PATH, while python3 folder/main.py adds folder to $PATH. The first option makes all imports much much easier.

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus