Skip to content

Commit

Permalink
Merge pull request #89 from jpulidojr/sqlreader
Browse files Browse the repository at this point in the history
Sqlreader implementation and remote http (requests) image viewer
  • Loading branch information
dhrogers authored Nov 8, 2023
2 parents 82733b2 + 20adf3b commit 99eaa45
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/wildfire/wildfire.sqlite3
Binary file not shown.
7 changes: 6 additions & 1 deletion pycinema/filters/ImageReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import h5py
import os
import re
import requests

from pycinema import getTableExtent

Expand Down Expand Up @@ -72,7 +73,11 @@ def _update(self):
file.close()

elif str.lower(extension) in ['png','jpg','jpeg']:
rawImage = PIL.Image.open(path)
if "https" in path:
rawImage = PIL.Image.open(requests.get(path, stream=True).raw)
else:
rawImage = PIL.Image.open(path)

if rawImage.mode == 'RGB':
rawImage = rawImage.convert('RGBA')
image = Image({ 'rgba': numpy.asarray(rawImage) })
Expand Down
81 changes: 81 additions & 0 deletions pycinema/filters/SqliteDatabaseReader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from pycinema import Filter

import sqlite3

from os.path import exists
import re

class SqliteDatabaseReader(Filter):

def __init__(self):
super().__init__(
inputs={
'path': '',
'table': '',
'file_column': 'FILE'
},
outputs={
'table': [[]]
}
)

def _update(self):

table = []
dbPath = self.inputs.path.get()
if not dbPath:
self.outputs.table.set([[]])
return 0

if not exists(dbPath):
print('[ERROR] sqlite db not found:', dbPath)
self.outputs.table.set([[]])
return 0

tname = self.inputs.table.get()
try:
conn = sqlite3.connect(dbPath)
cursor = conn.cursor()

# capture the names of each column
cdata = cursor.execute(f'PRAGMA table_info({tname});').fetchall()

cnames = [entry[1] for entry in cdata]
table.append(cnames)

print(table)
# capture row data
data = cursor.execute("SELECT * FROM " + tname + "").fetchall() #LIMIT 10
for row in data:
# tuple output convert to list
table.append(list(row))

print(table)
cursor.close()
except sqlite3.Error as error:
print("Error while connecting to sqlite", error)
self.outputs.table.set([[]])
return 0
finally:
if conn:
conn.close()

# remove empty lines
table = list(filter(lambda row: len(row)>0, table))

# # force lower case header
# table[0] = list(map(str.lower,table[0]))

try:
fileColumnIdx = [i for i, item in enumerate(table[0]) if re.search(self.inputs.file_column.get(), item, re.IGNORECASE)].pop()
except:
print('[ERROR] file column not found:',self.inputs.file_column.get())
self.outputs.table.set([[]])
return 0

for i in range(1,len(table)):
table[i][fileColumnIdx] = table[i][fileColumnIdx]

self.outputs.table.set(table)

return 1
5 changes: 1 addition & 4 deletions pycinema/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
from .ImageFilterPIL import *
from .ImageReader import *
from .MaskCompositing import *
from .PlotItem import *
from .PlotBarItem import *
from .PlotLineItem import *
from .ShaderDemoScene import *
from .ShaderFXAA import *
from .ShaderIBS import *
Expand All @@ -24,5 +21,5 @@
from .ShaderSSAO import *
from .ShaderLineAO import *
from .ShaderPointAO import *
from .TextFileReader import *
from .SqliteDatabaseReader import *
from .TableWriter import *
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"ipywidgets==8.0.6",
"PySide6>=6.0.0",
"python-igraph>=0.10.5",
"pyqtgraph"
"pyqtgraph",
"requests"
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit 99eaa45

Please sign in to comment.