@@ -0,0 +1,978 @@
+from   __future__ import unicode_literals%0Aimport json%0Aimport os%0Aimport sys%0A%0Asys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))%0A%0A# Delete the oldest %60n%60 entries%0Atry:%0A  limit = int(sys.argv%5B1%5D) or 1%0Aexcept:%0A  print %22Usage: python delte_oldest.py %5Bn%5D  -%3E Where n is an integer of items to be deleted%22%0A  sys.exit()%0A%0A# Import data file with all saved entries%0Awith open('_data/movie_data.json') as movie_details:%0A  movies = json.load(movie_details)%0A%0A# Sort by date info was retreived%0Aoldest_entries = sorted(movies.iteritems(), key=lambda (title, payload): payload%5B'info_retrieved'%5D)%5B0:limit%5D%0Atitles = %5Bx%5B0%5D for x in oldest_entries%5D%0A%0A# Delete the oldest entries%0Aprint %22Deleting the following titles: %7B%7D%22.format(titles)%0Afor title in titles:%0A  del movies%5Btitle%5D%0A%0A# Write modifiedcontents to JSON file%0A# TODO: Move this from temp file to _data/movies%0Awith open('temp-deleted', 'w+') as asset_feed:%0A  json.dump(movies, asset_feed, encoding=%22utf-8%22, indent=4)%0A

Delete oldest retrieved movies