Adding timewarp script used to adjust upload dates in bulk. Very much geared toward solving the problem at hand.
This commit is contained in:
commit
b2cad7976d
78
timewarp.py
Normal file
78
timewarp.py
Normal file
@ -0,0 +1,78 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from os.path import expanduser
|
||||
|
||||
import flickrapi
|
||||
|
||||
|
||||
class TimeWarper(object):
|
||||
|
||||
def __init__(self, sysargs=sys.argv[:]):
|
||||
self.sysargs = sysargs
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('min_upload_date')
|
||||
parser.add_argument('max_upload_date')
|
||||
parser.add_argument('set_to_date')
|
||||
|
||||
parser.add_argument(
|
||||
'-c', '--rcfile', default=expanduser('~/.frupplerc'),
|
||||
type=argparse.FileType('r')
|
||||
)
|
||||
|
||||
self.args = parser.parse_args(self.sysargs[1:])
|
||||
self._rc_conf = json.load(self.args.rcfile)
|
||||
|
||||
self.flickr = flickrapi.FlickrAPI(
|
||||
self._rc_conf['APIKEY'], self._rc_conf['APISECRET']
|
||||
)
|
||||
|
||||
token, frob = self.flickr.get_token_part_one(perms='write')
|
||||
if not token:
|
||||
raw_input("Press ENTER after you authorized this program")
|
||||
|
||||
self.flickr.get_token_part_two((token, frob))
|
||||
|
||||
def set_upload_date_for_photos(self, pagenum, photo_nodes, to_date):
|
||||
for i, photo in enumerate(photo_nodes):
|
||||
setdate_response = self.flickr.photos_setDates(
|
||||
photo_id=photo.attrib['id'],
|
||||
date_posted=to_date
|
||||
)
|
||||
print('page {} photo {}: rsp={}, attribs={}'.format(
|
||||
pagenum, i, setdate_response, setdate_response.attrib))
|
||||
|
||||
def run(self):
|
||||
query_args = dict(
|
||||
user_id='me',
|
||||
min_upload_date=self.args.min_upload_date,
|
||||
max_upload_date=self.args.max_upload_date,
|
||||
page=1
|
||||
)
|
||||
|
||||
print('Getting first page')
|
||||
firstpage = self.flickr.photos_search(**query_args)
|
||||
self.set_upload_date_for_photos(
|
||||
1,
|
||||
firstpage.getchildren()[0].getchildren(),
|
||||
self.args.set_to_date
|
||||
)
|
||||
|
||||
npages = int(firstpage.getchildren()[0].attrib['pages'])
|
||||
|
||||
for pagenum in range(1, npages + 1):
|
||||
print('Getting another page')
|
||||
page = self.flickr.photos_search(**query_args)
|
||||
self.set_upload_date_for_photos(
|
||||
pagenum,
|
||||
page.getchildren()[0].getchildren(),
|
||||
self.args.set_to_date
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(TimeWarper().run())
|
Loading…
Reference in New Issue
Block a user