personal-site/public/posts/pyautogui-for-simplifying-anki-routine/index.html

180 lines
11 KiB
HTML
Raw Normal View History

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">
2021-06-07 18:03:06 +00:00
<link rel="stylesheet" href="https://horhik.xyz/css/basic.css">
2021-06-06 12:09:21 +00:00
</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. Georges thoughts</span>
</pre></a>
<nav>
<ul class="page-list">
<li class="page-link"><a href="/portfolio/">
░█▀█░█▀█░█▀▄░▀█▀░█▀▀░█▀█░█░░░▀█▀░█▀█
░█▀▀░█░█░█▀▄░░█░░█▀▀░█░█░█░░░░█░░█░█
░▀░░░▀▀▀░▀░▀░░▀░░▀░░░▀▀▀░▀▀▀░▀▀▀░▀▀
2021-06-07 18:03:06 +00:00
</a></li>
<li class="page-link"><a href="/posts/">
░█▀▄░█░░░█▀█░█▀▀
░█▀▄░█░░░█░█░█░█
░▀▀░░▀▀▀░▀▀▀░▀▀▀
2021-06-06 16:38:42 +00:00
</a></li>
2021-06-07 18:03:06 +00:00
<li class="page-link"><a href="https://horhik.xyz/">░█░█░█▀█░█▀▄░█░█░▀█▀░█░█░░░░█░█░█░█░▀▀█
2021-06-06 16:38:42 +00:00
░█▀█░█░█░█▀▄░█▀█░░█░░█▀▄░░░░▄▀▄░░█░░▄▀░
2021-06-07 18:03:06 +00:00
░▀░▀░▀▀▀░▀░▀░▀░▀░▀▀▀░▀░▀░▀░░▀░▀░░▀░░▀▀▀</a></li>
2021-06-06 16:38:42 +00:00
</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&rsquo;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">&#34;/home/horhik/text.txt&#34;</span>, <span style="color:#0086d2">&#39;r+&#39;</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">&#34; &#34;</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> &ldquo;add card&rdquo; 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">&#34;winleft&#34;</span>, <span style="color:#0086d2">&#39;j&#39;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># toggle window</span>
pyautogui.press([<span style="color:#0086d2">&#34;v&#34;</span>, <span style="color:#0086d2">&#34;$&#34;</span>, <span style="color:#0086d2">&#34;y&#34;</span>]) <span style="color:#080;background-color:#0f140f;font-style:italic"># copy string</span>
pyautogui.hotkey(<span style="color:#0086d2">&#34;winleft&#34;</span>, <span style="color:#0086d2">&#39;j&#39;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># toggle window</span>
pyautogui.hotkey(<span style="color:#0086d2">&#34;ctrl&#34;</span>, <span style="color:#0086d2">&#39;v&#39;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># past text</span>
pyautogui.press(<span style="color:#0086d2">&#34;tab&#34;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># next input field</span>
pyautogui.hotkey(<span style="color:#0086d2">&#34;winleft&#34;</span>, <span style="color:#0086d2">&#39;j&#39;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># toggle window</span>
pyautogui.press([<span style="color:#0086d2">&#34;j&#34;</span>,<span style="color:#0086d2">&#34;0&#34;</span>, <span style="color:#0086d2">&#34;w&#34;</span>, <span style="color:#0086d2">&#34;v&#34;</span> , <span style="color:#0086d2">&#34;$&#34;</span>, <span style="color:#0086d2">&#34;y&#34;</span>, <span style="color:#0086d2">&#34;0&#34;</span>, <span style="color:#0086d2">&#34;j&#34;</span>, <span style="color:#0086d2">&#34;j&#34;</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">&#34;winleft&#34;</span>, <span style="color:#0086d2">&#39;j&#39;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># toggle window</span>
pyautogui.hotkey(<span style="color:#0086d2">&#34;ctrl&#34;</span>, <span style="color:#0086d2">&#39;v&#39;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># paste text</span>
pyautogui.press(<span style="color:#0086d2">&#34;tab&#34;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># ...</span>
pyautogui.press(<span style="color:#0086d2">&#34;tab&#34;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># ...</span>
pyautogui.press(<span style="color:#0086d2">&#34;tab&#34;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># ...</span>
pyautogui.press(<span style="color:#0086d2">&#34;tab&#34;</span>) <span style="color:#080;background-color:#0f140f;font-style:italic"># ... way to submit button</span>
pyautogui.press(<span style="color:#0086d2">&#34;space&#34;</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&rsquo;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>
2021-06-07 18:03:06 +00:00
<p class="copyright">&copy;2021 <a href="https://horhik.xyz/">Horhik.xyz</a></p>
2021-06-06 12:09:21 +00:00
</footer>
2021-06-06 16:38:42 +00:00
2021-06-06 12:09:21 +00:00
</body>
</html>