Posted in python
1900
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
35
This Month
132
This Year
186

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
A.A. Milne’s Winnie-the-Pooh: “If you live to be a hundred, I want to live to be a hundred minus one day so I never have to live without you.”
A.A. Milne
Random CSS Property

fallback

The fallback descriptor can be used to specify a counter style to fall back to if the current counter style cannot create a marker representation for a particular counter value.
fallback (@counter-style) css reference