google-photo-to-vcard/google_photo_to_vcard/download_photos.py

28 lines
769 B
Python
Raw Normal View History

2018-04-04 23:59:49 +00:00
import logging
2018-04-04 23:55:09 +00:00
import urllib.request as request
from pathlib import Path
from urllib.error import HTTPError
from google_photo_to_vcard.util import build_photo_path
from google_photo_to_vcard.util import download_url_to_path
from google_photo_to_vcard.util import read_email_photo_json
2018-04-04 23:59:49 +00:00
logging.basicConfig(level=logging.DEBUG)
2018-04-04 23:55:09 +00:00
def main():
email_to_photo = read_email_photo_json()
for email, photo_url in email_to_photo.items():
2018-04-04 23:59:49 +00:00
loging.info('Downloading (%s, %s)', email, photo_url)
2018-04-04 23:55:09 +00:00
photo_path = Path(build_photo_path(email))
if photo_path.exists():
2018-04-04 23:59:49 +00:00
loging.debug('Photo already downloaded')
2018-04-04 23:55:09 +00:00
continue
else:
download_url_to_path(photo_url, photo_path)
if __name__ == '__main__':
main()