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

Python import into SQLite research

Some examples i found while researching this import from python scripts into sqlite.

Example weather import beautiful soup

Python

def weather_():
page = requests.get("https://www.bbc.co.uk/weather/0/2643743")
soup = BeautifulSoup(page.content, 'html.parser')
today = soup.find('div',{'data-component-id' : 'forecast'})
temp = today.find(class_ = 'wr-day-temperature')
low_temp = (temp.get_text())
return low_temp

Insert into SQLite.

Python

import sqlite3
conn = sqlite3.connect('your_database.sqlite3', check_same_thread=False)
curs = conn.cursor()
curs.execute("INSERT INTO your_table_name low_temp='{}'".format(low_temp))
conn.commit()
curs.execute("INSERT INTO your_table_name low_temp=?", (low_temp,))

Insert or update

Python

INSERT INTO visits (ip, hits)
VALUES ('127.0.0.1', 1)
ON CONFLICT(ip) DO UPDATE SET hits = hits + 1;

Links

  1. https://stackoverflow.com/questions/50105781/how-do-i-save-beautiful-soup-outputs-into-my-sqlite-database 
  2. https://stackoverflow.com/questions/2717590/sqlite-insert-on-duplicate-key-update-upsert 

View Statistics
This Week
33
This Month
175
This Year
167

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...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

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
Old programmers never die; they just lose some of their functions.
Random CSS Property

column-width

The column-width CSS property sets the ideal column width in a multi-column layout. The container will have as many columns as can fit without any of them having a width less than the column-width value. If the width of the container is narrower than the specified value, the single column's width will be smaller than the declared column width.
column-width css reference