Python import into SQLite research
<p>Some examples i found while researching this import from python scripts into sqlite.</p>
<p>Example weather import beautiful soup</p>
<h4>Python</h4>
<pre><code class="html hljs xml">def weather():<br />page = requests.get("https://www.bbc.co.uk/weather/0/2643743")<br />soup = BeautifulSoup(page.content, 'html.parser')<br />today = soup.find('div',{'data-component-id' : 'forecast'})<br />temp = today.find(class = 'wr-day-temperature')<br />lowtemp = (temp.gettext())<br />return lowtemp</code></pre>
<p>Insert into SQLite.</p>
<h4>Python</h4>
<pre><code class="html hljs xml">import sqlite3<br />conn = sqlite3.connect('yourdatabase.sqlite3', checksamethread=False)<br />curs = conn.cursor()<br />curs.execute("INSERT INTO yourtablename lowtemp='{}'".format(lowtemp))<br />conn.commit()<br />curs.execute("INSERT INTO yourtablename lowtemp=?", (lowtemp,))</code><code class="html hljs xml"></code></pre>
<p>Insert or update</p>
<h4>Python</h4>
<pre><code class="html hljs xml">INSERT INTO visits (ip, hits)<br />VALUES ('127.0.0.1', 1)<br />ON CONFLICT(ip) DO UPDATE SET hits = hits + 1;</code></pre>
<p><strong>Links</strong></p>
<ol>
<li><a href="https://stackoverflow.com/questions/50105781/how-do-i-save-beautiful-soup-outputs-into-my-sqlite-database" target="blank" rel="noopener">https://stackoverflow.com/questions/50105781/how-do-i-save-beautiful-soup-outputs-into-my-sqlite-database</a> </li>
<li><a href="https://stackoverflow.com/questions/2717590/sqlite-insert-on-duplicate-key-update-upsert" target="blank" rel="noopener">https://stackoverflow.com/questions/2717590/sqlite-insert-on-duplicate-key-update-upsert</a> </li>
</ol>
<p>☕</p>
