Exemple #1
0
    def test_date_parse(self, mock_get_localzone):
        hill_valley = pytz.timezone('America/Los_Angeles')
        mock_get_localzone.return_value = hill_valley

        expected = hill_valley.localize(
            datetime.datetime(2015, 10, 21, 16, 29))
        formats = ['2015-10-21T23:29:00Z',
                   '2015-10-21T23:29:00.00',
                   '2015-10-21T23:29:00']
        for i in formats:
            self.assertEqual(expected,
                             util.date_parse({'time_created': i}))
            self.assertEqual(expected,
                             util.date_parse({'properties': {
                                 'time_created': i}}))
Exemple #2
0
    def export(self, args):
        try:
            to_export = self.find_objects(args.name, match=args.match,
                                          date_range=args.match_date)
        except command._Safety:
            to_export = []

        if not to_export:
            self.verbose('No items matched criteria')
            return 1

        for photo in to_export:
            if args.dry_run:
                self.verbose('Would download %r' % photo['title'])
            else:
                ds = util.date_parse(photo)
                ts = time.mktime(ds.timetuple())
                content_type, content = self.client.get_photo(photo['id'])
                extension = type_to_extension.get(content_type, 'dat')
                filename = '%s.%s' % (
                    pathvalidate.sanitize_filename(photo['title']), extension)
                if os.path.exists(filename):
                    print('File %r already exists; not overwriting' % filename)
                    continue
                with open(filename, 'wb') as f:
                    f.write(content)
                os.utime(filename, (ts, ts))
                self.verbose('Wrote %r' % filename)
Exemple #3
0
 def _match_date(self, item, date_range):
     start, end = date_range
     item_dt = util.date_parse(item)
     if item_dt:
         item_dt = item_dt.replace(tzinfo=None)
         return item_dt >= start and item_dt <= end
     else:
         return False