Example #1
0
 def testfeedItemFunctions(self):
     ''' Test the instantiation of each feed item (camera)'''
     
     parent   = os.getcwd()
     dataDir = os.path.join(parent, 'feedTestResources')
     fxml = open(os.path.join(dataDir, 'jamCamsv2.xml'), 'r')
     data = fxml.read()
     errors, header, rootUrl, cameras = baseUtils.extractContent(data)
     fc = baseObjects.feedChannel(header)
     
     fi = baseObjects.feedItem(fc, cameras[1], rootUrl)
     
     self.assertEquals(fi.source, 'transport for london')
     self.assertEquals(fi.title, 'tfl traffic cameras')
     self.assertEquals(fi.pubDate, datetime.datetime(2012,10,1,20,15,20))
     self.assertEquals(fi.copyright, 'transport for london')
     
     # New - item specific elements
     self.assertEquals(fi.camTitle, 'ram st/barchard st')
     self.assertEquals(fi.camCorridor, 'a205')
     self.assertEquals(fi.camLink, '/tfl/livetravelnews/trafficcams/cctv/0000102645.jpg')
     self.assertEquals(fi.camCurrentView, 'ram st n/b')
     self.assertEquals(fi.camId, '0000102645')
     self.assertAlmostEquals(fi.camGeo[0], -0.1920207, 4)
     self.assertAlmostEquals(fi.camGeo[1],  51.458282, 4)
     self.assertEquals(fi.camCaptureTime, datetime.datetime(2012,10,01,20,13,38))
Example #2
0
def main():
    """ """

    # Connect and get db and collection handle
    try:
        c, dbh = mdb.getHandle(p.dbHost, p.dbPort, p.db, p.dbUser, p.dbPassword)
        collectionHandle = dbh[p.camsCollection]
    except:
        logging.critical("DB connection Failed", exc_info=True)

    # Get the feed content
    feedContent = hitFeed(p.feedUrl)
    if not feedContent:
        logging.critical("** SCRIPT EXIT **\n%s\n\n" % ("=" * 52))
        sys.exit()

    # Break out the content into head and items
    header, rootUrl, cameras = extractContent(feedContent)
    if not header or not rootUrl or not cameras:
        logging.critical("** SCRIPT EXIT **\n%s\n\n" % ("=" * 52))
        sys.exit()

    # Build the camera root URL
    rootUrl = p.tflDomain + rootUrl
    fc = feedChannel(header)

    # Deal with each of the items
    for camera in cameras:

        # Build an 'item' object based on the RSS item
        item = feedItem(fc, camera, rootUrl)
        item.buildGeoJson()

        # Insert the document into mongo
        response = mongoInsert(collectionHandle, item)
Example #3
0
 def testfeedChannel(self):
     ''' Test the instantiation of the feedchannel object'''
     
     parent   = os.getcwd()
     dataDir = os.path.join(parent, 'feedTestResources')
     fxml = open(os.path.join(dataDir, 'jamCamsv2.xml'), 'r')
     data = fxml.read()
     errors, header, rootUrl, cameras = baseUtils.extractContent(data)
     fc = baseObjects.feedChannel(header)
     
     self.assertEquals(fc.title, 'tfl traffic cameras')
     truthDate = datetime.datetime(2012,10,1,20,15,20)
     self.assertEquals(fc.pubDate, truthDate)
     
     truth = 'transport for london'
     self.assertEquals(fc.copyright, truth)