-
-
Notifications
You must be signed in to change notification settings - Fork 567
fix earlier commit #232
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
Merged
Merged
fix earlier commit #232
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,36 @@ | ||
| #!/usr/bin/env python3 | ||
| # coding: utf-8 | ||
|
|
||
| import json # https://docs.python.org/3/library/json.html | ||
| import requests # https://github.com/kennethreitz/requests | ||
| import records # https://github.com/kennethreitz/records | ||
| import json | ||
| import requests | ||
| import records | ||
|
|
||
| # randomuser.me generates random 'user' data (name, email, addr, phone number, etc) | ||
| r = requests.get('http://api.randomuser.me/0.6/?nat=us&results=10') | ||
| j = r.json()['results'] | ||
| # Fetch random user data from randomuser.me API | ||
| response = requests.get('http://api.randomuser.me/0.6/?nat=us&results=10') | ||
| user_data = response.json()['results'] | ||
|
|
||
| # Valid SQLite URL forms are: | ||
| # sqlite:///:memory: (or, sqlite://) | ||
| # sqlite:///relative/path/to/file.db | ||
| # sqlite:////absolute/path/to/file.db | ||
| # Database connection string | ||
| DATABASE_URL = 'sqlite:///users.db' | ||
|
|
||
| # records will create this db on disk if 'users.db' doesn't exist already | ||
| db = records.Database('sqlite:///users.db') | ||
| # Initialize the database | ||
| db = records.Database(DATABASE_URL) | ||
|
|
||
| # Create the 'persons' table | ||
| db.query('DROP TABLE IF EXISTS persons') | ||
| db.query('CREATE TABLE persons (key int PRIMARY KEY, fname text, lname text, email text)') | ||
|
|
||
| for rec in j: | ||
| user = rec['user'] | ||
| name = user['name'] | ||
| db.query('CREATE TABLE persons (key INTEGER PRIMARY KEY, fname TEXT, lname TEXT, email TEXT)') | ||
|
|
||
| # Insert user data into the 'persons' table | ||
| for record in user_data: | ||
| user = record['user'] | ||
| key = user['registered'] | ||
| fname = name['first'] | ||
| lname = name['last'] | ||
| fname = user['name']['first'] | ||
| lname = user['name']['last'] | ||
| email = user['email'] | ||
| db.query('INSERT INTO persons (key, fname, lname, email) VALUES(:key, :fname, :lname, :email)', | ||
| key=key, fname=fname, lname=lname, email=email) | ||
| db.query( | ||
| 'INSERT INTO persons (key, fname, lname, email) VALUES (:key, :fname, :lname, :email)', | ||
| key=key, fname=fname, lname=lname, email=email | ||
| ) | ||
|
|
||
| # Retrieve and print the contents of the 'persons' table as CSV | ||
| rows = db.query('SELECT * FROM persons') | ||
| print(rows.export('csv')) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,7 +343,6 @@ def transaction(self): | |
| tx.commit() | ||
| except: | ||
| tx.rollback() | ||
| raise | ||
| finally: | ||
| conn.close() | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a
timeoutparameter and use HTTPS.The
requests.getcall has notimeout, so it can block indefinitely if the server is unresponsive (Ruff S113). Also, preferhttps://overhttp://to avoid transmitting data in plaintext.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.14.14)
[error] 9-9: Probable use of
requestscall without timeout(S113)
🤖 Prompt for AI Agents