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

160 lines
5.8 KiB
HTML

<!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://redeyes.club/css/basic.css">
</head>
<body>
<header class="logo--wrapper">
<a href="/posts/pyautogui-for-simplifying-anki-routine/"><pre class="logo toilet-logo" title="Home">
░█▀▄░█░░░█▀█░█▀▀
░█▀▄░█░░░█░█░█░█
░▀▀░░▀▀▀░▀▀▀░▀▀▀
</pre></a>
<nav>
<ul class="page-list">
<li class="page-link"><a href="/music/">
░█▄█░█░█░█▀▀░▀█▀░█▀▀
░█░█░█░█░▀▀█░░█░░█░░
░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀
</a></li>
<li class="page-link"><a href="/portfolio/">
░█▀█░█▀█░█▀▄░▀█▀░█▀▀░█▀█░█░░░▀█▀░█▀█
░█▀▀░█░█░█▀▄░░█░░█▀▀░█░█░█░░░░█░░█░█
░▀░░░▀▀▀░▀░▀░░▀░░▀░░░▀▀▀░▀▀▀░▀▀▀░▀▀
</a></li>
<li class="page-link"><a href="/posts/">
░█▀▄░█░░░█▀█░█▀▀
░█▀▄░█░░░█░█░█░█
░▀▀░░▀▀▀░▀▀▀░▀▀▀
</a></li>
<li class="page-link"><a href="https://redeyes.club/">░█▄█░█▀█░▀█▀░█▀█░▄▀░░▀▄░
░█░█░█▀█░░█░░█░█░█░░░░█░
░▀░▀░▀░▀░▀▀▀░▀░▀░░▀░░▀░░</a></li>
</ul>
</nav>
</header>
<main>
<style>
audio {height:200px;
width:300px;
background-image:url("");
background-position: center;
background-size: 550px 425px;
border-radius: 10px;
}
</style>
<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>
<pre><code class="language-python">import os
f = open(&quot;/home/horhik/text.txt&quot;, 'r+')
lines = f.readlines()
for ind, line in enumerate(lines):
print(line.lower(), &quot; &quot;, line)
</code></pre>
<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>
<pre><code class="language-python">import pyautogui
import os
while(True):
pyautogui.hotkey(&quot;winleft&quot;, 'j') # toggle window
pyautogui.press([&quot;v&quot;, &quot;$&quot;, &quot;y&quot;]) # copy string
pyautogui.hotkey(&quot;winleft&quot;, 'j') # toggle window
pyautogui.hotkey(&quot;ctrl&quot;, 'v') # past text
pyautogui.press(&quot;tab&quot;) # next input field
pyautogui.hotkey(&quot;winleft&quot;, 'j') # toggle window
pyautogui.press([&quot;j&quot;,&quot;0&quot;, &quot;w&quot;, &quot;v&quot; , &quot;$&quot;, &quot;y&quot;, &quot;0&quot;, &quot;j&quot;, &quot;j&quot; ])
# move to next line beginning, copy it and go to next occurence
pyautogui.hotkey(&quot;winleft&quot;, 'j') # toggle window
pyautogui.hotkey(&quot;ctrl&quot;, 'v') # paste text
pyautogui.press(&quot;tab&quot;) # ...
pyautogui.press(&quot;tab&quot;) # ...
pyautogui.press(&quot;tab&quot;) # ...
pyautogui.press(&quot;tab&quot;) # ... way to submit button
pyautogui.press(&quot;space&quot;) # pressing submit button
</code></pre>
<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>
<footer>
<ul class="contacts">
<li><a href="https://github.com/horhik" class=" contact-link" title="github">
<pre>
┏━╸╻╺┳╸╻ ╻╻ ╻┏┓
┃╺┓┃ ┃ ┣━┫┃ ┃┣┻┓
┗━┛╹ ╹ ╹ ╹┗━┛┗━┛</pre></a></li>
<li><a href="https://mastodon.ml/web/accounts/74403" class=" contact-link" title="mastodon: @horhik@mastodon.ml">
<pre>
┏┳┓┏━┓┏━┓╺┳╸┏━┓╺┳┓┏━┓┏┓╻
┃┃┃┣━┫┗━┓ ┃ ┃ ┃ ┃┃┃ ┃┃┗┫
╹ ╹╹ ╹┗━┛ ╹ ┗━┛╺┻┛┗━┛╹ ╹
</pre></a></li>
<li><a href="mailto:horhik@tuta.io" class=" contact-link" title="Mail">
<pre>
┏┳┓┏━┓╻╻
┃┃┃┣━┫┃┃
╹ ╹╹ ╹╹┗━╸</pre></a></li>
</ul>
<p class="copyright">&copy;2021 <a href="https://redeyes.club/">Horhik</a></p>
</footer>
</body>
</html>