2021-06-06 12:09:21 +00:00
<!DOCTYPE html>
< html lang = "en-us" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< title > PyAutoGUI for simplifying anki routine< / title >
< link rel = "preconnect" href = "https://fonts.gstatic.com" >
< link href = "https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,400;0,500;0,700;1,300&display=swap" rel = "stylesheet" >
< link rel = "stylesheet" href = "https://site.horhik.xyz/css/basic.css" >
< / head >
< body >
2021-06-06 16:38:42 +00:00
< header class = "logo--wrapper" >
< a href = "/posts/pyautogui-for-simplifying-anki-routine/" > < pre class = "logo toilet-logo" title = "Home" >
░█▀▄░█░░░█▀█░█▀▀
░█▀▄░█░░░█░█░█░█
░▀▀░░▀▀▀░▀▀▀░▀▀▀
< span class = "logo-quote" > O. George’ s thoughts< / span >
< / pre > < / a >
< nav >
< ul class = "page-list" >
< li class = "page-link" > < a href = "/posts/" >
░█▀▄░█░░░█▀█░█▀▀
░█▀▄░█░░░█░█░█░█
░▀▀░░▀▀▀░▀▀▀░▀▀▀
< / a > < / li >
< li class = "page-link" > < a href = "/portfolio/" >
░█▀█░█▀█░█▀▄░▀█▀░█▀▀░█▀█░█░░░▀█▀░█▀█
░█▀▀░█░█░█▀▄░░█░░█▀▀░█░█░█░░░░█░░█░█
░▀░░░▀▀▀░▀░▀░░▀░░▀░░░▀▀▀░▀▀▀░▀▀▀░▀▀
< / a > < / li >
< li class = "page-link" > < a href = "https://site.horhik.xyz/" > ░█░█░█▀█░█▀▄░█░█░▀█▀░█░█░░░░█░█░█░█░▀▀█
░█▀█░█░█░█▀▄░█▀█░░█░░█▀▄░░░░▄▀▄░░█░░▄▀░
░▀░▀░▀▀▀░▀░▀░▀░▀░▀▀▀░▀░▀░▀░░▀░▀░░▀░░▀▀▀
< / a > < / li >
< / ul >
< / nav >
2021-06-06 12:09:21 +00:00
< / header >
< main >
< article class = "blog-post" >
< h1 class = "blog-header" > PyAutoGUI for simplifying anki routine< / h1 >
< sub > < small > < time > 21.01.2021 10:26< / time > < / small > < / sub >
< div >
< p > I had been adding some cards to Anki.
It was lowercase word and word with stress in russian. like < em > торты тОрты.< / em > < / p >
< p > I’ m lazy and i wrote two simple scripts. All what i have to do is input words with stress into a file.< br >
First script for creating file with list of sequence of word with stress and lowercase word< / p >
2021-06-06 16:38:42 +00:00
< div class = "highlight" > < div style = "color:#fff;background-color:#111;-moz-tab-size:2;-o-tab-size:2;tab-size:2" >
2021-06-06 12:09:21 +00:00
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2021-06-06 16:38:42 +00:00
< pre style = "color:#fff;background-color:#111;-moz-tab-size:2;-o-tab-size:2;tab-size:2" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
2021-06-06 12:09:21 +00:00
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 2
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 3
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 4
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 5
< / span > < / code > < / pre > < / td >
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
2021-06-06 16:38:42 +00:00
< pre style = "color:#fff;background-color:#111;-moz-tab-size:2;-o-tab-size:2;tab-size:2" > < code class = "language-python" data-lang = "python" > < span style = "color:#fb660a;font-weight:bold" > import< / span > os
f = open(< span style = "color:#0086d2" > " /home/horhik/text.txt" < / span > , < span style = "color:#0086d2" > ' r+' < / span > )
lines = f.readlines()
< span style = "color:#fb660a;font-weight:bold" > for< / span > ind, line in enumerate(lines):
< span style = "color:#fb660a;font-weight:bold" > print< / span > (line.lower(), < span style = "color:#0086d2" > " " < / span > , line)
2021-06-06 12:09:21 +00:00
< / code > < / pre > < / td > < / tr > < / table >
< / div >
< / div > < p > After, i just pushed output to file and opened it it Emacs.< / p >
< p > Second script automatizing adding cards to A< strong > nki< / strong > .< br >
I split my window by < strong > Anki< / strong > “ add card” window and < strong > Emacs< / strong > . As i use < code > evil< / code > mode in Emacs, script looks like that:< / p >
2021-06-06 16:38:42 +00:00
< div class = "highlight" > < div style = "color:#fff;background-color:#111;-moz-tab-size:2;-o-tab-size:2;tab-size:2" >
2021-06-06 12:09:21 +00:00
< table style = "border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;" > < tr > < td style = "vertical-align:top;padding:0;margin:0;border:0;" >
2021-06-06 16:38:42 +00:00
< pre style = "color:#fff;background-color:#111;-moz-tab-size:2;-o-tab-size:2;tab-size:2" > < code > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 1
2021-06-06 12:09:21 +00:00
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 2
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 3
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 4
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 5
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 6
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 7
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 8
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 9
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 10
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 11
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 12
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 13
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 14
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 15
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 16
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 17
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 18
< / span > < span style = "margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" > 19
< / span > < / code > < / pre > < / td >
< td style = "vertical-align:top;padding:0;margin:0;border:0;;width:100%" >
2021-06-06 16:38:42 +00:00
< pre style = "color:#fff;background-color:#111;-moz-tab-size:2;-o-tab-size:2;tab-size:2" > < code class = "language-python" data-lang = "python" > < span style = "color:#fb660a;font-weight:bold" > import< / span > pyautogui
2021-06-06 12:09:21 +00:00
2021-06-06 16:38:42 +00:00
< span style = "color:#fb660a;font-weight:bold" > import< / span > os
< span style = "color:#fb660a;font-weight:bold" > while< / span > (True):
pyautogui.hotkey(< span style = "color:#0086d2" > " winleft" < / span > , < span style = "color:#0086d2" > ' j' < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # toggle window< / span >
pyautogui.press([< span style = "color:#0086d2" > " v" < / span > , < span style = "color:#0086d2" > " $" < / span > , < span style = "color:#0086d2" > " y" < / span > ]) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # copy string< / span >
pyautogui.hotkey(< span style = "color:#0086d2" > " winleft" < / span > , < span style = "color:#0086d2" > ' j' < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # toggle window< / span >
pyautogui.hotkey(< span style = "color:#0086d2" > " ctrl" < / span > , < span style = "color:#0086d2" > ' v' < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # past text< / span >
pyautogui.press(< span style = "color:#0086d2" > " tab" < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # next input field< / span >
pyautogui.hotkey(< span style = "color:#0086d2" > " winleft" < / span > , < span style = "color:#0086d2" > ' j' < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # toggle window< / span >
pyautogui.press([< span style = "color:#0086d2" > " j" < / span > ,< span style = "color:#0086d2" > " 0" < / span > , < span style = "color:#0086d2" > " w" < / span > , < span style = "color:#0086d2" > " v" < / span > , < span style = "color:#0086d2" > " $" < / span > , < span style = "color:#0086d2" > " y" < / span > , < span style = "color:#0086d2" > " 0" < / span > , < span style = "color:#0086d2" > " j" < / span > , < span style = "color:#0086d2" > " j" < / span > ])
< span style = "color:#080;background-color:#0f140f;font-style:italic" > # move to next line beginning, copy it and go to next occurence< / span >
pyautogui.hotkey(< span style = "color:#0086d2" > " winleft" < / span > , < span style = "color:#0086d2" > ' j' < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # toggle window< / span >
pyautogui.hotkey(< span style = "color:#0086d2" > " ctrl" < / span > , < span style = "color:#0086d2" > ' v' < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # paste text< / span >
pyautogui.press(< span style = "color:#0086d2" > " tab" < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # ...< / span >
pyautogui.press(< span style = "color:#0086d2" > " tab" < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # ...< / span >
pyautogui.press(< span style = "color:#0086d2" > " tab" < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # ...< / span >
pyautogui.press(< span style = "color:#0086d2" > " tab" < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # ... way to submit button< / span >
pyautogui.press(< span style = "color:#0086d2" > " space" < / span > ) < span style = "color:#080;background-color:#0f140f;font-style:italic" > # pressing submit button< / span >
2021-06-06 12:09:21 +00:00
< / code > < / pre > < / td > < / tr > < / table >
< / div >
< / div > < p > < code > while(true)< / code > was my mistake. I launched script in terminal, with < code > sleep< / code > 3 seconds before.< br >
But i couldn’ t shut script down without any strange effect when i opening not only 2 windows in my Window Manager.< br >
Some strange things happen before I cached terminal and pressed < code > Ctrl+C< / code > < / p >
< / div >
< / article >
< / main >
2021-01-24 16:23:53 +00:00
2021-06-06 12:09:21 +00:00
< footer >
< ul class = "contacts" >
2021-06-06 16:38:42 +00:00
< li > < a href = "https://github.com/horhik" class = " contact-link" title = "github" >
2021-06-06 12:09:21 +00:00
< pre > oo dP dP dP
2021-01-24 16:23:53 +00:00
88 88 88
.d8888b. dP d8888P 88d888b. dP dP 88d888b.
88' `88 88 88 88' `88 88 88 88' `88
88. .88 88 88 88 88 88. .88 88. .88
`8888P88 dP dP dP dP `88888P' 88Y8888'
.88
2021-06-06 12:09:21 +00:00
d8888P < / pre > < / a > < / li >
2021-06-06 16:38:42 +00:00
< li > < a href = "https://twitter.com/HORHl" class = " contact-link" title = "twitter" >
2021-06-06 12:09:21 +00:00
< pre > dP oo dP dP
2021-01-24 16:23:53 +00:00
88 88 88
d8888P dP dP dP dP d8888P d8888P .d8888b. 88d888b.
88 88 88 88 88 88 88 88ooood8 88' `88
88 88.88b.88' 88 88 88 88. ... 88
dP 8888P Y8P dP dP dP `88888P' dP
2021-06-06 12:09:21 +00:00
< / pre > < / a > < / li >
2021-06-06 16:38:42 +00:00
< li > < a href = "mailto:horhik@tuta.io" class = " contact-link" title = "Mail" >
2021-06-06 12:09:21 +00:00
< pre > oo dP
2021-01-24 16:23:53 +00:00
88
88d8b.d8b. .d8888b. dP 88
88'`88'`88 88' `88 88 88
88 88 88 88. .88 88 88
dP dP dP `88888P8 dP dP
2021-06-06 12:09:21 +00:00
< / pre > < / a > < / li >
< / ul >
< p class = "copyright" > © 2021 < a href = "https://site.horhik.xyz/" > Horhik.xyz< / a > < / p >
< / footer >
2021-06-06 16:38:42 +00:00
2021-06-06 12:09:21 +00:00
< / body >
< / html >