Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blog/live-databases-are-now-live/ #16

Open
utterances-bot opened this issue Oct 11, 2023 · 2 comments
Open

blog/live-databases-are-now-live/ #16

utterances-bot opened this issue Oct 11, 2023 · 2 comments

Comments

@utterances-bot
Copy link

Live databases are now .. live! - DB Browser for SQLite

https://sqlitebrowser.org/blog/live-databases-are-now-live/

Copy link

import requests
import sqlite3

Step 1: API bata data fetch bhayo

api_url = "https://raw.githubusercontent.com/younginnovations/internship-challenges/master/programming/petroleum-report/data.json"
response = requests.get(api_url)

if response.status_code == 200:
data = response.json()
else:
print("Failed to fetch data from the API.")
exit()

Step 2: Database ko Name jasma connect garney

database_file = "petroleum_data.db"

try:
# database ma connect gareyra entity add gardai
conn = sqlite3.connect(database_file)
cursor = conn.cursor()

cursor.execute('''
    CREATE TABLE IF NOT EXISTS petroleum_sales (
        id INTEGER PRIMARY KEY,
        country TEXT,
        product TEXT,
        year INTEGER,
        sales REAL
    )
''')

# Data haldai
for entry in data:
    cursor.execute('''
    INSERT INTO petroleum_sales (country, product, year, sales)
    VALUES (?, ?, ?, ?)
  ''', (entry['country'], entry['petroleum_product'], entry['year'], entry['sale']))

 # Print the inserted data
print("Inserted data:", entry)



conn.commit()
print("Data successfully stored in the SQLite database.")

except sqlite3.Error as e:
print("SQLite Error:", e)
exit()

finally:

conn.close()

@justinclift
Copy link
Member

@pranishdon Looking over your code, it's not clear what it's trying to do?

It doesn't seem to be doing anything with live databases, or am I misunderstanding? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants