Posted in python
293
11:14 pm, March 28, 2021
 

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('your
database.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>&nbsp;</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>&nbsp;</li>
</ol>
<p>☕</p>

View Statistics
This Week
97
This Month
324
This Year
327

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Articles
Search Articles by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


minecraft
Latest News
## 🚀 AI Giants Hit Bullseye: Anthropic & OpenAI Achieve Product-Market Fit Anthropic and OpenAI have reached a significant milestone, finding product-market fit with their AI technologies, which means their products effectively meet the needs of their customers, driving growth and adoption. This achievement showcases the practical value of their innovations, enabling businesses and individuals to leverage AI for enhanced productivity and efficiency. With this alignment of product and market needs, these companies are poised to transform industries and shape the future of technology.