summaryrefslogtreecommitdiff
path: root/docs/posts/2021-06-25-Blog2Twitter-P1.html
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2022-11-07 23:36:11 -0700
committernavanchauhan <navanchauhan@gmail.com>2022-11-07 23:36:11 -0700
commitd75527f7eecc4e2fcdd18ab157412506717c8adb (patch)
tree8a96e3036d59030f5654725edb1ca5ad6db4cb4e /docs/posts/2021-06-25-Blog2Twitter-P1.html
parent8ca94ab784138ef673bc7c1691b99e2d4d69e015 (diff)
add blog post
Diffstat (limited to 'docs/posts/2021-06-25-Blog2Twitter-P1.html')
-rw-r--r--docs/posts/2021-06-25-Blog2Twitter-P1.html24
1 files changed, 16 insertions, 8 deletions
diff --git a/docs/posts/2021-06-25-Blog2Twitter-P1.html b/docs/posts/2021-06-25-Blog2Twitter-P1.html
index ada9666..62233ab 100644
--- a/docs/posts/2021-06-25-Blog2Twitter-P1.html
+++ b/docs/posts/2021-06-25-Blog2Twitter-P1.html
@@ -57,7 +57,8 @@ I am not handling lists or images right now.</p>
<p><code>pip install tweepy</code></p>
-<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">os</span>
+<div class="codehilite">
+<pre><span></span><code><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">tweepy</span>
<span class="n">consumer_key</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;consumer_key&quot;</span><span class="p">]</span>
@@ -70,13 +71,15 @@ I am not handling lists or images right now.</p>
<span class="n">auth</span><span class="o">.</span><span class="n">set_access_token</span><span class="p">(</span><span class="n">access_token</span><span class="p">,</span> <span class="n">access_token_secret</span><span class="p">)</span>
<span class="n">api</span> <span class="o">=</span> <span class="n">tweepy</span><span class="o">.</span><span class="n">API</span><span class="p">(</span><span class="n">auth</span><span class="p">)</span>
-</code></pre></div>
+</code></pre>
+</div>
<p>The program need to convert the blog post into text fragments.</p>
<p>It reads the markdown file, removes the top YAML content, checks for headers and splits the content.</p>
-<div class="codehilite"><pre><span></span><code><span class="n">tweets</span> <span class="o">=</span> <span class="p">[]</span>
+<div class="codehilite">
+<pre><span></span><code><span class="n">tweets</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">first___n</span> <span class="o">=</span> <span class="mi">0</span>
@@ -103,13 +106,15 @@ I am not handling lists or images right now.</p>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;ERROR&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tweets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
-</code></pre></div>
+</code></pre>
+</div>
<p>Every status update using tweepy has an id attached to it, for the next tweet in the thread, it adds that ID while calling the function.</p>
<p>For every tweet fragment, it also appends 1/n.</p>
-<div class="codehilite"><pre><span></span><code><span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">tweet</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">tweets</span><span class="p">):</span>
+<div class="codehilite">
+<pre><span></span><code><span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">tweet</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">tweets</span><span class="p">):</span>
<span class="n">tweet</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">{}</span><span class="s2">/</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">idx</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">tweets</span><span class="p">))</span>
<span class="k">if</span> <span class="n">idx</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">a</span> <span class="o">=</span> <span class="kc">None</span>
@@ -118,12 +123,15 @@ I am not handling lists or images right now.</p>
<span class="n">a</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">update_status</span><span class="p">(</span><span class="n">tweet</span><span class="p">,</span><span class="n">in_reply_to_status_id</span><span class="o">=</span><span class="n">a</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">tweet</span><span class="p">),</span><span class="n">end</span><span class="o">=</span><span class="s2">&quot; &quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">/</span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">idx</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">tweets</span><span class="p">)))</span>
-</code></pre></div>
+</code></pre>
+</div>
<p>Finally, it replies to the last tweet in the thread with the link of the post.</p>
-<div class="codehilite"><pre><span></span><code><span class="n">api</span><span class="o">.</span><span class="n">update_status</span><span class="p">(</span><span class="s2">&quot;Web Version: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">post_link</span><span class="p">))</span>
-</code></pre></div>
+<div class="codehilite">
+<pre><span></span><code><span class="n">api</span><span class="o">.</span><span class="n">update_status</span><span class="p">(</span><span class="s2">&quot;Web Version: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">post_link</span><span class="p">))</span>
+</code></pre>
+</div>
<h2>Result</h2>