Advertisement
caparol6991

scheduler

Apr 9th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. import pymongo
  2. from datetime import datetime
  3.  
  4.  
  5. dbName = "tablica_informacyjna"
  6. scheduleCol = "schedule"
  7. scheduleTextCol = "textSchedule"
  8.  
  9. myclient = pymongo.MongoClient("mongodb://localhost:27017/")
  10. mydb = myclient[dbName]
  11.  
  12. #typy danych - image,video,hmtl,link,webcam
  13. def scheduleMedia():
  14.   dblist = myclient.list_database_names()
  15.   if dbName not in dblist:
  16.     return []
  17.  
  18.   mycol = mydb["schedule"]
  19.   collist = mydb.list_collection_names()
  20.   if scheduleCol not in collist:
  21.     return []
  22.  
  23.   dateToday = datetime.today().strftime('%Y-%m-%d')
  24.   query = {"$and": [ {"start": {"$lte" : dateToday},"end": {"$gte" : dateToday} }]}
  25.   list = []
  26.   for item in mycol.find(query, {"_id": 0}):
  27.     list.append(item)
  28.   return list
  29.  
  30.  
  31. def scheduleText():
  32.   dblist = myclient.list_database_names()
  33.   if dbName not in dblist:
  34.     return []
  35.  
  36.   mycol = mydb["textSchedule"]
  37.   collist = mydb.list_collection_names()
  38.   if scheduleCol not in collist:
  39.     return []
  40.  
  41.   dateToday = datetime.today().strftime('%Y-%m-%d')
  42.   query = {"$and": [ {"start": {"$lte" : dateToday},"end": {"$gte" : dateToday} }]}
  43.  
  44.   list = []
  45.   for item in mycol.find(query, {"_id": 0}):
  46.     list.append(item)
  47.   return list
  48.  
  49.  
  50. for x in scheduleMedia():
  51.   print(x["name"] + " " + x["type"] + " - " + x["duration"] + " s")
  52.  
  53. for x in scheduleText():
  54.   print(x["text"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement