def get_feed(self): return feedparser.parse(self.feed_path) def get_feed_metadata(self): metadata = dict() metadata['title'] = self.raw_feed.feed.title metadata['subtitle'] = self.raw_feed.feed.subtitle metadata['description'] = self.raw_feed.feed.description metadata['etag'] = self.raw_feed.headers['ETag'] metadata['source'] = self.raw_feed.feed.title_detail.base metadata['value'] = self.raw_feed.feed.title_detail.value return metadata def get_feed_entries(self): return self.raw_feed.entries def read_feed(self): feed = dict() feed['metadata'] = self.get_feed_metadata() feed['entries'] = self.get_feed_entries() return feed if __name__ == "__main__": args = Arguments() args.add_argument('--feed') feed_source = args.get('feed', str()) reader = FeedReader(feed_path='http://travel.state.gov/_res/rss/TWs.xml') feed = reader.read_feed()
self.feed_metadata = feed_metadata def parse_temporal(self, temporal=None): start = arrow.get(temporal.split('/')[0]).format('YYYY-MM-DD HH:mm:ss') try: end = arrow.get(temporal.split('/')[1]).format('YYYY-MM-DD HH:mm:ss') except: end = 'Null' return start, end def save_feed(self, file=None, feed=None, field_names=None): save_rows(file=file, rows=feed, field_names=field_names) pass if __name__ == "__main__": args = Arguments(description='this script is for reading and writing' 'travel feeds from travel.gov') args.add_argument('--feed_path', help='The path is the path to your resource', required=True, ) args.add_argument('--metadata_path', help='The path is the path to your resource', required=True, ) args.add_argument('--description', help='The description describes the type of feed ' '(e.g., "alerts")', required=True, ) feed_path = args.get('--feed_path', str()) metadata_path = args.get('--metadata_path', str())