Facebook
From Morose Lemur, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 233
  1. import cv2
  2. import glob
  3. import time
  4. import pymongo
  5. from datetime import datetime
  6.  
  7. dbName = "tablica_informacyjna"
  8. scheduleCol = "schedule"
  9. scheduleTextCol = "textSchedule"
  10. myclient = pymongo.MongoClient("mongodb://localhost:27017/")
  11. mydb = myclient[dbName]
  12.  
  13. file = 'C:\\Users\\Nico\\Desktop\\WP\\'
  14.  
  15.  
  16. # typy danych - image,video,hmtl,link,webcam
  17. def scheduleMedia():
  18.     dblist = myclient.list_database_names()
  19.     if dbName not in dblist:
  20.         return []
  21.  
  22.     mycol = mydb["schedule"]
  23.     collist = mydb.list_collection_names()
  24.     if scheduleCol not in collist:
  25.         return []
  26.  
  27.     dateToday = datetime.today().strftime('%Y-%m-%d')
  28.     query = {"$and": [{"start": {"$lte": dateToday}, "end": {"$gte": dateToday}}]}
  29.     list = []
  30.     for item in mycol.find(query, {"_id": 0}):
  31.         list.append(item)
  32.     return list
  33.  
  34. def video(filename):
  35.     cap = cv2.VideoCapture(file+filename)
  36.  
  37.     while (cap.isOpened()):
  38.         ret, frame = cap.read()
  39.         print(ret)
  40.         if ret:
  41.             cv2.imshow('Gallery', frame)
  42.             if cv2.waitKey(33) == 27:
  43.                 exit()
  44.                 break
  45.         else:
  46.             break
  47.     cap.release()
  48.  
  49. def img(filename,time):
  50.     cv2.imshow('Gallery', cv2.imread(file+filename))
  51.     time.sleep(time)
  52.     if cv2.waitKey(33) == ord('q'):
  53.         exit()
  54.  
  55. image_list = []
  56. for filename in glob.glob('C:\\Users\\Nico\\Desktop\\WP/*.jpg'):
  57.     im = cv2.imread(filename)
  58.     image_list.append(im)
  59. i = 0
  60. cv2.namedWindow('Gallery', cv2.WND_PROP_FULLSCREEN)
  61. cv2.setWindowProperty('Gallery', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
  62.  
  63. l=scheduleMedia()
  64. while True:
  65.     for x in scheduleMedia():
  66.         if x["type"] == 'image':
  67.             img(x[["name"]], x["duration"])
  68.         if x["type"] == 'video':
  69.             video(x[["name"]])
  70.  
  71.  
  72.