# Example 1: Chicago and method chaining # create instance of parser with data feed details parser = BSRParser(chicago_data_feed) # retrieving will return False or, if successfull, the parser object (self) parser.retrieve() # save cleaned data locally according to the default schema (fullset) parser.save('') # save the raw data if you wish parser.save_raw('') # retrieve the data in array form, perhaps to insert into DB data_array = parser.get_data_array() # or, since most of these methods return the object/self, do it all in one line data_array = parser.retrieve().save('').save_raw('').get_data_array() # Example 2: Lyon and data feed API keys # For lyon we have already identified the feed we would like: lyon = urllib2.urlopen('http://bikeshare-research.org/api/v1/categories/data/records/10') lyon_data_feed = json.loads(lyon.read())[0] parser = BSRParser(lyon_data_feed) # we don't need to explicitly call retrieve(), saving will do so if necessary parser.set_apikey('YOUR JCDECAUX API KEY').retrieve().save_raw('').save('') # data is saved locally, done # You can convert the UTC time to the local timezone using the timezome attribute in '/systems/lyon/categories/base/'
print("No feed is specified for this BSS.") if len(feeds) > 1: print("The feed has " + str(len(feeds)) + " parts.") for feed in feeds: if feed['parsername'] is not None: print("Using parser: " + feed['parsername']) parser = BSRParser(feed) if apikey != '': print(apikey) parser.set_apikey(apikey) parser.retrieve() parser.parse() stns = parser.get_data_array() # test reuse of stations if stns: # stns is not equal to false for stn in stns: # print data array try: print(stn) except UnicodeEncodeError: print( "Encountered UnicodeEncodeError: Can't print results") print(ascii(stn)) try: print(parser.get_string()) except UnicodeEncodeError: