diff options
author | Niclas Dobbertin <niclas.dobbertin@stud.tu-darmstadt.de> | 2023-06-15 16:05:04 +0200 |
---|---|---|
committer | Niclas Dobbertin <niclas.dobbertin@stud.tu-darmstadt.de> | 2023-06-15 16:05:04 +0200 |
commit | b6b5918493260518ee4b868ea03e5316caca40aa (patch) | |
tree | df9dfc7a73a0dfe3c895e3e95e2b5c18fdbc1a3c /bjoern | |
parent | e16826dcbb7fc6036de5fc1ad50f74e4e695ac00 (diff) |
change get_url to return first url string
Diffstat (limited to 'bjoern')
-rw-r--r-- | bjoern/videoanalyse/read_sqlite.py | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/bjoern/videoanalyse/read_sqlite.py b/bjoern/videoanalyse/read_sqlite.py index 2041ac3..6c3e5b0 100644 --- a/bjoern/videoanalyse/read_sqlite.py +++ b/bjoern/videoanalyse/read_sqlite.py @@ -1,32 +1,41 @@ -import sqlite3; -import fileinput; -import csv; +import sqlite3 +import csv + def print_sqlite(cursor): for row in cursor.fetchall(): print(dict(row)) + def create_csv_from_sqlite(data): - with open('sqlite_output.csv', 'w', newline='') as f: + with open("sqlite_output.csv", "w", newline="") as f: writer = csv.writer(f) - writer.writerow(['id', 'url', ...]) + writer.writerow(["id", "url", ...]) writer.writerows(data) - + + def get_url_from_sqlite(sqlite_file, title): con = sqlite3.connect(sqlite_file) con.row_factory = sqlite3.Row - + cur = con.cursor() - select_statement = 'SELECT url FROM moz_places WHERE title = ?' + select_statement = "SELECT url FROM moz_places WHERE title = ?" dat = cur.execute(select_statement, (title,)) - - print_sqlite(cur) - + + row = dat.fetchone() + if row: + return row["url"] + return None + + def main(): - get_url_from_sqlite('chsokl11/places.sqlite', 'Atmosphärische Gegenstrahlung – Wikipedia') - - #create_csv_from_sqlite(dat) - #concat_logfiles() + get_url_from_sqlite( + "chsokl11/places.sqlite", "Atmosphärische Gegenstrahlung – Wikipedia" + ) + + # create_csv_from_sqlite(dat) + # concat_logfiles() + if __name__ == "__main__": main() |