Browse Source

from_location returns a dictionnary

Olivier Marty 8 years ago
parent
commit
3511c396a1
2 changed files with 7 additions and 8 deletions
  1. 4 3
      main.py
  2. 3 5
      source.py

+ 4 - 3
main.py

@@ -13,7 +13,6 @@ def main():
     gap = timedelta(minutes=30) # 30 minutes : time to check trafic before an event
     while True:
         # TODO feed heap
-        # then look for problems
 
         # sleep the min between 1 minute and the next event - gap
         next = timedelta(seconds=1) # TODO 1 minute
@@ -26,16 +25,18 @@ def main():
         # next event
         if not heap.empty() and heap.top().date-datetime.now() < gap:
             event = heap.pop()
+            print(event.description + " at " + event.location + ", " + str(event.date))
 
             # get useful ids of sources for this location
             ids_sources = source.from_location(event.location)
+            # flatten this dictionnary
+            ids_sources_flat = [item for (key, sublist) in ids_sources.items() for item in sublist]
             # grab info from internet for these sources
             sources=source.gen_sources(ids_sources)
             for src in sources:
-              if src.id in ids_sources and src.problem():
+              if src.id in ids_sources_flat and src.problem():
                 # there is a problem ! We notify the user...
                 notification.notify(src.message)
-            print(event.description + " at " + event.location + ", " + str(event.date))
 
 if __name__ == "__main__":
     main()

+ 3 - 5
source.py

@@ -120,12 +120,10 @@ def transilien():
 
 def from_location(location):
     """return a list of source ids useful for location
-    TODO : for the moment returns all ids in config.sources"""
-    lists = [values for (name, values) in config.sources.items()]
-    # return flattened list
-    return [item for sublist in lists for item in sublist]
+    TODO : for the moment returns the whole config.sources"""
+    return config.sources
 
 def gen_sources(ids):
   return chain(ratp_trafic(),\
       transilien(),\
-      jcdecaux_vls(config.sources['jcdecaux_vls'])) # TODO filter out ids for jcdecaux
+      jcdecaux_vls(ids.get('jcdecaux_vls', [])))