Posted in python
1882
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
34
This Month
176
This Year
168

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
You want to be the best, you MUST put the long yards in! Nothing comes easy in life so stop wishing and start DOING! So many people would rather bitch and moan than help themselves. Dont be one of those negative drainers, start today, make a small change and keep going forwards with this attitude!
Unknown
Random CSS Property

font-family

The font-family CSS descriptor allows authors to specify the font family for the font specified in an @font-face rule.
font-family (@font-face) css reference